Beispiel #1
0
 protected function _getTokenFromServer()
 {
     $params = ['appid' => $this->appId, 'secret' => $this->appSecret, 'grant_type' => 'client_credential'];
     $token = $this->parseJSON(Http::get(self::API_TOKEN_GET, $params));
     if (empty($token['access_token'])) {
         trigger_error('Request AccessToken fail. response: ' . json_encode($token, JSON_UNESCAPED_UNICODE), E_USER_ERROR);
     }
     return $token;
 }
Beispiel #2
0
 /**
  * 获取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'];
 }
Beispiel #3
0
 /**
  * 获取access token
  *
  * @param string $code
  *
  * @return string
  */
 public function getAccessPermission($code)
 {
     $params = array('appid' => $this->appId, 'secret' => $this->appSecret, 'code' => $code, 'grant_type' => 'authorization_code');
     $res = $this->parseJSON(Http::post(self::API_TOKEN_GET . '?' . http_build_query($params)));
     if (isset($res['errorcode'])) {
         trigger_error('get access_token error: ' . $res['errormsg'], E_USER_ERROR);
     }
     return $this->lastPermission = $res;
 }
Beispiel #4
0
 /**
  * 获取jsticket.
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'pakey_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'];
     });
 }