Esempio n. 1
0
 /**
  * 获取jsticket
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'overtrue.wechat.card.api_ticket';
     return $this->cache->get($key, function ($key) {
         $result = $this->http->get(self::API_TICKET);
         $this->cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
 /**
  * 获取Token
  *
  * @param bool $forceRefresh
  *
  * @return string
  */
 public function getToken($forceRefresh = false)
 {
     $cacheKey = $this->cacheKey;
     $cached = $this->cache->get($cacheKey);
     if ($forceRefresh || !$cached) {
         $token = $this->getTokenFromServer();
         $this->cache->set($cacheKey, $token['access_token'], $token['expires_in'] - 800);
         return $token['access_token'];
     }
     return $cached;
 }
Esempio n. 3
0
 /**
  * 获取jsticket
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'overtrue.wechat.jsapi_ticket.' . $this->appId;
     // for php 5.3
     $appId = $this->appId;
     $appSecret = $this->appSecret;
     $cache = $this->cache;
     $apiTicket = self::API_TICKET;
     return $this->cache->get($key, function ($key) use($appId, $appSecret, $cache, $apiTicket) {
         $http = new Http(new AccessToken($appId, $appSecret));
         $result = $http->get($apiTicket);
         $cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
Esempio n. 4
0
 /**
  * 获取jsticket
  *
  * @return string
  */
 public function getTicket()
 {
     if ($this->ticket) {
         return $this->ticket;
     }
     $key = 'overtrue.wechat.card.api_ticket';
     // for php 5.3
     $http = $this->http;
     $cache = $this->cache;
     return $this->ticket = $this->cache->get($key, function ($key) use($http, $cache) {
         $result = $http->get(self::API_TICKET);
         $cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
 public function updateToken()
 {
     $accessToken = new AccessToken($this->_appId, $this->_secret);
     $token = $accessToken->getToken();
     $cache = new Cache($this->_appId);
     $this->show($token);
     $cache->forget('overtrue.wechat.access_token');
     $this->show($accessToken->getToken());
 }