1
This commit is contained in:
parent
81708abe83
commit
ff56dcd1b4
@ -174,11 +174,9 @@ class User extends Controller
|
|||||||
public function wxCode()
|
public function wxCode()
|
||||||
{
|
{
|
||||||
$appid = 'wx89c12dd426a55a2e';
|
$appid = 'wx89c12dd426a55a2e';
|
||||||
$app_secret = '33e66bcf944f9810abbb5ddd7825403d';
|
$redirect_uri = $this->request->host() . 'api/food.user/wxLogin';
|
||||||
$redirect_uri=$this->request->host().'api/food.user/getWxUserCoupon';
|
|
||||||
$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";
|
$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, '成功');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -196,13 +194,16 @@ class User extends Controller
|
|||||||
if (isset($result['access_token'])) {
|
if (isset($result['access_token'])) {
|
||||||
$access_token = $result['access_token'];
|
$access_token = $result['access_token'];
|
||||||
$openid = $result['openid'];
|
$openid = $result['openid'];
|
||||||
|
|
||||||
|
|
||||||
$wx_url = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";
|
$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);
|
$data = json_decode(Http::get($wx_url), true);
|
||||||
if (isset($data['headimgurl'])) {
|
if (isset($data['headimgurl'])) {
|
||||||
Db::name('user_wx')->where(['wx_openid' => $openid])->update(['headimgurl' => $data['headimgurl'], 'nickname' => $data['nickname']]);
|
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('授权失败');
|
return $this->renderError('授权失败');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user