WeChat development always fails to get the token

Source: Internet
Author: User
Tags openid
Development, always failed to get token $ appid & nbsp; wx1aabc8673b8f103a; $ appsecret & nbsp; 9aa99fc9db9bf1321c1afe05feb29b6c; $ url & nbsp; api. weixin. qq. comcgi-bintoken? Grant _ development, always fail to get 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));


Actually, you can get the token, that is, if you are using it, it will become invalid. what should you do?
------ Solution ----------------------
You can refer to the php script provided by the official php sdk to modify your program,

In addition, do you expose appid and appsecret .......
------ Solution ----------------------
First obtain the code, then use the code to obtain access_token and openid, and then obtain the user information.
------ Solution ----------------------
You only need to pass the token to userinfo. The returned result is openid and the like. you used getdo twice and the token is updated, and the query is the first token value.
------ Solution ----------------------
Openid = {$ appid}
An error is reported.

Step 1: the user agrees to the authorization and obtains the code
Step 2: exchange code for webpage authorization access_token

Reference: http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.