yii2 easy wechat
1.0.3: Merge pull request #13 from jonneyless
WeChat SDK für yii2, basierend auf overtrue/wechat.
Mit dieser Erweiterung können Sie auf einfache und vertraute Weise auf die Anwendung overtrue/wechat
zugreifen: Yii::$app->wechat
.
composer require maxwen/yii2-easy-wechat
Fügen Sie das SDK als yii2- component
in der config/main.php
hinzu:
' 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
]);
Die overtrue/wechat
-Anwendung erstellt immer mit einem $options
Parameter. Ich habe die Optionen als yii2-Parameter in der params.php
erstellt:
Empfohlener Weg:
// 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 ' ),
ODER
' WECHAT ' => [ // wechat options here ]
Wechat-Optionen konfigurieren Hilfedokumente.
siehe EasyWeChat-Dokumente.
Dank overtrue/wechat
ist es wirklich eine einfache Möglichkeit, mit dem Wechat SDK zu spielen?
yii2-ckeditor-widget
yii2-adminlte-gii
yii2-curl