1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
...
大专栏 Laravel wxxcx 微信小程序获取用户信息 class="line">use IwanliWxxcxWxxcx;
class WxxcxController extends Controller { protected $wxxcx;
function __construct(Wxxcx $wxxcx) { $this->wxxcx = $wxxcx; }
public function getWxUserInfo() { // code 在小程序端使用 wx.login 获取 $code = request('code', ''); // encryptedData 和 iv 在小程序端使用 wx.getUserInfo 获取 $encryptedData = request('encryptedData', ''); $iv = request('iv', '');
// 根据 code 获取用户 openid, session_key $loginInfo = $this->wxxcx->getLoginInfo($code);
// 获取解密后的用户信息 $userInfo = $this->wxxcx->getUserInfo($encryptedData, $iv);
return [ "loginInfo" => $loginInfo, "userInfo" => $userInfo, ];
/* 数据格式: loginInfo : { openid : "xxx", session_key : "xxx", } userInfo : { openId: "xxx", nickName: "用户昵称", gender: 1, language: "zh_CN", city: "", province: "Beijing", country: "China", avatarUrl: "用户头像", watermark: { timestamp: 1544277591, appid: "xxx" } } */ } }
|