dever vor 2 Jahren
Ursprung
Commit
d9817c3b62
1 geänderte Dateien mit 20 neuen und 14 gelöschten Zeilen
  1. 20 14
      lib/Wechat.php

+ 20 - 14
lib/Wechat.php

@@ -125,20 +125,13 @@ class Wechat
 		
 		$where['option_project_id'] = $this->project['id'];
 		$info = $db->one($where);
-		# 为方便测试,这里可以直接用接口返回的token
-		if ($type == 'token' && isset($this->project['url']) && $this->project['url']) {
-			$param = array('type' => $type, 'appid' => $this->project['appid']);
-			$param = Dever::token($param, $this->project['secret']);
-			$service = Dever::curl($this->project['url'], $param);
-			$service = Dever::json_decode($service);
-			if (isset($service['data']) && $service['data']) {
-				return array('value' => $service['data']);
-			}
-		}
+
 		$update = false;
 			
 		if ($state == true) {
 			$update = true;
+		} elseif ($type == 'token' && isset($this->project['url']) && $this->project['url']) {
+			$update = true;
 		} elseif ($info && time() - $info['mdate'] >= $info['expires']) {
 			$update = true;
 		} elseif($info) {
@@ -153,10 +146,23 @@ class Wechat
 
 		if (is_array($value) || (is_string($value) && strstr($value, 'http://'))) {
 
-			if ($refresh) {
-				$result = $this->curl(false, $value, false, $type);
-			} else {
-				$result = $this->curl(false, $value, true, $type);
+			# 为方便测试,这里可以直接用接口返回的token
+			$result = array();
+			if ($type == 'token' && isset($this->project['url']) && $this->project['url']) {
+				$param = array('type' => $type, 'appid' => $this->project['appid']);
+				$param = Dever::token($param, $this->project['secret']);
+				$result = Dever::curl($this->project['url'], $param);
+				$result = Dever::json_decode($result);
+				if (isset($result['data'])) {
+					$result = $result['data'];
+				}
+			}
+			if (!$result) {
+				if ($refresh) {
+					$result = $this->curl(false, $value, false, $type);
+				} else {
+					$result = $this->curl(false, $value, true, $type);
+				}
 			}
 
 			$key = $type;