Example #1
0
 public function getToken($forceRefresh = 0)
 {
     $cacheKey = 'pakey_weixin_accesstoken_' . $this->appId;
     $data = Cache::get($cacheKey);
     if ($forceRefresh || empty($data)) {
         $token = $this->_getTokenFromServer();
         // XXX: T_T... 7200 - 1500
         Cache::set($cacheKey, $token['access_token'], $token['expires_in'] - 1500);
         return $token['access_token'];
     }
     return $data;
 }
Example #2
0
File: Js.php Project: pakey/weixin
 /**
  * 获取jsticket.
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'pakey_wechat_jsapi_ticket.' . $this->appId;
     $data = Cache::get($key);
     if (!$data || empty($data['ticket'])) {
         $token = $this->getToken();
         $data = $this->parseJSON(Http::get(self::API_TICKET, ['access_token' => $token]));
         if ($data && !empty($data['ticket'])) {
             Cache::set($key, $data, $data['expires_in'] / 10);
         } else {
             $data['ticket'] = null;
         }
     }
     return $data['ticket'];
 }