1. Go to this page and download the library: Download hjp1011/yii2-easy-wechat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hjp1011 / yii2-easy-wechat example snippets
'components' => [
// ...
'wechat' => [
'class' => 'yiiframe\easywechat\Wechat',
'userOptions' => [], // user identity class parameters
'sessionParam' => 'wechatUser', // wechatUser information will be stored in the session in this key
'returnUrlParam' => '_wechatReturnUrl', //returnUrl is stored in the session
'rebinds' => [ // Customizable service module
// 'cache' => 'common\components\Cache',
]
],
// ...
]
if (Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) {
return Yii::$app->wechat->authorizeRequired()->send();
}
// Method 1 to obtain the current user information of wechat
Yii::$app->session->get('wechatUser')
// Method 2 to obtain the current user information of wechat
Yii::$app->wechat->user