七、获取access_token

原文地址:http://www.cnblogs.com/txw1958/p/weixin-access-token.html

(这个token和微信登录的token不是同一个)

$appid = "";
$appsecret = "";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";

$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);
print_r($jsoninfo);

只需填入appid和appsecret就行。
打印出来的格式是这样的:

Array ( 
[access_token] => M_tI7axFRkdt6-E4sbf9mAlKIM9GW-6cqiozM_k5O1U5nuHc9zWhQtYcxHYVnrjOaYaWThdtzfVR198-8SOIr09A50FEfseyMFZ1W5-IlXFTSa51f3rW8S2nTSbDW3zKDNXhAEAMWG 
[expires_in] => 7200 
) 

你可能感兴趣的:(七、获取access_token)