yii2 easy wechat
1.0.3: Merge pull request #13 from jonneyless
WeChat SDK สำหรับ yii2 อิงจาก overtrue/wechat
ส่วนขยายนี้ช่วยให้คุณเข้าถึงแอปพลิเคชัน overtrue/wechat
ด้วยวิธีที่เรียบง่ายและคุ้นเคย: Yii::$app->wechat
composer require maxwen/yii2-easy-wechat
เพิ่ม SDK เป็น component
แอปพลิเคชัน yii2 ใน config/main.php
:
' components ' => [
// ...
' wechat ' => [
' class ' => ' maxweneasywechatWechat ' ,
// 'userOptions' => [] # user identity class params
// 'sessionParam' => '' # wechat user info will be stored in session under this key
// 'returnUrlParam' => '' # returnUrl param stored in session
],
// ...
]
// here are two representative examples that will help you:
// 微信网页授权:
if (Yii:: $ app -> wechat -> isWechat && !Yii:: $ app -> wechat -> isAuthorized ()) {
return Yii:: $ app -> wechat -> authorizeRequired ()-> send ();
}
// 微信支付(JsApi):
$ orderData = [
' openid ' => ' .. '
// ... etc.
];
$ order = new WechatOrder ( $ orderData );
$ payment = Yii:: $ app -> wechat -> payment ;
$ prepayRequest = $ payment -> prepare ( $ order );
if ( $ prepayRequest -> return_code = ' SUCCESS ' && $ prepayRequest -> result_code == ' SUCCESS ' ) {
$ prepayId = $ prepayRequest -> prepay_id ;
} else {
throw new yii base ErrorException ( '微信支付异常, 请稍后再试' );
}
$ jsApiConfig = $ payment -> configForPayment ( $ prepayId );
return $ this -> render ( ' wxpay ' , [
' jsApiConfig ' => $ jsApiConfig ,
' orderData ' => $ orderData
]);
แอปพลิเคชัน overtrue/wechat
จะสร้างด้วยพารามิเตอร์ $options
เสมอ ฉันสร้างตัวเลือกเป็นพารามิเตอร์ yii2 ใน params.php
:
วิธีที่แนะนำ:
// in this way you need to create a wechat.php in the same directory of params.php
// put contents in the wechat.php like:
// return [
// // wechat options here
// ];
' WECHAT ' => require ( __DIR__ . ' /wechat.php ' ),
หรือ
' WECHAT ' => [ // wechat options here ]
ตัวเลือก Wechat กำหนดค่าเอกสารช่วยเหลือ
ดูเอกสาร EasyWeChat
ขอบคุณ overtrue/wechat
วิธีง่ายๆ ในการเล่นด้วย wechat SDK จริงหรือ?
yii2-ckeditor-วิดเจ็ต
yii2-adminlte-gii
yii2-ขด