Home > Backend Development > PHP Tutorial > 微信开发,老是获取token失败

微信开发,老是获取token失败

WBOY
Release: 2016-06-13 12:22:48
Original
1237 people have browsed it

微信开发,总是获取token失败

<br /><br />$appid = 'wx1aabc8673b8f103a';<br />$appsecret = '9aa99fc9db9bf1321c1afe05feb29b6c';<br />$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";<br />$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx1aabc8673b8f103a&secret=9aa99fc9db9bf1321c1afe05feb29b6c';<br /><br /><br />//echo $access_token;<br /><br />function getDo($url){<br />$ch = curl_init();<br />curl_setopt($ch, CURLOPT_URL, $url);<br />curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); <br />curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); <br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />$output = curl_exec($ch);<br />curl_close($ch);<br />$jsoninfo = json_decode($output, true);<br /><br />return $jsoninfo;<br />}<br /><br />$arr=getDo($url);<br /><br /><br />$info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$arr["access_token"]}&openid={$appid}&lang=zh_CN";<br /><br /><br /><br />        print_r(getDo($info_url));<br />
Copy after login


其实是能获取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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template