小插曲就是app做微信三方登陆是很久之前,后面又添加了pc的微信三方登陆,而文档上说unionid是同一个账号下不同应用统一的,但是app拿的是uid,导致pc拿的unionid始终对不上,导致浪费了一天的时间都在需找资料统一的问题,还有问题是解决了!希望小伙伴们做app的和pc微信三方登陆的时候一定要注意,app和pc都要拿unionid!好了下面就开始教大家怎么整合pc的微信三方登陆了:
1、申请时候所填写的信息,主要网站信息登记表扫描件是客户提供意外其他都是自己填写,注意的是授权回调域要写一级域名,和调用的时候recudirt_url保持一致
调用接口的步骤
(1):
注意了这个微信的小图标就是微信登陆的链接了,也就是a标签,href是这个值(官方文档1号店的微信登陆)
https://open.weixin.qq.com/connect/qrconnect?appid=wxbdc5610cc59c1631&redirect_uri=https://passport.yhd.com/wechat/callback.do&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect
(2)上面的链接会返回一个code的参数,这个是换取access_token和openid值的媒介,之后呢就逻辑判断了
if(isset($_get['code'])&&$_get['state'] =='3d6be0a4035d839573b04816624a415e') {
//调用的是获取用户的个人信息的方法
$res = $this->message_request($code);
}
public function message_request($code){
//修改自己的
$appid = wx16a15xxxxxxxxx;
$appsecret = fc4b2b999787cxxxxxxxxxxx;
//修改自己的
$url = https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code;
$output = $this->httpsrequest($url);
$jsoninfo = json_decode($output, true);
$openid = $jsoninfo[openid];
$access_token = $jsoninfo['access_token'];
$url = https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_cn;
$output = $this->httpsrequest($url);
$message = json_decode($output,true);
return $message;
}
public function httpsrequest($url,$data = null){
$curl = curl_init();
curl_setopt($curl, curlopt_url, $url);
curl_setopt($curl, curlopt_ssl_verifypeer, false);
curl_setopt($curl, curlopt_ssl_verifyhost, false);
if (!empty($data)){
curl_setopt($curl, curlopt_post, 1);
curl_setopt($curl, curlopt_postfields, $data);
}
curl_setopt($curl, curlopt_returntransfer, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
重要:
access_token和微信公众平台用户授权登陆不一样,微信公众平台的有限制一天,开放平台的没有限制,而且必须是同时生成,不能过期,app和pc用户的信息保持同步就都用[unionid] 这个是同一个开放平台下的不同应用[unionid] 是唯一的,app和pc都要拿这个
得到的结果
array(10) { [openid] => string(28) od5xqwgvj1glb3_zgjp72udgesyk [nickname] => string(6) 刘柱 //用户的昵称 [sex] => int(1) //性别 1:男 [language] => string(5) zh_cn [city] => string(6) 南开 //区 [province] => string(7) 天津 //省 [country] => string(2) 天津 //市 [headimgurl] => string(129) http://wx.qlogo.cn/mmopen/aqvs6rqd9yjtthtcyb0aqloq3rboynl3cyejleogbib53y6xiaibzvfz6qudapekupg10scykkdvpwkiayuj3dmxjnicovkv73x1k/0 //用户的头像 [privilege] => array(0) { } [unionid] => string(28) o2vj4xeuwd51_7f2bhisybhf3fvk //unionid app和pc信息保持一致的基准 }
