http://blog.csdn.net/u011415782/article/details/51870790
具体可以参考这个文档写的很详细。
那么问题来了,具体是什么问题导致了,不能正常获取文件接口呢? 哎,主要是token 和 jsapi_ticket 导致的,
写文件到了本地,那么我如果是多个号进行 操作 ,就会导致不能正确的获取接口
应该怎么操作? 保存为不同的文件名,
保存的文件名可以为
"jsapi_ticket".$this->appId.".php"
不会重名即可。
private function getJsApiTicket() { // jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例 $data = json_decode($this->get_php_file("jsapi_ticket".$this->appId.".php")); if ($data->expire_time < time()) { $accessToken = $this->getAccessToken(); // 如果是企业号用以下 URL 获取 ticket // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; $res = json_decode($this->httpGet($url)); $ticket = $res->ticket; if ($ticket) { $data->expire_time = time() + 7000; $data->jsapi_ticket = $ticket; $this->set_php_file("jsapi_ticket".$this->appId.".php", json_encode($data)); } } else { $ticket = $data->jsapi_ticket; } return $ticket; } private function getAccessToken() { // access_token 应该全局存储与更新,以下代码以写入到文件中做示例 $data = json_decode($this->get_php_file("access_token".$this->appId.".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($this->httpGet($url)); $access_token = $res->access_token; if ($access_token) { $data->expire_time = time() + 7000; $data->access_token = $access_token; $this->set_php_file("access_token".$this->appId.".php", json_encode($data)); } } else { $access_token = $data->access_token; } return $access_token; }