微信修改了獲取用戶基本信息 接口返回的參數(shù),不在返回nickname、headimgurl;因此PRO的微信授權方法也需要做兼容.自行按照下面的操作兼容.
關于微信授權獲取用戶昵稱、圖像問題修復
1、下載修復包在根目錄解壓
2、文件:crmeb/services/WechatService.php,增加如下方法:
/**
* 網(wǎng)頁授權
* @return easywechat\oauth2\wechat\WechatOauth2Provider
*/
public static function oauth2Service()
{
$_this = self::instance();
$_this->serverRequest(app()->request, 'oauth2');
return self::instance()->application->oauth2;
}
3、全局搜索:::oauthService()->user()->getOriginal(),授權獲取openid方法:
改成: ::oauth2Service()->oauth();
4、搜索調(diào)用:::getUserInfo()這個方法,全部替換成:
::oauth2Service()->getUserInfo()->toArray()
注:這個方法參數(shù)為用戶:openid
以下方法中調(diào)用::getUserInfo()不用替換:
文件:app/services/wechat/WechatUserServices.php
方法1:updateWecahtUser()
方法2:setNewUser()
方法3:syncWechatUser()
文件:app/services/user/UserServices.php
方法4:importUser()
本次微信獲取用戶基本信息不在返回用戶昵稱、圖像信息
關注公眾號生成用戶,同步公眾號用戶;使用openid獲取用戶信息不用更改,只需增加nickname字段驗證,事例代碼如下:
if (isset($userInfo['nickname']) && $userInfo['nickname']) {
$userInfo['nickname'] = filter_emoji($userInfo['nickname']);
} else {
mt_srand();
$userInfo['nickname'] = 'wx' . rand(100000, 999999);
}