yii2 easy wechat
1.0.3: Merge pull request #13 from jonneyless
yii2 的微信 SDK,基於 overtrue/wechat。
此擴充功能可協助您以簡單熟悉的方式存取overtrue/wechat
應用程式: Yii::$app->wechat
。
composer require maxwen/yii2-easy-wechat
在config/main.php
中加入 SDK 作為 yii2 應用程式component
:
' 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
參數建構。我在params.php
中將選項設定為 yii2 參數:
推薦方式:
// 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 ]
微信選項配置幫助文件。
參見易微信文件。
感謝overtrue/wechat
,真的是個簡單的方法來玩微信 SDK 嗎?
yii2-ckeditor-widget
yii2-adminlte-gii
yii2-curl