|
@@ -187,6 +187,7 @@ class Wechat
|
|
|
$this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
|
|
|
$this->debug = isset($options['debug'])?$options['debug']:false;
|
|
|
$this->logcallback = isset($options['logcallback'])?$options['logcallback']:false;
|
|
|
+ $this->Cache =Cache::store("Redis");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1092,7 +1093,7 @@ class Wechat
|
|
|
* @return boolean
|
|
|
*/
|
|
|
protected function setCache($cachename,$value,$expired){
|
|
|
- return Cache::set($cachename,$value,$expired);
|
|
|
+ return $this->Cache->set($cachename,$value,$expired);
|
|
|
// return false;
|
|
|
}
|
|
|
|
|
@@ -1104,7 +1105,7 @@ class Wechat
|
|
|
protected function getCache($cachename){
|
|
|
//TODO: get cache implementation
|
|
|
// Cache::get($cachename);
|
|
|
- return Cache::get($cachename);
|
|
|
+ return $this->Cache->get($cachename);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1115,7 +1116,16 @@ class Wechat
|
|
|
protected function removeCache($cachename){
|
|
|
//TODO: remove cache implementation
|
|
|
|
|
|
- return Cache::delete($cachename);
|
|
|
+ return $this->Cache->delete($cachename);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取键值失效时间
|
|
|
+ * @param string $cachename
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ protected function getExpire($cachename){
|
|
|
+ //TODO: remove cache implementation
|
|
|
+ return $this->Cache->ttl($cachename);
|
|
|
}
|
|
|
/**
|
|
|
* 获取access_token
|
|
@@ -1134,13 +1144,15 @@ class Wechat
|
|
|
}
|
|
|
|
|
|
$authname = 'wechat_access_token'.$appid;
|
|
|
-
|
|
|
+ $expire=$this->getExpire($authname);
|
|
|
+ if($expire>0 ||$expire==-1){
|
|
|
if ($rs = $this->getCache($authname)) {
|
|
|
$this->access_token = $rs;
|
|
|
return $rs;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ }else{
|
|
|
+ $this->removeCache($authname);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
$result = $this->http_get(self::API_URL_PREFIX.self::AUTH_URL.'appid='.$appid.'&secret='.$appsecret);
|