| @@ 103-117 (lines=15) @@ | ||
| 100 | * |
|
| 101 | * @return string |
|
| 102 | */ |
|
| 103 | public function ticket($forceRefresh = false) |
|
| 104 | { |
|
| 105 | $key = self::TICKET_CACHE_PREFIX.$this->getAccessToken()->getAppId(); |
|
| 106 | $ticket = $this->getCache()->fetch($key); |
|
| 107 | ||
| 108 | if (!$forceRefresh && !empty($ticket)) { |
|
| 109 | return $ticket; |
|
| 110 | } |
|
| 111 | ||
| 112 | $result = $this->parseJSON('get', [self::API_TICKET, ['type' => 'jsapi']]); |
|
| 113 | ||
| 114 | $this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500); |
|
| 115 | ||
| 116 | return $result['ticket']; |
|
| 117 | } |
|
| 118 | ||
| 119 | /** |
|
| 120 | * Build signature. |
|
| @@ 178-193 (lines=16) @@ | ||
| 175 | * |
|
| 176 | * @return string $apiTicket |
|
| 177 | */ |
|
| 178 | public function getAPITicket($refresh = false) |
|
| 179 | { |
|
| 180 | $key = $this->getTicketCacheKey(); |
|
| 181 | ||
| 182 | $ticket = $this->getCache()->fetch($key); |
|
| 183 | ||
| 184 | if (!$ticket || $refresh) { |
|
| 185 | $result = $this->parseJSON('get', [self::API_GET_CARD_TICKET, ['type' => 'wx_card']]); |
|
| 186 | ||
| 187 | $this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500); |
|
| 188 | ||
| 189 | return $result['ticket']; |
|
| 190 | } |
|
| 191 | ||
| 192 | return $ticket; |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * 微信卡券:JSAPI 卡券发放. |
|