This commit is contained in:
尖叫 2023-12-08 11:13:54 +08:00
parent 81708abe83
commit ff56dcd1b4

View File

@ -174,11 +174,9 @@ class User extends Controller
public function wxCode()
{
$appid = 'wx89c12dd426a55a2e';
$app_secret = '33e66bcf944f9810abbb5ddd7825403d';
$redirect_uri=$this->request->host().'api/food.user/getWxUserCoupon';
$redirect_uri = $this->request->host() . 'api/food.user/wxLogin';
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
return $this->renderSuccess($url, '成功');
}
@ -197,12 +195,15 @@ class User extends Controller
$access_token = $result['access_token'];
$openid = $result['openid'];
$wx_url = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";
$data = json_decode(Http::get($wx_url), true);
if (isset($data['headimgurl'])) {
Db::name('user_wx')->where(['wx_openid' => $openid])->update(['headimgurl' => $data['headimgurl'], 'nickname' => $data['nickname']]);
return $this->renderSuccess($data, '成功');
$arr = [
'openid' => $openid,
'redirect_uri' => 'https://app.cxhxy.dev.1nww.com/#/pages/details/details'
];
return $this->renderSuccess($arr, '成功');
}
}
return $this->renderError('授权失败');