rabin 1 hari lalu
induk
melakukan
c529354c37

+ 4 - 4
app/Lib/Platform.php

@@ -66,7 +66,7 @@ class Platform
         } else {
             Dever::error('account error');
         }
-        $this->field = new Field($field);
+        $this->field = Dever::load(Field::class)->init($field);
         $this->field->setPlatformId($this->platform['id']);
         $this->field->setApid($this->info['id']);
         $this->field->setHost($this->platform['host']);
@@ -90,7 +90,7 @@ class Platform
             $url = $this->url();
         }
         $method = $this->method();
-        $request = new Request($this->field, $this->platform['id'], $this->type, $this->info['id']);
+        $request = Dever::load(Request::class)->init($this->field, $this->platform['id'], $this->type, $this->info['id']);
         $body = $request->body();
         $header = $request->header();
         $json = $this->info['post_method'] == 3 ? true : false;
@@ -99,7 +99,7 @@ class Platform
         $response_body = $curl->result();
         $response_header = $curl->header();
         $response_config = ['id' => $this->platform['id'], 'type' => $this->platform['response_type']];
-        $response = new Response($response_body, $response_header, $this->field, $response_config, $this->type, $this->info['id']);
+        $response = Dever::load(Response::class)->init($response_body, $response_header, $this->field, $response_config, $this->type, $this->info['id']);
         $result = $response->out();
         $log = [];
         $log['platform_id'] = $this->platform['id'];
@@ -129,7 +129,7 @@ class Platform
             $url = $this->url();
         }
         $method = $this->method();
-        $request = new Request($this->field, $this->platform['id'], $this->type, $this->info['id']);
+        $request = Dever::load(Request::class)->init($this->field, $this->platform['id'], $this->type, $this->info['id']);
         $request->body();
         $url .= '?';
         foreach ($this->field->body as $k => $v) {

+ 4 - 3
app/Lib/Platform/Field.php

@@ -4,13 +4,14 @@ class Field
 {
     private $data = [];
     public $ssl;
-    public function __construct($data)
+    public function init($data)
     {
         $this->data = $data;
-        $this->ssl = new Ssl($this);
+        $this->ssl = Dever::load(Ssl::class)->init($this);
         $this->set('time', time());
         $this->set('timestamp', \Dever\Helper\Secure::timestamp());
         $this->set('nonce', \Dever\Helper\Secure::nonce());
+        return $this;
     }
 
     public function add($index, $value, $key = 'body')
@@ -189,7 +190,7 @@ class Field
                     if ($value) {
                         $info['arg'] = $value;
                     }
-                    $value = Sign::load($this, $info)->get();
+                    $value = Dever::get(Sign::class, true, $info['id'])->init($this, $info)->get();
                 }
             }
         }

+ 3 - 2
app/Lib/Platform/Request.php

@@ -2,12 +2,13 @@
 use Dever;
 class Request
 {
-    public function __construct($field, $platform_id, $type, $type_id)
+    public function init($field, $platform_id, $type, $type_id)
     {
         $this->field = $field;
         $this->platform_id = $platform_id;
         $this->type = $type;
         $this->type_id = $type_id;
+        return $this;
     }
 
     public function body()
@@ -36,7 +37,7 @@ class Request
 
     protected function get(&$data, $prefix, $type, $where)
     {
-        $request = Dever::db($prefix . '_request_' . $type, 'api')->select($where);
+        $request = Dever::db('api/' . $prefix . '_request_' . $type)->select($where);
         if ($request) {
             foreach ($request as $k => $v) {
                 $value = $this->field->value($v['value'], $v['type']);

+ 3 - 2
app/Lib/Platform/Response.php

@@ -2,7 +2,7 @@
 use Dever;
 class Response
 {
-    public function __construct($body, $header, $field, $config, $type, $type_id)
+    public function init($body, $header, $field, $config, $type, $type_id)
     {
         $this->body = $body;
         $this->header = $header;
@@ -10,6 +10,7 @@ class Response
         $this->type = $type;
         $this->type_id = $type_id;
         $this->config = $config;
+        return $this;
     }
 
     public function out()
@@ -104,7 +105,7 @@ class Response
         if (!$body) {
             $body = Dever::db('api/platform_response_body')->select(['platform_id' => $this->config['id']]);
         }
-        $value = Value::load($this->field);
+        $value = Dever::load(Value::class)->init($this->field);
         $result = $value->get($body, $data);
         $this->save($value, $result);
         return $result;

+ 8 - 12
app/Lib/Platform/Sign.php

@@ -2,20 +2,16 @@
 use Dever;
 class Sign
 {
-    public static function load($field, $config)
-    {
-        return new self($field, $config);
-    }
-
-    public function __construct($field, $config)
+    public function init($field, $config)
     {
         $this->field = $field;
         $this->config = $config;
+        return $this;
     }
 
     public function get()
     {
-        $this->init();
+        $this->load();
         $this->encrypt();
         $this->after();
         $this->field->set($this->config['name'], $this->info);
@@ -32,7 +28,7 @@ class Sign
             Dever::error('签名验证失败');
         }
         if ($this->config['encrypt'] > 0) {
-            $this->init();
+            $this->load();
             $check = $this->field->ssl->decrypt($this->config['encrypt'], $sign, $this->info);
         } else {
             $check = $sign == $this->get();
@@ -42,7 +38,7 @@ class Sign
         }
     }
 
-    protected function init()
+    protected function load()
     {
         $this->create();
         if ($this->config['kv_sort'] == 2) {
@@ -112,10 +108,10 @@ class Sign
                 $v = Dever::json_encode($v);
             }
             if ($this->config['kv_key_handle']) {
-                $k = Dever::load('util', 'api')->format($this->config['kv_key_handle'], $k);
+                $k = Dever::load(\Api\Lib\Util::class)->format($this->config['kv_key_handle'], $k);
             }
             if ($this->config['kv_value_handle']) {
-                $v = Dever::load('util', 'api')->format($this->config['kv_value_handle'], $v);
+                $v = Dever::load(\Api\Lib\Util::class)->format($this->config['kv_value_handle'], $v);
             }
             if ($this->config['kv_type'] == 1) {
                 $string .= $v;
@@ -163,7 +159,7 @@ class Sign
     protected function after()
     {
         if ($this->config['after']) {
-            $this->info = Dever::load('util', 'api')->format($this->config['after'], $this->info);
+            $this->info = Dever::load(\Api\Lib\Util::class)->format($this->config['after'], $this->info);
         }
     }
 }

+ 4 - 3
app/Lib/Platform/Ssl.php

@@ -2,9 +2,10 @@
 use Dever;
 class Ssl
 {
-    public function __construct($field)
+    public function init($field)
     {
         $this->field = $field;
+        return $this;
     }
 
     public function encrypt($id, $value)
@@ -54,7 +55,7 @@ class Ssl
 
     protected function config($id, $type, $value)
     {
-        $config = Dever::db('platform_ssl', 'api')->find($id);
+        $config = Dever::db('api/platform_ssl')->find($id);
         if (!$config) {
             return false;
         }
@@ -106,7 +107,7 @@ class Ssl
             $project = $this->field->account_project;
             $account_id = $this->field->account_id;
             if ($project && $account_id) {
-                $cert = Dever::db('account_cert', $project)->find(['account_id' => $account_id, 'platform_cert_id' => $config['cert_id']], ['order' => 'edate desc']);
+                $cert = Dever::db($project . '/account_cert')->find(['account_id' => $account_id, 'platform_cert_id' => $config['cert_id']], ['order' => 'edate desc']);
             }
             if (!$cert) {
                 $config['cert'] = false;

+ 2 - 6
app/Lib/Platform/Value.php

@@ -2,14 +2,10 @@
 use Dever;
 class Value
 {
-    public static function load($field)
-    {
-        return new self($field);
-    }
-
-    public function __construct($field)
+    public function init($field)
     {
         $this->field = $field;
+        return $this;
     }
 
     public function get($config, $data)

+ 5 - 3
app/Lib/Util.php

@@ -18,7 +18,9 @@ class Util
     public function setting($key, $account, $project = 'api')
     {
         $setting = Dever::db('api/platform_setting')->find(['key' => $key]);
-        $setting = Dever::db($project . '/account_setting')->find(['account_id' => $account, 'platform_setting_id' => $setting['id']]);
+        if ($setting) {
+            $setting = Dever::db($project . '/account_setting')->find(['account_id' => $account, 'platform_setting_id' => $setting['id']]);
+        }
         $value = $setting['value'] ?? 0;
         return $value;
     }
@@ -61,7 +63,7 @@ class Util
     # 获取token
     public function token($account, $env, $project = 'api')
     {
-        $account = Dever::load(Account::clas)->get($account, $project);
+        $account = Dever::load(Account::class)->get($account, $project);
         $result = '';
         if ($env == 5) {
             $appid = 'applet_appid';
@@ -75,7 +77,7 @@ class Util
             if ($info && time() <= $info['edate']) {
                 $result = $info['token'];
             } else {
-                $data = Dever::load(Account::clas)->run($account, 'access_token', $param, 1, 'run', $project);
+                $data = Dever::load(Account::class)->run($account, 'access_token', $param, 1, 'run', $project);
                 if (isset($data['access_token'])) {
                     $result = $data['access_token'];
                     $param['token'] = $result;