Skip to content

Commit

Permalink
修正当yii2-wx在一个程序中支持多个公众号时引发的js ticket互相覆盖问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
abei2017 committed Jul 25, 2018
1 parent 294db6e commit 5d6c28a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/mp/js/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ public function getSignature($ticket,$nonce,$timestamp,$url){
*/
public function ticket(){

$ticket = Yii::$app->cache->get($this->cacheKey);
$cacheKey = "{$this->cacheKey}-{$this->conf['app_id']}";
$ticket = Yii::$app->cache->get($cacheKey);
if($ticket == false){
// 从服务器获取
$accessToken = (new AccessToken(['conf'=>$this->conf,'httpClient'=>$this->httpClient]))->getToken();
$response = $this->get(self::API_TICKET."?access_token={$accessToken}&type=jsapi")->send();

$data = $response->setFormat(Client::FORMAT_JSON)->getData();
$ticket = $data['ticket'];
Yii::$app->cache->set($this->cacheKey,$ticket,$data['expires_in']-600);
Yii::$app->cache->set($cacheKey,$ticket,$data['expires_in']-600);
}

return $ticket;
Expand Down

0 comments on commit 5d6c28a

Please sign in to comment.