/** * 调用微信SDK接口,获得相关Token * @return 微信SDK接口返回的Token */ private function getAccessToken() { // access_token 应该全局存储与更新,以下代码以写入到文件中做示例 $data = json_decode(CTools::GetPHPFileContent("access_token.php")); if ($data->expire_time < time()) { // 如果是企业号用以下URL获取access_token //$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appID&corpsecret=$this->appSecret"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appID}&secret={$this->appSecret}"; $res = json_decode(CTools::httpGet($url)); //CTools::SetPHPFileContent("jsapi_token_original.php", json_encode($res)); $access_token = $res->access_token; if ($access_token) { $data->expire_time = time() + 7000; $data->access_token = $access_token; CTools::SetPHPFileContent("access_token.php", json_encode($data)); } } else { $access_token = $data->access_token; } return $access_token; }