微信开发,总是获取token失败
$appid = 'wx1aabc8673b8f103a';
$appsecret = '9aa99fc9db9bf1321c1afe05feb29b6c';
$url = https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret;
$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx1aabc8673b8f103a&secret=9aa99fc9db9bf1321c1afe05feb29b6c';
//echo $access_token;
function getdo($url){
$ch = curl_init();
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_ssl_verifypeer, false);
curl_setopt($ch, curlopt_ssl_verifyhost, false);
curl_setopt($ch, curlopt_returntransfer, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
return $jsoninfo;
}
$arr=getdo($url);
$info_url = https://api.weixin.qq.com/sns/userinfo?access_token={$arr[access_token]}&openid={$appid}&lang=zh_cn;
print_r(getdo($info_url));
其实是能获取token,就是在使用是,就失效了,怎么办啊?
------解决思路----------------------
微信 有提供官方的php sdk 可以参照其提供的php脚本 来修改你的程序,
另外 话说你是不是把appid和appsecret暴露了.......
------解决思路----------------------
先获取code 然后利用code获取access_token和openid 然后获取用户信息
------解决思路----------------------
userinfo只要传token就可以了。返回的是openid之类的,还有,你用了2次getdo,token更新了,而查询的是第一次的token值
------解决思路----------------------
openid={$appid}
传错了。
第一步:用户同意授权,获取code
第二步:通过code换取网页授权access_token
参考:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html