/** * Get token from WeChat API. * * @return string */ public function getToken() { $cacheKey = $this->prefix . $this->appId; return $this->cache->get($cacheKey, function ($cacheKey) { $params = ['appid' => $this->appId, 'secret' => $this->secret, 'grant_type' => 'client_credential']; $token = $this->http->get(self::API_TOKEN_GET, $params); $this->cache->set($cacheKey, $token['access_token'], $token['expires_in'] - 100); return $token['access_token']; }); }
/** * Get JSSDK ticket. * * @return string */ public function getTicket() { if ($this->ticket) { return $this->ticket; } $key = 'overtrue.wechat.card.api_ticket'; return $this->ticket = $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']; }); }