使用微信JS-SDK开发时无法获得access_token

在微信公众平台接口调试工具(http://mp.weixin.qq.com/debug)使用appid和appSecret能够获取access_token。但是在服务器页面上使用微信官方的demo(http://demo.open.weixin.qq.com/jssdk/sample.zip),这个函数无法取得access_token private function getAccessToken() { $data = json_decode(file_get_contents("access_token.json")); if ($data->expire_time < time()) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; $res = json_decode($this->httpGet($url)); $access_token = $res->access_token; if ($access_token) { $data->expire_time = time() + 7000; $data->access_token = $access_token; $fp = fopen("access_token.json", "w"); fwrite($fp, json_encode($data)); fclose($fp); } } else { $access_token = $data->access_token; } return $access_token; }已确定服务器支持json_decode的,也没有触发频率限制。现在无法得到access_token,导致无法得到jsapi_ticket,最后无法使用微信JS-SDK各项功能。请教高手
2026年09月28日 19:35
有2个网友回答
网友(1):

看起来是前面错误了,建议一步一步print出来,看看中间是哪个变量没有取到。

网友(2):

错误代码是什么?