php微信 - 2获取AccessToken

来源:转载

获取AccessToken

<?php $wechatObj = new wechatCallAPI(); $wechatObj ->getAccessToken(); class wechatCallAPI { private $token = "weixin"; private $appId = "appId "; private $appSecret = "appSecret";// 获取AccessToken public function getAccessToken(){ $AppId = $this->appId; $AppSecret = $this->appSecret; $getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $getUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $data = curl_exec($ch); $response = json_decode($data); echo'<pre>'; var_dump($AppId); var_dump($AppSecret); var_dump($getUrl); var_dump($response); echo'</pre>'; return $response->access_token; } }?>

分享给朋友:
您可能感兴趣的文章:
随机阅读: