微信開發,老是擷取token失敗

來源:互聯網
上載者:User
開發,總是擷取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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.