Example #1
0
File: WJS.php Project: enozoom/es
 /**
  * 获取JS票据
  * @param string $access_token 
  * @return string
  */
 public function jsapi_ticket($access_token)
 {
     // 从没有获取过access_token或者已经过期
     $path = FileStatic::cache_file();
     if (file_exists($path)) {
         $ticket = json_decode(file_get_contents($path));
         if ($ticket->expires > time()) {
             return $ticket->ticket;
         }
     }
     $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi';
     $json = json_decode($this->curlGet(sprintf($url, $access_token)));
     if ($json->errcode) {
         die('get jsapi_ticket fail!');
     } else {
         $ticket = array('expires' => time() + $json->expires_in, 'ticket' => $json->ticket);
         file_put_contents($path, json_encode($ticket));
         return $json->ticket;
     }
     return '';
 }