dever il y a 2 ans
Parent
commit
5f9e7ad810
1 fichiers modifiés avec 14 ajouts et 18 suppressions
  1. 14 18
      lib/Wechat.php

+ 14 - 18
lib/Wechat.php

@@ -125,7 +125,16 @@ 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($result);
+			if (isset($service['data']) && $service['data']) {
+				return $service['data'];
+			}
+		}
 		$update = false;
 			
 		if ($state == true) {
@@ -144,23 +153,10 @@ class Wechat
 
 		if (is_array($value) || (is_string($value) && strstr($value, 'http://'))) {
 
-			# 为方便测试,这里可以直接用接口返回的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);
-				}
+			if ($refresh) {
+				$result = $this->curl(false, $value, false, $type);
+			} else {
+				$result = $this->curl(false, $value, true, $type);
 			}
 
 			$key = $type;