rabin 1 dzień temu
rodzic
commit
c2f4024f08
4 zmienionych plików z 28 dodań i 36 usunięć
  1. 2 12
      app/Api/Notify.php
  2. 3 3
      app/Api/Oauth.php
  3. 2 2
      app/Api/Task.php
  4. 21 19
      app/Lib/Platform/Value.php

+ 2 - 12
app/Api/Notify.php

@@ -70,10 +70,8 @@ class Notify extends Api
         $body = $this->body($input);
         $this->header();
         $this->verify();
-
         # 判断是否成功
         $status = $this->status($body);
-
         if ($status < 3 && isset($method)) {
             $param[] = $status;
             $param[] = $body;
@@ -94,15 +92,7 @@ class Notify extends Api
     protected function body($body)
     {
         $config = Dever::db('api/api_notify_body')->select(['api_id' => $this->info['id']]);
-        $result = Value::load($this->field)->get($config, $body);
-        if ($result) {
-            foreach ($config as $k => $v) {
-                if (isset($body[$v['value']])) {
-                    $value = $this->field->value($body[$v['value']], $v['type'], false);
-                    $this->field->set($v['key'], $value);
-                }
-            }
-        }
+        $result = Dever::load(Value::class)->init($this->field)->get($config, $body);
         return $result;
     }
 
@@ -135,7 +125,7 @@ class Notify extends Api
             Dever::error('签名验证失败');
         }
         $info = Dever::db('api/platform_sign')->find($this->notify['sign_id']);
-        Sign::load($this->field, $info)->check($this->notify['sign_arg']);
+        Dever::get(Sign::class, true, $info['id'])->init($this->field, $info)->get();
     }
 
     protected function status($body)

+ 3 - 3
app/Api/Oauth.php

@@ -22,14 +22,14 @@ class Oauth
                 'refer' => Secure::encode($refer),
             )
         ));
-        Dever::load('api/account')->run($this->account, 'oauth_code', $param, 1, 'jump');
+        Dever::load(\Api\Lib\Account::class)->run($this->account, 'oauth_code', $param, 1, 'jump');
     }
 
     # 获取token
     public function token()
     {
         $param['code'] = Dever::input('code', 'is_string', 'code');
-        $data = Dever::load('api/account')->run($this->account, 'oauth_token', $param);
+        $data = Dever::load(\Api\Lib\Account::class)->run($this->account, 'oauth_token', $param);
         if ($data && isset($data['openid'])) {
             if ($t = Secure::checkLogin($this->t)) {
                 if ($t['uid'] && $t['uid'] > 0) {
@@ -58,7 +58,7 @@ class Oauth
     {
         $param['access_token'] = $data['access_token'];
         $param['openid'] = $data['openid'];
-        $data = Dever::load('api/account')->run($this->account, 'oauth_user', $param);
+        $data = Dever::load(\Api\Lib\Account::class)->run($this->account, 'oauth_user', $param);
         if ($data) {
             # 获取到用户了
         }

+ 2 - 2
app/Api/Task.php

@@ -12,7 +12,7 @@ class Task
             foreach ($data as $k => $v) {
                 $account = Dever::db('api/account')->find(['app_id' => $v['app_id']]);
                 if ($account) {
-                    Dever::load('api/account')->run($account, $v);
+                    Dever::load(\Api\Lib\Account::class)->run($account, $v);
                 }
             }
         }
@@ -24,6 +24,6 @@ class Task
     public function api()
     {
         $param = Dever::input();
-        return Dever::load('api/api')->run($param['api_id'], $param);
+        return Dever::load(\Api\Lib\Api::class)->run($param['api_id'], $param);
     }
 }

+ 21 - 19
app/Lib/Platform/Value.php

@@ -35,13 +35,14 @@ class Value
 
     public function convert($array, $source, $dest, $type = '')
     {
+        $default = $source;
         $source = explode('.', $source);
         $dest = explode('.', $dest);
-        $extracted = $this->extracted($array, $source, $type);
+        $extracted = $this->extracted($array, $source, $default, $type);
         return $this->transform($extracted, $dest);
     }
 
-    public function extracted(&$array, $source, $type = '')
+    public function extracted(&$array, $source, $default, $type = '')
     {
         $current = array_shift($source);
         if (substr($current, -2) == '[]') {
@@ -49,7 +50,7 @@ class Value
             $result = [];
             if (isset($array[$current]) && is_array($array[$current])) {
                 foreach ($array[$current] as $item) {
-                    $sub = $this->extracted($item, $source, $type);
+                    $sub = $this->extracted($item, $source, $default, $type);
                     if ($sub !== null) {
                         $result[] = $sub;
                     }
@@ -62,12 +63,12 @@ class Value
                 if (empty($source)) {
                     $result = $array[$current];
                 } else {
-                    return $this->extracted($array[$current], $source, $type);
+                    return $this->extracted($array[$current], $source, $default, $type);
                 }
             } elseif ($this->field->$current) {
                 $result = $this->field->$current;
             } else {
-                $result = $current;
+                $result = $default;
             }
             if ($type) {
                 $result .= '||' . $type;
@@ -102,12 +103,13 @@ class Value
         if (!is_array($data)) {
             return $data;
         }
+        /*
         foreach ($data as $k => $v) {
             if (!is_array($v)) {
                 $temp = explode('||', $v);
                 $this->field->set($k, $temp[0]);
             }
-        }
+        }*/
         foreach ($data as $k => $v) {
             if (is_array($v)) {
                 if (isset($v[0])) {
@@ -122,28 +124,28 @@ class Value
                 if (empty($temp[1])) {
                     $temp[1] = '';
                 }
+                $value = $temp[0];
+                $type = $temp[1];
+                if (strstr($value, '.')) {
+                    $value = $this->extracted($data, explode('.', $value), $value);
+                }
                 $state = false;
                 # 临时特殊处理,以后封装
-                if (strstr($temp[0], '\n')) {
-                    $array = explode('\n', $temp[0]);
-                    foreach ($array as &$v1) {
-                        if (isset($data[$v1])) {
-                            $v1 = $data[$v1];
-                        }
-                    }
-                    $temp[0] = implode("\n", $array);
-                    $state = true;
-                } elseif (strstr($temp[0], '+')) {
-                    $array = explode('+', $temp[0]);
+                if (strstr($value, '\n')) {
+                    $array = explode('\n', $value);
                     foreach ($array as &$v1) {
                         if (isset($data[$v1])) {
                             $v1 = $data[$v1];
                         }
                     }
-                    $temp[0] = implode('', $array);
+                    $value = implode("\n", $array);
                     $state = true;
+                } 
+                
+                $data[$k] = $this->field->value($value, $type, $state);
+                if (!$state && strpos($data[$k], '{') === 0) {
+                    $data[$k] = Dever::json_decode($data[$k]);
                 }
-                $data[$k] = $this->field->value($temp[0], $temp[1], $state);
                 $this->field->set($k, $data[$k]);
             }
         }