rabin vor 6 Monaten
Ursprung
Commit
fdb22aee94
50 geänderte Dateien mit 1246 neuen und 867 gelöschten Zeilen
  1. 23 17
      api/Notify.php
  2. 72 0
      api/Oauth.php
  3. 15 1
      lib/App.php
  4. 58 59
      lib/Platform.php
  5. 83 40
      lib/Platform/Field.php
  6. 9 7
      lib/Platform/Request.php
  7. 30 172
      lib/Platform/Response.php
  8. 77 50
      lib/Platform/Sign.php
  9. 13 11
      lib/Platform/Value.php
  10. 4 4
      lib/Spec.php
  11. 80 3
      lib/Util.php
  12. 24 2
      manage/account.php
  13. 2 2
      manage/account_cert.php
  14. 8 7
      manage/account_setting.php
  15. 53 104
      manage/api.php
  16. 36 0
      manage/api_notify.php
  17. 0 0
      manage/api_path.php
  18. 2 0
      manage/api_query.php
  19. 0 21
      manage/api_response.php
  20. 2 0
      manage/api_setting.php
  21. 61 0
      manage/app_func.php
  22. 0 0
      manage/app_func_input.php
  23. 0 0
      manage/app_func_output.php
  24. 14 5
      manage/core.php
  25. 42 0
      manage/format.php
  26. 34 64
      manage/platform.php
  27. 1 27
      manage/platform_cert.php
  28. 14 1
      manage/platform_request_body.php
  29. 5 0
      manage/platform_response_code.php
  30. 104 0
      manage/platform_sign.php
  31. 5 5
      manage/platform_ssl.php
  32. 1 1
      table/account_setting.php
  33. 2 38
      table/api.php
  34. 51 9
      table/api_log.php
  35. 38 0
      table/api_notify.php
  36. 7 9
      table/api_path.php
  37. 13 0
      table/api_query.php
  38. 13 0
      table/api_setting.php
  39. 13 0
      table/app_func.php
  40. 2 2
      table/app_func_input.php
  41. 2 2
      table/app_func_output.php
  42. 49 0
      table/format.php
  43. 31 0
      table/openid.php
  44. 2 169
      table/platform.php
  45. 11 27
      table/platform_request_body.php
  46. 14 2
      table/platform_response_code.php
  47. 120 0
      table/platform_sign.php
  48. 2 2
      table/sku.php
  49. 2 2
      table/spec.php
  50. 2 2
      table/spec_value.php

+ 23 - 17
api/Notify.php

@@ -5,6 +5,7 @@ use Api\Lib\Platform\Sign;
 use Api\Lib\Platform\Value;
 class Notify extends Api
 {
+    private $notify;
     public function common()
     {
         $input = Dever::input();
@@ -44,7 +45,11 @@ class Notify extends Api
         if (!$input) {
             $this->error('error');
         }
-        if ($this->info['notify_type'] == 2) {
+        if ($this->info['notify'] == 2) {
+            $this->error('error');
+        }
+        $this->notify = Dever::db('api_notify', 'api')->find(array('api_id' => $api_id));
+        if (!$this->notify) {
             $this->error('error');
         }
         $body = $this->body($input);
@@ -65,7 +70,7 @@ class Notify extends Api
 
         # 返回给上游信息
         if ($status == 1) {
-            echo $this->info['notify_success'];die;
+            echo $this->notify['success'];die;
         } elseif ($status == 2) {
             $this->error('error');
         }
@@ -74,8 +79,7 @@ class Notify extends Api
     protected function body($body)
     {
         $config = Dever::db('api_notify_body', 'api')->select(array('api_id' => $this->info['id']));
-        $value = new Value($this->field, $this->sign);
-        $result = $value->get($config, $body);
+        $result = Value::load($this->field)->get($config, $body);
         if ($result) {
             foreach ($config as $k => $v) {
                 if (isset($body[$v['value']])) {
@@ -99,22 +103,24 @@ class Notify extends Api
                 }
             }
         }
+        $config = Dever::db('api_response_header', 'api')->select(array('api_id' => $this->info['id']));
+        if ($config) {
+            foreach ($config as $k => $v) {
+                if (isset($header[$v['value']])) {
+                    $value = $this->field->value($header[$v['value']], $v['type'], false);
+                    $this->field->set($v['key'], $value);
+                }
+            }
+        }
     }
 
     protected function verify()
     {
-        $this->sign['verify_set'] = explode(',', $this->sign['verify_set']);
-        if (!in_array(1, $this->sign['verify_set'])) {
-            return;
-        }
-        if (!$this->field->sign) {
+        if (!$this->notify['sign_id']) {
             Dever::error('签名验证失败');
         }
-        if ($this->sign['verify_col']) {
-            $this->sign['col'] = $this->sign['verify_col'];
-        }
-        $sign = new Sign($this->field, $this->sign);
-        $sign->check($this->field->sign);
+        $info = Dever::db('platform_sign', 'api')->find($this->notify['sign_id']);
+        Sign::load($this->field, $info)->check($this->notify['sign_arg']);
     }
 
     protected function status($body)
@@ -134,13 +140,13 @@ class Notify extends Api
 
     protected function error($msg)
     {
-        if ($this->info && $this->info['notify_error']) {
-            $temp = explode("\n", $this->info['notify_error']);
+        if ($this->notify && $this->notify['error']) {
+            $temp = explode("\n", $this->notify['error']);
             if (!isset($temp[1])) {
                 $temp[1] = 500;
             }
             $this->code($temp[1]);
-            echo $this->info['notify_error'];die;
+            echo $this->notify['error'];die;
         }
         echo $msg;die;
     }

+ 72 - 0
api/Oauth.php

@@ -0,0 +1,72 @@
+<?php namespace Api\Api;
+use Dever;
+use Dever\Helper\Secure;
+class Oauth
+{
+    public function __construct()
+    {
+        $this->t = Dever::input('t', 'is_string', 't');
+        $this->account = Dever::input('account', 'is_string', '通信账户');
+    }
+
+    # 获取code
+    public function code()
+    {
+        $refer = Dever::input('refer');
+        $scope = Dever::input('scope', 'is_string', 'scope', 'snsapi_base');
+        $param['scope'] = $scope;
+        $param['redirect_uri'] = urlencode(Dever::url('api/oauth.token', array
+            (
+                't' => $this->t,
+                'account' => $this->account,
+                'refer' => Secure::encode($refer),
+            )
+        ));
+        Dever::load('account', 'api')->run($this->account, 'oauth_code', $param, 1, 'jump');
+    }
+
+    # 获取token
+    public function token()
+    {
+        $param['code'] = Dever::input('code', 'is_string', 'code');
+        $data = Dever::load('account', 'api')->run($this->account, 'oauth_token', $param);
+        if ($data && isset($data['openid'])) {
+            if ($t = Secure::checkLogin($this->t)) {
+                if ($t['uid'] && $t['uid'] > 0) {
+                    $update['uid'] = $t['uid'];
+                    $update['account_id'] = $data['account_id'];
+                    $update['env'] = 3;
+                    $info = Dever::db('openid', 'api')->find($update);
+                    if (!$info) {
+                        $update['openid'] = $data['openid'];
+                        Dever::db('openid', 'api')->insert($update);
+                    }
+                }
+            }
+            if (isset($data['scope']) && $data['scope'] == 'snsapi_userinfo') {
+                $user = $this->user($data);
+            }
+        }
+        $refer = Secure::decode(Dever::input('refer'));
+        if ($refer) {
+            header('location:' . $refer);
+        }
+    }
+
+    # 获取用户信息
+    public function user($data)
+    {
+        $param['access_token'] = $data['access_token'];
+        $param['openid'] = $data['openid'];
+        $data = Dever::load('account', 'api')->run($this->account, 'oauth_user', $param);
+        if ($data) {
+            # 获取到用户了
+        }
+    }
+
+    # 根据refresh_token获取token
+    public function refreshToken($id)
+    {
+
+    }
+}

+ 15 - 1
lib/App.php

@@ -20,6 +20,13 @@ class App
         }
     }
 
+    public function updateApi($db, $data)
+    {
+        if (isset($data['notify']) && $data['notify'] == 2) {
+            Dever::db('api/api_notify')->delete(array('api_id' => $data['id']));
+        }
+    }
+
     public function getPlatform($app)
     {
         $set['join'] = array
@@ -67,8 +74,15 @@ class App
         $set['order'] = 'app_func_work.sort asc,api.id desc';
         $where['app_func_work.app_func_id'] = $func_id;
         if ($env) {
-            $where['api.env_type'] = $env;
+            $where['api.env'] = $env;
         }
         return Dever::db('app_func_work', 'api')->select($where, $set);
     }
+
+    public function getAppPlatform($app_id, $platform_id)
+    {
+        $app = Dever::db('app', 'api')->find($app_id);
+        $platform = Dever::db('platform', 'api')->find($platform_id);
+        return $app['name'] . '-' . $platform['name'];
+    }
 }

+ 58 - 59
lib/Platform.php

@@ -1,7 +1,6 @@
 <?php namespace Api\Lib;
 use Dever;
 use Api\Lib\Platform\Field;
-use Api\Lib\Platform\Sign;
 use Api\Lib\Platform\Ssl;
 use Api\Lib\Platform\Request;
 use Api\Lib\Platform\Response;
@@ -33,17 +32,6 @@ class Platform
         if (!$this->platform) {
             Dever::error('platform error');
         }
-        $this->sign = $this->response = array('id' => $this->platform['id']);
-        foreach ($this->platform as $k => $v) {
-            if (strstr($k, 'sign_')) {
-                $k = str_replace('sign_', '', $k);
-                $this->sign[$k] = $v;
-            }
-            if (strstr($k, 'response_')) {
-                $k = str_replace('response_', '', $k);
-                $this->response[$k] = $v;
-            }
-        }
         if ($this->info['method'] == -1) {
             $this->info['method'] = $this->platform['method'];
             $this->info['post_method'] = $this->platform['post_method'];
@@ -56,6 +44,8 @@ class Platform
     protected function field($field)
     {
         if (isset($field['account_project']) && isset($field['account_id'])) {
+            $this->info['account_id'] = $field['account_id'];
+            $this->info['account_project'] = $field['account_project'];
             $setting = Dever::db('account_setting', $field['account_project'])->select(array('account_id' => $field['account_id']));
             if ($setting) {
                 foreach ($setting as $k => $v) {
@@ -69,51 +59,62 @@ class Platform
                     }
                 }
             }
+        } else {
+            Dever::error('account error');
         }
         $this->field = new Field($field);
+        $this->field->setPlatformId($this->platform['id']);
+        $this->field->setApid($this->info['id']);
         $this->field->setHost($this->platform['host']);
         $this->field->setUri($this->info['uri']);
         $this->field->setNotify($this->createNotify($field));
+
+        $setting = Dever::db('api_setting', 'api')->select(array('api_id' => $this->info['id']));
+        if ($setting) {
+            foreach ($setting as $k => $v) {
+                $this->field->set($v['key'], $this->field->value($v['value'], $v['type']));
+            }
+        }
     }
 
     # 发起请求
     protected function curl($url = false)
     {
+        # 生成请求ID
+        $this->field->createRequestId();
         if (!$url) {
             $url = $this->url();
         }
         $method = $this->method();
         $request = new Request($this->field, $this->platform['id'], $this->type, $this->info['id']);
-        $request_body = $request->body();
-        if ($this->info['sign_col']) {
-            $this->platform['sign_col'] = $this->info['sign_col'];
-        }
-        $sign = new Sign($this->field, $this->sign);
-        $sign = $sign->get();
-
-        if ($this->platform['sign_name']) {
-            $request_body[$this->platform['sign_name']] = $sign;
-        }
-        $request_header = $request->header();
-
+        $body = $request->body();
+        $header = $request->header();
         $json = $this->info['post_method'] == 3 ? true : false;
-        $curl = Dever::curl($url, $request_body, $method, $json, $request_header);
+        $curl = Dever::curl($url, $body, $method, $json, $header);
         $curl->setResultHeader(true);
         $response_body = $curl->result();
         $response_header = $curl->header();
-        $response = new Response($response_body, $response_header, $this->response, $this->field, $this->type, $this->info['id'], $this->sign);
+        $response_config = array('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']);
         $result = $response->out();
+        $log = array();
         $log['platform_id'] = $this->platform['id'];
-        $log['type'] = $this->type;
-        $log['type_id'] = $this->info['id'];
+        $log['api_id'] = $this->info['id'];
+        $log['account_id'] = $this->info['account_id'];
+        $log['account_project'] = $this->info['account_project'];
+        $log['request_id'] = $this->field->request_id;
         $log['url'] = $url;
         $log['method'] = $method;
-        $log['json'] = $json;
-        $log['request_body'] = Dever::json_encode($request_body);
-        $log['request_header'] = Dever::json_encode($request_header);
+        $log['body'] = $body;
+        $log['header'] = $header;
         $log['response_body'] = $response_body;
-        $log['response_header'] = Dever::json_encode($response_header);
-        Dever::debug($log);
+        $log['response_header'] = $response_header;
+        $log['data'] = $result;
+        Dever::db('api_log', 'api')->update($log['request_id'], $log);
+        if ($this->field->log) {
+            Dever::log($log, 'api');
+            Dever::debug($log, 'api');
+        }
         return $result;
     }
 
@@ -125,18 +126,9 @@ class Platform
         }
         $method = $this->method();
         $request = new Request($this->field, $this->platform['id'], $this->type, $this->info['id']);
-        $request_body = $request->body();
-        if ($this->info['sign_col']) {
-            $this->platform['sign_col'] = $this->info['sign_col'];
-        }
-        $sign = new Sign($this->field, $this->sign);
-        $sign = $sign->get();
-
-        if ($this->platform['sign_name']) {
-            $request_body[$this->platform['sign_name']] = $sign;
-        }
+        $request->body();
         $url .= '?';
-        foreach ($request_body as $k => $v) {
+        foreach ($this->field->body as $k => $v) {
             if ($k == '#') {
                 $url .= $k . $v;
             } else {
@@ -163,11 +155,10 @@ class Platform
         if (strstr($this->info['uri'], 'http')) {
             $this->platform['host'] = '';
         }
-        $uri = Dever::db('api_uri', 'api')->select(array('api_id' => $this->info['id']));
-        if ($uri) {
+        $path = Dever::db('api_path', 'api')->select(array('api_id' => $this->info['id']));
+        if ($path) {
             $path = array();
-            $param = array();
-            foreach ($uri as $k => $v) {
+            foreach ($path as $k => $v) {
                 $v['value'] = $this->field->value($v['value']);
                 if ($v['type'] == 1) {
                     $path[] = $v['value'];
@@ -175,23 +166,31 @@ class Platform
                     $path[] = $v['key'] . '/' . $v['value'];
                 } elseif ($v['type'] == 3) {
                     $path[] = $v['key'] . '=' . $v['value'];
-                } elseif ($v['type'] == 4) {
-                    $param[] = $v['value'];
-                } elseif ($v['type'] == 5) {
-                    $param[] = $v['key'] . '=' . $v['value'];
                 }
             }
             if ($path) {
-                $this->info['uri'] .= implode('/', $path);
+                $path = implode('/', $path);
+                $this->field->setPath($path);
+                $this->info['uri'] .= $path;
             }
-            if ($param) {
-                if (!strstr($this->info['uri'], '?')) {
-                    $this->info['uri'] .= '?';
+        }
+
+        $query = Dever::db('api_query', 'api')->select(array('api_id' => $this->info['id']));
+        if ($query) {
+            $param = array();
+            foreach ($query as $k => $v) {
+                $param[$v['key']] = $this->field->value($v['value'], $v['type']);
+                if (is_array($param[$v['key']])) {
+                    $param[$v['key']] = Dever::json_encode($param[$v['key']]);
                 }
-                $this->info['uri'] .= implode('&', $param);
+            }
+            if ($param) {
+                $this->field->setQuery($param);
+                $this->info['uri'] .= '?' . http_build_query($param);
             }
         }
-        $this->field->setUri($this->info['uri']);
-        return $this->platform['host'] . $this->info['uri'];
+        $url = $this->platform['host'] . $this->info['uri'];
+        $this->field->setUrl($url);
+        return $url;
     }
 }

+ 83 - 40
lib/Platform/Field.php

@@ -13,6 +13,11 @@ class Field
         $this->set('nonce', \Dever\Helper\Secure::nonce());
     }
 
+    public function add($index, $value, $key = 'body')
+    {
+        $this->data[$key][$index] = $value;
+    }
+
     public function set($key, $value)
     {
         $this->data[$key] = $value;
@@ -32,6 +37,22 @@ class Field
         }
     }
 
+    public function createRequestId()
+    {
+        $value = Dever::db('api_log', 'api')->insert([]);
+        $this->set('request_id', $value);
+    }
+
+    public function setPlatformId($value)
+    {
+        $this->set('platform_id', $value);
+    }
+
+    public function setApid($value)
+    {
+        $this->set('api_id', $value);
+    }
+
     public function setHost($value)
     {
         $this->set('body', $value);
@@ -42,14 +63,24 @@ class Field
         $this->set('uri', $value);
     }
 
-    public function setNotify($value)
+    public function setPath($value)
     {
-        $this->set('notify', $value);
+        $this->set('path', $value);
+    }
+
+    public function setQuery($value)
+    {
+        $this->set('query', $value);
+    }
+
+    public function setUrl($value)
+    {
+        $this->set('url', $value);
     }
 
-    public function setSign($value)
+    public function setNotify($value)
     {
-        $this->set('sign', $value);
+        $this->set('notify', $value);
     }
 
     public function setMethod($value)
@@ -72,14 +103,19 @@ class Field
         $this->set('header', $value);
     }
 
+    public function setHeaderJson($value)
+    {
+        $this->set('header_json', $value);
+    }
+
     public function setNumber($value)
     {
         $this->set('number', $value);
     }
 
-    public function value($value, $type = -1, $state = true)
+    public function value($source, $type = '', $state = true)
     {
-        $value = trim($value);
+        $value = trim($source);
         if ($this->data && isset($this->data[$value])) {
             $value = $this->data[$value];
         } elseif (strstr($value, 'key=') && strstr($value, '&')) {
@@ -87,6 +123,25 @@ class Field
         } elseif ($a = strstr($value, '{') || strstr($value, '(')) {
             $value = $this->eval($value);
         }
+        if (!$type && $source == $value) {
+            /*
+            $field = Dever::db('platform_field', 'api')->find(array('platform_id' => $this->data['platform_id'], 'key' => $value));
+            if ($field) {
+                $value = $field['value'];
+                $type = $field['type'];
+            } else {
+                $sign = Dever::db('platform_sign', 'api')->find(array('platform_id' => $this->data['platform_id'], 'name' => $value));
+                if ($sign) {
+                    $value = '';
+                    $type = '3,' . $sign['id'];
+                }
+            }*/
+            $sign = Dever::db('platform_sign', 'api')->find(array('platform_id' => $this->data['platform_id'], 'name' => $value));
+            if ($sign) {
+                $value = '';
+                $type = '3,' . $sign['id'];
+            }
+        }
         return $this->handle($type, $value, $state);
     }
 
@@ -114,40 +169,28 @@ class Field
 
     protected function handle($type, $value, $state)
     {
-        # state == true 是编码 == false 是解码
-        if ($type == -1) {
-            $value = (string) $value;
-        } elseif ($type == -2) {
-            $value = (float) $value;
-        } elseif ($type == -3) {
-            if ($state) {
-                $value = Dever::json_encode($value);
-            } else {
-                $value = Dever::json_decode($value);
-            }
-        } elseif ($type == -4) {
-            if ($state) {
-                $value = strtotime($value);
-            } else {
-                $value = date('Y-m-d H:i:s', $value);
-            }
-        } elseif ($type == -5) {
-            if ($state) {
-                $value = date('Y-m-d H:i:s', $value);
-            } else {
-                $value = strtotime($value);
-            }
-        } elseif ($type == -6) {
-            if ($state) {
-                $value = date('Y-m-d\TH:i:sP', $value);
-            } else {
-                $value = strtotime($value);
-            }
-        } else {
-            if ($state) {
-                $value = $this->ssl->encrypt($type, $value);
-            } else {
-                $value = $this->ssl->decrypt($type, $value);
+        if (strpos($type, ',')) {
+            list($type, $type_id) = explode(',', $type);
+            if ($type == 1) {
+                $info = Dever::db('format', 'api')->find($type_id);
+                if ($info) {
+                    $value = \Dever\Helper\Str::val($info['method'], array('value' => $value));
+                }
+            } elseif ($type == 2) {
+                # state == true 是编码 == false 是解码
+                if ($state) {
+                    $value = $this->ssl->encrypt($type_id, $value);
+                } else {
+                    $value = $this->ssl->decrypt($type_id, $value);
+                }
+            } elseif ($type == 3) {
+                $info = Dever::db('platform_sign', 'api')->find($type_id);
+                if ($info) {
+                    if ($value) {
+                        $info['arg'] = $value;
+                    }
+                    $value = Sign::load($this, $info)->get();
+                }
             }
         }
         return $value;

+ 9 - 7
lib/Platform/Request.php

@@ -13,8 +13,8 @@ class Request
     public function body()
     {
         $body = array();
-        $this->load($body, 'body');
         $this->field->setBody($body);
+        $this->load($body, 'body');
         $this->field->setBodyJson($body ? Dever::json_encode($body) : '');
         return $body;
     }
@@ -22,20 +22,21 @@ class Request
     public function header()
     {
         $header = array();
-        $this->load($header, 'header');
         $this->field->setHeader($header);
+        $this->load($header, 'header');
+        $this->field->setHeaderJson($header ? Dever::json_encode($header) : '');
         return $header;
     }
 
-    protected function load(&$data, $table)
+    protected function load(&$data, $type)
     {
-        $this->get($data, 'platform_request_' . $table, array('platform_id' => $this->platform_id));
-        $this->get($data, $this->type . '_request_' . $table, array($this->type . '_id' => $this->type_id));
+        $this->get($data, 'platform', $type, array('platform_id' => $this->platform_id));
+        $this->get($data, $this->type, $type, array($this->type . '_id' => $this->type_id));
     }
 
-    protected function get(&$data, $table, $where)
+    protected function get(&$data, $prefix, $type, $where)
     {
-        $request = Dever::db($table, 'api')->select($where);
+        $request = Dever::db($prefix . '_request_' . $type, 'api')->select($where);
         if ($request) {
             foreach ($request as $k => $v) {
                 $value = $this->field->value($v['value'], $v['type']);
@@ -51,6 +52,7 @@ class Request
                         $data[$v['key']] = $value;
                     }
                     $this->field->set($v['key'], $value);
+                    $this->field->add($v['key'], $value, $type);
                 }
             }
         }

+ 30 - 172
lib/Platform/Response.php

@@ -2,21 +2,25 @@
 use Dever;
 class Response
 {
-    public function __construct($body, $header, $config, $field, $type, $type_id, $sign)
+    public function __construct($body, $header, $field, $config, $type, $type_id)
     {
         $this->body = $body;
         $this->header = $header;
-        $this->config = $config;
         $this->field = $field;
         $this->type = $type;
         $this->type_id = $type_id;
-        $this->sign = $sign;
+        $this->config = $config;
     }
 
     public function out()
     {
         $this->header();
-        return $this->body();
+        $body = $this->body();
+        $this->verify();
+        
+        $data = $this->handle($this->body);
+        $this->status($data);
+        return $data;
     }
 
     public function header()
@@ -43,32 +47,13 @@ class Response
         }
         $this->field->setBodyJson($this->body);
         $this->parse();
-        $status = $this->status();
-        $msg = $this->msg();
-        if ($status == 2) {
-            Dever::error($msg);
-        }
-        $body = $this->data();
-        $this->field->setBody($body);
-        $this->verify();
-        $data = $this->handle($body);
-        return $data;
+        $this->field->setBody($this->body);
     }
 
+    # 响应是否验签
     protected function verify()
     {
-        $this->sign['verify_set'] = explode(',', $this->sign['verify_set']);
-        if (!in_array(2, $this->sign['verify_set'])) {
-            return;
-        }
-        if (!$this->field->sign) {
-            Dever::error('签名验证失败');
-        }
-        if ($this->sign['verify_col']) {
-            $this->sign['col'] = $this->sign['verify_col'];
-        }
-        $sign = new Sign($this->field, $this->sign);
-        $sign->check($this->field->sign);
+        # 这里和notify里的verify一样就行,暂时不做,一般响应都不验签
     }
 
     protected function parse()
@@ -90,51 +75,26 @@ class Response
         }
     }
 
-    protected function status()
+    protected function status($data)
     {
-        $status = 2;
-        if (!$this->config['code']) {
-            $status = 1;
-        }
-        if ($this->config['code'] && isset($this->body[$this->config['code']])) {
-            $code = $this->body[$this->config['code']];
-            $code = Dever::db('response_code', 'api')->find(array('platform_id' => $this->config['id'], 'value' => $code));
-            if ($code && $code['type'] == 1) {
-                $status = 1;
-            }
-        }
-        return $status;
-    }
-
-    protected function msg()
-    {
-        $msg = 'ok';
-        if ($this->config['msg'] && isset($this->body[$this->config['msg']])) {
-            $msg = $this->config['msg'];
-        }
-        return $msg;
-    }
-
-    protected function data()
-    {
-        $data = $this->body;
-        if ($this->config['data']) {
-            if (strstr($this->config['data'], ',')) {
-                $temp = explode(',', $this->config['data']);
-                foreach ($temp as $k => $v) {
-                    if (isset($this->body[$v])) {
-                        $data = $this->body[$v];
-                        break;
+        $msg = '';
+        $status = 1;
+        $code = Dever::db('platform_response_code', 'api')->select(array('platform_id' => $this->config['id']));
+        if ($code) {
+            foreach ($code as $k => $v) {
+                if (isset($data[$v['key']]) && $data[$v['key']] == $v['value']) {
+                    $status = $v['type'];
+                    if ($v['msg'] && isset($data[$v['msg']])) {
+                        $msg = $data[$v['msg']];
                     }
+                    break;
                 }
-            } elseif (strstr($this->config['data'], '.')) {
-                $temp = explode('.', $this->config['data']);
-                $data = isset($this->body[$temp[0]][$temp[1]]) ? $this->body[$temp[0]][$temp[1]] : (isset($this->body[$temp[0]]) ? $this->body[$temp[0]] : false);
-            } else {
-                $data = $this->body[$this->config['data']] ?? $this->body;
             }
         }
-        return $data;
+        if ($status == 2) {
+            if (!$msg) $msg = 'error';
+            Dever::error($msg);
+        }
     }
 
     protected function handle($data)
@@ -144,115 +104,13 @@ class Response
         if (!$body) {
             $body = Dever::db('platform_response_body', 'api')->select(array('platform_id' => $this->config['id']));
         }
-        $value = new Value($this->field, $this->sign);
+        $value = Value::load($this->field);
         $result = $value->get($body, $data);
-        $this->save($result);
+        $this->save($value, $result);
         return $result;
     }
 
-    protected function convert($array, $source, $dest, $type = -1)
-    {
-        $source = explode('.', $source);
-        $dest = explode('.', $dest);
-        $extracted = $this->extracted($array, $source, $type);
-        return $this->transform($extracted, $dest);
-    }
-
-    protected function extracted(&$array, $source, $type = '')
-    {
-        $current = array_shift($source);
-        if (substr($current, -2) == '[]') {
-            $current = substr($current, 0, -2);
-            $result = [];
-            if (isset($array[$current]) && is_array($array[$current])) {
-                foreach ($array[$current] as $item) {
-                    $sub = $this->extracted($item, $source, $type);
-                    if ($sub !== null) {
-                        $result[] = $sub;
-                    }
-                }
-            }
-            return $result;
-        } else {
-            $result = '';
-            if (isset($array[$current])) {
-                if (empty($source)) {
-                    $result = $array[$current];
-                } else {
-                    return $this->extracted($array[$current], $source, $type);
-                }
-            } elseif ($this->field->$current) {
-                $result = $this->field->$current;
-            } else {
-                $result = $current;
-            }
-            if ($type) {
-                $result .= '||' . $type;
-            }
-            return $result;
-        }
-        return null;
-    }
-
-    protected function transform($value, $dest)
-    {
-        $current = array_shift($dest);
-        if (substr($current, -2) == '[]') {
-            $current = substr($current, 0, -2);
-            $result = [];
-            $result[$current] = [];
-            foreach ($value as $item) {
-                $result[$current][] = $this->transform($item, $dest);
-            }
-            return $result;
-        } else {
-            if (empty($dest)) {
-                return [$current => $value];
-            } else {
-                return [$current => $this->transform($value, $dest)];
-            }
-        }
-    }
-
-    protected function value($data)
-    {
-        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])) {
-                    foreach ($v as $k1 => $v1) {
-                        $data[$k][$k1] = $this->value($v1);
-                    }
-                } else {
-                    $data[$k] = $this->value($v, $key);
-                }
-            } else {
-                $temp = explode('||', $v);
-                if (empty($temp[1])) {
-                    $temp[1] = -1;
-                }
-                if (strstr($temp[0], 'sign-')) {
-                    $temp[0] = str_replace('sign-', '', $temp[0]);
-                    $this->sign['col'] = $temp[0];
-                    $sign = new Sign($this->field, $this->sign);
-                    $temp[0] = $sign->get();
-                }
-                $data[$k] = $this->field->value($temp[0], $temp[1], false);
-                $this->field->set($k, $data[$k]);
-            }
-        }
-        return $data;
-    }
-
-    protected function save($data)
+    protected function save($value, $data)
     {
         $save = Dever::db($this->type . '_save', 'api')->select(array($this->type . '_id' => $this->type_id));
         if ($save) {
@@ -268,7 +126,7 @@ class Response
                 }
                 if (strstr($v['value'], '.')) {
                     $v['value'] = explode('.', $v['value']);
-                    $v['value'] = $this->extracted($data, $v['value']);
+                    $v['value'] = $value->extracted($data, $v['value']);
                     $table[$v['table']]['total'] = count($v['value']);
                 } else {
                     if (isset($data[$v['value']])) {

+ 77 - 50
lib/Platform/Sign.php

@@ -2,45 +2,43 @@
 use Dever;
 class Sign
 {
+    protected static $load;
+    public static function load($field, $config)
+    {
+        $key = $config['id'];
+        if (empty(self::$load[$key])) {
+            self::$load[$key] = new self($field, $config);
+        }
+        return self::$load[$key];
+    }
+
     public function __construct($field, $config)
     {
         $this->field = $field;
         $this->config = $config;
-        if (isset($this->config['sort']) && $this->config['sort'] == 3) {
-            ksort($this->field->body);
-        }
     }
 
     public function get()
     {
-        if ($this->config['method'] == -1) {
-            return false;
-        }
-        $this->create();
-        if ($this->config['sort'] == 2) {
-            ksort($this->info);
-        }
-        $this->split();
-        $this->toString();
+        $this->init();
         $this->encrypt();
         $this->after();
-        $this->field->setSign($this->info);
+        $this->field->set($this->config['name'], $this->info);
         return $this->info;
     }
 
-    public function check($sign)
+    public function check($arg = '')
     {
-        if ($this->config['method'] == -1) {
-            return false;
+        if ($arg) {
+            $this->config['arg'] = $arg;
         }
-        if ($this->config['verify_type'] == 2 && $this->config['method'] > 0) {
-            $this->create();
-            if ($this->config['sort'] == 2) {
-                ksort($this->info);
-            }
-            $this->split();
-            $this->toString();
-            $check = $this->field->ssl->decrypt($this->config['method'], $sign, $this->info);
+        $sign = $this->field->{$this->config['name']};
+        if (!$sign) {
+            Dever::error('签名验证失败');
+        }
+        if ($this->config['encrypt'] > 0) {
+            $this->init();
+            $check = $this->field->ssl->decrypt($this->config['encrypt'], $sign, $this->info);
         } else {
             $check = $sign == $this->get();
         }
@@ -49,14 +47,28 @@ class Sign
         }
     }
 
+    protected function init()
+    {
+        $this->create();
+        if ($this->config['kv_sort'] == 2) {
+            ksort($this->info);
+        }
+        $this->join();
+        $this->toString();
+    }
+
     protected function create()
     {
         $this->info = array();
-        if ($this->config['col']) {
-            $col = explode('+', $this->config['col']);
+        if ($this->config['arg']) {
+            $col = explode("\n", $this->config['arg']);
             foreach ($col as $k => $v) {
                 if ($v == 'body') {
                     $this->info = array_merge($this->field->body, $this->info);
+                } elseif ($v == 'header') {
+                    $this->info = array_merge($this->field->header, $this->info);
+                } elseif ($v == 'query') {
+                    $this->info = array_merge($this->field->query, $this->info);
                 } else {
                     $k = $v;
                     if (strstr($v, '=')) {
@@ -72,10 +84,10 @@ class Sign
         }
     }
 
-    protected function split()
+    protected function join()
     {
-        if (strstr($this->config['split'], '\\')) {
-            $this->config['split'] = preg_replace_callback(
+        if (strstr($this->config['kv_join'], '\\')) {
+            $this->config['kv_join'] = preg_replace_callback(
                 '/\\\\([nrtf])/', // 匹配 \n, \r, \t, \f 等特殊字符
                 function ($matches) {
                     $map = [
@@ -86,7 +98,7 @@ class Sign
                     ];
                     return $map[$matches[1]]; // 直接从映射中获取替换值
                 },
-                $this->config['split']
+                $this->config['kv_join']
             );
         }
     }
@@ -95,27 +107,35 @@ class Sign
     {
         $string = '';
         foreach ($this->info as $k => $v) {
-            if ($this->config['empty'] == 2 && !$v) {
+            
+            if ($this->config['kv_value_empty'] == 2 && null === $v) {
                 continue;
             }
-            if ($this->config['encode'] == 2 && strstr($v, 'http')) {
-                $v = urlencode($v);
-                if (isset($this->field->body[$k])) {
-                    $this->field->body[$k] = $v;
-                }
+            if (is_array($v)) {
+                $v = Dever::json_encode($v);
             }
-            if ($this->config['type'] == 1) {
+            if ($this->config['kv_key_handle']) {
+                $k = Dever::load('util', 'api')->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);
+            }
+            if ($this->config['kv_type'] == 1) {
                 $string .= $v;
-            } elseif ($this->config['type'] == 2) {
+            } elseif ($this->config['kv_type'] == 2) {
+                $string .= $k;
+            } elseif ($this->config['kv_type'] == 3) {
                 $string .= $k . '=' . $v;
-            } elseif ($this->config['type'] == 3) {
+            } elseif ($this->config['kv_type'] == 4) {
                 $string .= $k . $v;
+            } elseif ($this->config['kv_type'] == 5) {
+                $string .= $k . ':' . $v;
             }
             
-            $string .= "{$this->config['split']}";
+            $string .= "{$this->config['kv_join']}";
         }
-        if ($this->config['split_type'] == 1) {
-            $this->info = rtrim($string, $this->config['split']);
+        if ($this->config['kv_join_handle'] == 1) {
+            $this->info = rtrim($string, $this->config['kv_join']);
         } else {
             $this->info = $string;
         }
@@ -123,23 +143,30 @@ class Sign
 
     protected function encrypt()
     {
-        if ($this->config['method'] == -2) {
+        $log = array();
+        $log['request_id'] = $this->field->request_id;
+        $log['name'] = $this->config['name'];
+        $log['string'] = $this->info;
+        if ($this->config['encrypt'] == -2) {
             $this->info = md5($this->info);
-        } elseif ($this->config['method'] == -3) {
+        } elseif ($this->config['encrypt'] == -3) {
             $this->info = hash("sha256", $this->info);
-        } elseif ($this->config['method'] == -4) {
+        } elseif ($this->config['encrypt'] == -4) {
             $this->info = sha1($this->info);
         } else {
-            $this->info = $this->field->ssl->encrypt($this->config['method'], $this->info);
+            $this->info = $this->field->ssl->encrypt($this->config['encrypt'], $this->info);
+        }
+        $log['encode'] = $this->info;
+        if ($this->field->log) {
+            Dever::log($log, 'api_sign');
+            Dever::debug($log, 'api_sign');
         }
     }
 
     protected function after()
     {
-        if ($this->config['after'] == 2) {
-            $this->info = strtoupper($this->info);
-        } elseif ($this->config['after'] == 2) {
-            $this->info = strtolower($this->info);
+        if ($this->config['after']) {
+            $this->info = Dever::load('util', 'api')->format($this->config['after'], $this->info);
         }
     }
 }

+ 13 - 11
lib/Platform/Value.php

@@ -2,10 +2,18 @@
 use Dever;
 class Value
 {
-    public function __construct($field, $sign)
+    protected static $load;
+    public static function load($field)
+    {
+        if (empty(self::$load)) {
+            self::$load = new self($field);
+        }
+        return self::$load;
+    }
+
+    public function __construct($field)
     {
         $this->field = $field;
-        $this->sign = $sign;
     }
 
     public function get($config, $data)
@@ -32,7 +40,7 @@ class Value
         return $result;
     }
 
-    protected function convert($array, $source, $dest, $type = -1)
+    public function convert($array, $source, $dest, $type = '')
     {
         $source = explode('.', $source);
         $dest = explode('.', $dest);
@@ -40,7 +48,7 @@ class Value
         return $this->transform($extracted, $dest);
     }
 
-    protected function extracted(&$array, $source, $type = '')
+    public function extracted(&$array, $source, $type = '')
     {
         $current = array_shift($source);
         if (substr($current, -2) == '[]') {
@@ -119,13 +127,7 @@ class Value
             } else {
                 $temp = explode('||', $v);
                 if (empty($temp[1])) {
-                    $temp[1] = -1;
-                }
-                if (strstr($temp[0], 'sign-')) {
-                    $temp[0] = str_replace('sign-', '', $temp[0]);
-                    $this->sign['col'] = $temp[0];
-                    $sign = new Sign($this->field, $this->sign);
-                    $temp[0] = $sign->get();
+                    $temp[1] = '';
                 }
                 $data[$k] = $this->field->value($temp[0], $temp[1], false);
                 $this->field->set($k, $data[$k]);

+ 4 - 4
lib/Spec.php

@@ -3,11 +3,11 @@ use Dever;
 class Spec
 {
     # 获取规格数据
-    public function manage($api_id)
+    public function manage($app_func_id)
     {
         $result = array();
-        if ($api_id) {
-            $result = Dever::db('spec', 'api')->select(array('api_id' => $api_id));
+        if ($app_func_id) {
+            $result = Dever::db('spec', 'api')->select(array('app_func_id' => $app_func_id));
             if ($result) {
                 foreach ($result as $k => $v) {
                     $result[$k]['type'] = 'show';
@@ -15,7 +15,7 @@ class Spec
                     $result[$k]['show'] = true;
                     $result[$k]['fixed'] = true;
                     $result[$k]['key'] = $v['name'];
-                    $value = Dever::db('spec_value', 'api')->select(array('api_id' => $api_id, 'spec_id' => $v['id']));
+                    $value = Dever::db('spec_value', 'api')->select(array('app_func_id' => $app_func_id, 'spec_id' => $v['id']));
                     if ($value) {
                         foreach ($value as $k1 => $v1) {
                             $value[$k1]['parent'] = $result[$k]['key'];

+ 80 - 3
lib/Util.php

@@ -6,7 +6,7 @@ class Util
     public function createNumber($prefix, $table)
     {
         $number = \Dever\Helper\Str::order($prefix);
-        $state = Dever::db($table)->find(array('number' => $number));
+        $state = Dever::db($table)->find(array('order_num' => $number));
         if (!$state) {
             return $number;
         } else {
@@ -14,6 +14,83 @@ class Util
         }
     }
 
-    # 获取openid
-    
+    # 获取openid 仅jspai和小程序需要openid
+    public function openid($account, $env, $uid, $result = array())
+    {
+        $account = Dever::db('account', 'api')->find(array('key' => $account));
+        if ($account) {
+            $info = Dever::db('openid', 'api')->find(array('account_id' => $account['id'], 'uid' => $uid, 'env' => $env));
+            if ($info) {
+                $result['openid'] = $info['openid'];
+            } else {
+                if ($env == 3) {
+                    # jsapi 一般需要oauth授权
+                    if (empty($result['t'])) {
+                        $result['t'] = \Dever\Helper\Secure::login($uid);
+                    }
+                    $result['account'] = $account['key'];
+                    $result['link'] = Dever::url('api/oauth.code', $result);
+                } elseif ($env == 5) {
+                    # 小程序
+                    $param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
+                    $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env);
+                    if (isset($data['openid'])) {
+                        $result['openid'] = $data['openid'];
+                        $update['uid'] = $uid;
+                        $update['account_id'] = $account['id'];
+                        $update['env'] = $env;
+                        $update['openid'] = $data['openid'];
+                        Dever::db('openid', 'api')->insert($update);
+                    }
+                }
+            }
+        }
+        return $result;
+    }
+
+    # 获取参数类型
+    public function fieldType($platform_id)
+    {
+        $data = array();
+        $data[] = array
+        (
+            'id' => 1,
+            'name' => '格式转换',
+            'children' => Dever::db('format', 'api')->select([]),
+        );
+
+        $where = ['platform_id' => $platform_id];
+
+        $data[] = array
+        (
+            'id' => 2,
+            'name' => '加密',
+            'children' => Dever::db('platform_ssl', 'api')->select($where),
+        );
+
+        $data[] = array
+        (
+            'id' => 3,
+            'name' => '签名',
+            'children' => Dever::db('platform_sign', 'api')->select($where),
+        );
+        return $data;
+    }
+
+    # 获取签名列表
+    public function getPlatformSign($platform_id)
+    {
+        return Dever::db('platform_sign', 'api')->select(array('platform_id' => $platform_id));
+    }
+
+    # 格式转换
+    public function format($id, $value)
+    {
+        $info = Dever::db('format', 'api')->find($id);
+        if ($info) {
+            $info['method'] = str_replace('{value}', "'{value}'", $info['method']);
+            $value = \Dever\Helper\Str::val($info['method'], array('value' => $value));
+        }
+        return $value;
+    }
 }

+ 24 - 2
manage/account.php

@@ -1,4 +1,18 @@
 <?php
+$account_id = Dever::input('id');
+$show = false;
+$account_setting = array();
+if ($account_id) {
+    $account = Dever::db('account', 'api')->find($account_id);
+    $setting = Dever::db('platform_setting', 'api')->select(array('platform_id' => $account['platform_id']));
+    if ($setting) {
+        $show = true;
+        foreach ($setting as $k => $v) {
+            $account_setting[] = array('platform_setting_name' => $v['name'], 'platform_setting_id' => $v['id'], 'value' => '');
+        }
+    }
+}
+
 return array
 (
     'list' => array
@@ -24,7 +38,7 @@ return array
         ),
         'data_button' => array
         (
-            '设置' => array('edit', 'name,key,api/account_setting'),
+            '设置' => array('edit', 'name,key,app_platform_name,api/account_setting'),
             '证书' => array('route', array
             (
                 'path' => 'api_manage/account_cert',
@@ -62,10 +76,18 @@ return array
                 'remote'    => 'api/manage.getAppPlatform',
                 'remote_default' => false,
             ),
+            'app_platform_name' => array
+            (
+                'name' => '平台与应用',
+                'type' => 'show',
+                'default' => 'Dever::call("api/app.getAppPlatform", array("{app_id}", "{platform_id}"))',
+            ),
             'api/account_setting' => array
             (
-                'name' => '参数配置',
+                'show' => $show,
+                'name' => '平台参数配置',
                 'where'  => array('account_id' => 'id'),
+                'default' => $account_setting,
             ),
         ),
         'check' => 'key',

+ 2 - 2
manage/account_cert.php

@@ -53,12 +53,12 @@ return array
             ),
             'public' => array
             (
-                'rules' => true,
+                //'rules' => true,
                 'type' => 'textarea',
             ),
             'private' => array
             (
-                'rules' => true,
+                //'rules' => true,
                 'type' => 'textarea',
             ),
         ),

+ 8 - 7
manage/account_setting.php

@@ -1,8 +1,5 @@
 <?php
-$account_id = Dever::input('set')['account_id'] ?? 0;
-if (!$account_id) {
-    $account_id = Dever::input('field')['account_id'] ?? 0;
-}
+$account_id = Dever::input('id');
 $account = Dever::db('account', 'api')->find($account_id);
 return array
 (
@@ -10,10 +7,14 @@ return array
     (
         'field'    => array
         (
-            'platform_setting_id' => array
+            'platform_setting_id' => 'hidden',
+            'platform_setting_name' => array
             (
-                'type' => 'select',
-                'option'     => 'Dever::call("api/app.getSetting", '.$account['platform_id'].')',
+                'name' => '参数名',
+                'type' => 'show',
+                'default' => 'Dever::call("api/platform_setting-find", "{platform_setting_id}")["name"]',
+                //'disable' => true,
+                //'option'     => 'Dever::call("api/app.getSetting", '.$account['platform_id'].')',
                 //'remote' => 'api/manage.getSettingName',
                 //'remote_default' => false,
             ),

+ 53 - 104
manage/api.php

@@ -1,5 +1,8 @@
 <?php
 $platform_id = Dever::input('set')['platform_id'] ?? 0;
+if (!$platform_id) {
+    $platform_id = Dever::input('field')['platform_id'] ?? 0;
+}
 $platform = include('platform.php');
 $config = array
 (
@@ -12,7 +15,7 @@ $config = array
             'sort' => 'input',
             'name',
             'uri',
-            'env_type',
+            'env',
             'platform_id',
             'status' => array
             (
@@ -24,12 +27,12 @@ $config = array
         ),
         'data_button' => array
         (
-            '设置' => 'edit',
+            '设置' => array('edit', array('platform_id' => $platform_id)),
             '删除' => 'delete',
         ),
         'button' => array
         (
-            '新增' => array('fastadd', array('platform_id' => $platform_id, 'field' => 'name,env_type,platform_id,uri')),
+            '新增' => array('fastadd', array('platform_id' => $platform_id, 'field' => 'name,env,platform_id,uri')),
         ),
         'search' => array
         (
@@ -45,38 +48,47 @@ $config = array
     ),
     'update' => array
     (
+        'end' => 'api/app.updateApi',
         'desc' => $platform['update']['desc'],
         'tab' => array
         (
-            '基本设置' => 'name,env_type,sign_col,uri,api/api_uri',
-            '价格设置' => 'spec_type,api/sku,api/sku#',
-            '请求参数' => 'method,post_method,api/api_request_header,api/api_request_body',
+            '基本设置' => 'name,env,api/api_setting',
+            '请求地址' => 'uri,method,post_method,api/api_path,api/api_query',
+            '请求参数' => 'api/api_request_header,api/api_request_body',
             '响应参数' => 'api/api_response_header,api/api_response_body',
             
-            '输入输出' => 'api/api_request_input,api/api_request_output',
             '存储设置' => 'api/api_save',
-            '回调设置' => 'notify_type,notify_sign_col,notify_success,notify_error,api/api_notify_body,api/api_notify_code',
+            '回调设置' => 'notify,api/api_notify,api/api_notify_body,api/api_notify_code',
+            //'价格设置' => 'spec_type,api/sku,api/sku#',
+            //'输入输出' => 'api/api_request_input,api/api_request_output',
         ),
         'field'    => array
         (
             'name',
-            'env_type' => 'radio',
+            'env' => 'radio',
             'platform_id' => array
             (
                 'desc' => '【提交后不能更改】',
             ),
-            'sign_col' => array
+            'uri',
+            'api/api_path' => array
             (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-                'desc' => '按顺序做加密,用+号隔开,为空则所有字段均参与加密,这里填写后,将替换平台中的签名加密参数',
+                'name' => '接口路径',
+                'where'  => array('api_id' => 'id'),
+                'desc' => '填写接口上的路径path参数',
             ),
-            'uri',
-            'api/api_uri' => array
+            'api/api_query' => array
             (
-                'name' => '接口地址生成',
+                'name' => '接口查询参数',
                 'where'  => array('api_id' => 'id'),
-                'desc' => '如果需要动态生成接口地址,这里填写参数即可,同样支持变量',
+                'desc' => '填写接口上的query参数',
+            ),
+
+            'api/api_setting' => array
+            (
+                'name' => '基础参数',
+                'where'  => array('api_id' => 'id'),
+                'desc' => '设置仅限该接口使用的参数,用于定义一些特殊的参数',
             ),
 
             'method' => array
@@ -89,17 +101,6 @@ $config = array
                 'type' => 'radio',
                 'show' => false,
             ),
-            'api/api_request_input' => array
-            (
-                'name' => '参数输入',
-                'where'  => array('api_id' => 'id'),
-                'desc' => '[默认值/可选项:可以多行输入,默认值为第一行,其他行为可选项]',
-            ),
-            'api/api_request_output' => array
-            (
-                'name' => '参数输出',
-                'where'  => array('api_id' => 'id'),
-            ),
             'api/api_request_body' => array
             (
                 'name' => '请求体',
@@ -132,72 +133,43 @@ $config = array
                 'where'  => array('api_id' => 'id'),
             ),
 
-            'notify_type' => array
+            'notify' => array
             (
                 'type' => 'radio',
                 'control' => true,
             ),
-            'notify_success' => array
+            /*
+            #也可以这样设置
+            'api/api_notify#' => array
             (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-                'desc' => '回调成功后,返回给上游的信息',
+                'field' => 'sign_arg',
+                'name' => '签名参数',
+                'where'  => array('api_id' => 'id'),
             ),
-            'notify_error' => array
+            'api/api_notify##' => array
             (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-                'desc' => '回调失败后,返回给上游的信息,默认应答状态码为500,可以换行输入应答状态码',
-            ),
-            'notify_sign_col' => array
+                'field' => 'sign_id',
+                'name' => '签名',
+                'where'  => array('api_id' => 'id'),
+            ),*/
+            'api/api_notify' => array
             (
-                'desc' => '填写参与回调签名的参数,不填写则使用平台设置的签名参数',
+                'name' => '基本设置',
+                'where'  => array('api_id' => 'id'),
+                'default' => array(array()),
+                # 默认使用表格形式展示,可以改成每行展示
+                #'type' => 'line',
             ),
             'api/api_notify_body' => array
             (
-                'name' => '回调参数设置',
+                'name' => '参数设置',
                 'where'  => array('api_id' => 'id'),
             ),
             'api/api_notify_code' => array
             (
-                'name' => '回调状态码',
+                'name' => '状态码',
                 'where'  => array('api_id' => 'id'),
             ),
-
-            'spec_type' => array
-            (
-                'type' => 'radio',
-                'control' => true,
-            ),
-            'api/sku' => array
-            (
-                'name' => '单规格设置',
-                'where'  => array('api_id' => 'id', 'key' => '-1'),
-                # 默认值,如果有默认值则无法添加和删除
-                'default' => array
-                (
-                    # 默认值
-                    array
-                    (
-                        'price' => '',
-                        'num' => '',
-                        'day_num' => '',
-                    ),
-                ),
-            ),
-
-            'api/sku#' => array
-            (
-                'name' => '多规格设置',
-                'where' => array('api_id' => 'id', 'key' => array('!=', '-1')),
-                'type' => 'sku',
-                # 设置规格表名
-                'spec' => 'api/spec',
-                # 设置规格表关联字段
-                'spec_field' => 'api_id',
-                # 获取规格数据的接口
-                'spec_data' => 'api/spec.manage',
-            ),
         ),
 
         'control' => array
@@ -206,40 +178,17 @@ $config = array
             (
                 'method' => 2,
             ),
-            'notify_success' => array
-            (
-                'notify_type' => 1,
-            ),
-            'notify_error' => array
+            'api/api_notify' => array
             (
-                'notify_type' => 1,
+                'notify' => 1,
             ),
             'api/api_notify_body' => array
             (
-                'notify_type' => 1,
+                'notify' => 1,
             ),
             'api/api_notify_code' => array
             (
-                'notify_type' => 1,
-            ),
-            'notify_sign_col' => array
-            (
-                'notify_type' => 1,
-            ),
-            /*
-            'api/api_notify' => array
-            (
-                'notify_type' => 1,
-            ),*/
-
-            'api/sku' => array
-            (
-                'spec_type' => 1,
-            ),
-
-            'api/sku#' => array
-            (
-                'spec_type' => 2,
+                'notify' => 1,
             ),
         ),
     ),

+ 36 - 0
manage/api_notify.php

@@ -0,0 +1,36 @@
+<?php
+$platform_id = Dever::input('set')['platform_id'] ?? 0;
+if (!$platform_id) {
+    $platform_id = Dever::input('field')['platform_id'] ?? 0;
+}
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'sign_id' => array
+            (
+                'type' => 'select',
+                'option'     => 'Dever::call("api/util.getPlatformSign", '.$platform_id.')',
+                'clearable' => true,
+                'default' => '',
+            ),
+            'sign_arg' => array
+            (
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+            ),
+            'success' => array
+            (
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+            ),
+            'error' => array
+            (
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+            ),
+        ),
+    ),
+);

+ 0 - 0
manage/api_uri.php → manage/api_path.php


+ 2 - 0
manage/api_query.php

@@ -0,0 +1,2 @@
+<?php
+return include('platform_request_body.php');

+ 0 - 21
manage/api_response.php

@@ -1,21 +0,0 @@
-<?php
-return array
-(
-    'update' => array
-    (
-        'field'    => array
-        (
-            'key' => array
-            (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-            ),
-            'value' => array
-            (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-            ),
-            'type',
-        ),
-    ),
-);

+ 2 - 0
manage/api_setting.php

@@ -0,0 +1,2 @@
+<?php
+return include('platform_request_body.php');

+ 61 - 0
manage/app_func.php

@@ -43,6 +43,8 @@ return array
         (
             '基本设置' => 'app_id,name,key,desc,cron_date,cron_time',
             '接口设置' => 'type,api/app_func_work',
+            '价格设置' => 'spec_type,api/sku,api/sku#',
+            '输入输出' => 'api/app_func_input,api/app_func_output',
         ),
         'field'    => array
         (
@@ -74,6 +76,65 @@ return array
                 'desc' => '设置功能包含的接口',
                 'where'  => array('app_func_id' => 'id'),
             ),
+
+            'spec_type' => array
+            (
+                'type' => 'radio',
+                'control' => true,
+            ),
+            'api/sku' => array
+            (
+                'name' => '单规格设置',
+                'where'  => array('app_func_id' => 'id', 'key' => '-1'),
+                # 默认值,如果有默认值则无法添加和删除
+                'default' => array
+                (
+                    # 默认值
+                    array
+                    (
+                        'price' => '',
+                        'num' => '',
+                        'day_num' => '',
+                    ),
+                ),
+            ),
+
+            'api/sku#' => array
+            (
+                'name' => '多规格设置',
+                'where' => array('app_func_id' => 'id', 'key' => array('!=', '-1')),
+                'type' => 'sku',
+                # 设置规格表名
+                'spec' => 'api/spec',
+                # 设置规格表关联字段
+                'spec_field' => 'app_func_id',
+                # 获取规格数据的接口
+                'spec_data' => 'api/spec.manage',
+            ),
+
+            'api/app_func_input' => array
+            (
+                'name' => '参数输入',
+                'where'  => array('app_func_id' => 'id'),
+                'desc' => '[参数名:对应接口中的请求参数名,默认值/可选项:可以多行输入,默认值为第一行,其他行为可选项]',
+            ),
+            'api/app_func_output' => array
+            (
+                'name' => '参数输出',
+                'where'  => array('app_func_id' => 'id'),
+            ),
+        ),
+        'control' => array
+        (
+            'api/sku' => array
+            (
+                'spec_type' => 2,
+            ),
+
+            'api/sku#' => array
+            (
+                'spec_type' => 3,
+            ),
         ),
     ),
 );

+ 0 - 0
manage/api_request_input.php → manage/app_func_input.php


+ 0 - 0
manage/api_request_output.php → manage/app_func_output.php


+ 14 - 5
manage/core.php

@@ -28,21 +28,21 @@ return array
             'sort'      => '3',
         ),
 
-        'platform_api' => array
+        'format' => array
         (
             'parent'    => 'api_manage',
-            'name'      => '平台接口管理',
+            'name'      => '参数格式转换',
             'icon'      => 'tools-line',
             'sort'      => '4',
             'show'      => 3,
         ),
 
-        'platform_cert' => array
+        'api' => array
         (
             'parent'    => 'api_manage',
-            'name'      => '平台证书管理',
+            'name'      => '平台接口管理',
             'icon'      => 'tools-line',
-            'sort'      => '5',
+            'sort'      => '4',
             'show'      => 3,
         ),
 
@@ -51,6 +51,15 @@ return array
             'parent'    => 'api_manage',
             'name'      => '平台加密管理',
             'icon'      => 'tools-line',
+            'sort'      => '5',
+            'show'      => 3,
+        ),
+
+        'platform_sign' => array
+        (
+            'parent'    => 'api_manage',
+            'name'      => '平台签名管理',
+            'icon'      => 'tools-line',
             'sort'      => '6',
             'show'      => 3,
         ),

+ 42 - 0
manage/format.php

@@ -0,0 +1,42 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'sort' => 'input',
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search' => array
+        (
+            'name',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'method' => array
+            (
+                'rules' => true,
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 6),
+            ),
+        ),
+    ),
+);

+ 34 - 64
manage/platform.php

@@ -9,22 +9,21 @@ $config = array
             'id',
             'name',
             'host',
-            //'method',
         ),
         'data_button' => array
         (
             '设置' => 'edit',
-            '证书' => array('route', array
+            '加密' => array('route', array
             (
-                'path' => 'api_manage/platform_cert',
+                'path' => 'api_manage/platform_ssl',
                 'param' => array
                 (
                     'set' => array('platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'),
                 ),
             )),
-            '加解密' => array('route', array
+            '签名' => array('route', array
             (
-                'path' => 'api_manage/platform_ssl',
+                'path' => 'api_manage/platform_sign',
                 'param' => array
                 (
                     'set' => array('platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'),
@@ -42,6 +41,14 @@ $config = array
         'button' => array
         (
             '新增' => array('fastadd', 'name,host'),
+            '定义格式转换' => array('route', array
+            (
+                'path' => 'api_manage/format',
+                'param' => array
+                (
+                    'set' => array('menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'),
+                ),
+            )),
         ),
         'search' => array
         (
@@ -50,15 +57,12 @@ $config = array
     ),
     'update' => array
     (
-        'desc' => "所有参数定义后均可以直接使用,也支持函数,参数值可以是变量、函数、字符串,如果函数中或者字符串中需要增加变量或者常量,请用{}隔开,默认常量:method请求方式,host主机域名,uri请求路径,sign签名,time秒时间戳,timestamp毫秒时间戳,nonce随机值,notify请求回调地址,order_num请求订单号,aad签名附加数据,body请求体参数,body_json请求体参数(json格式)",
+        'desc' => "所有参数定义后均可以直接使用,也支持函数,参数值可以是变量、函数、字符串,如果函数中或者字符串中需要增加变量或者常量,请用{}隔开,默认常量:method请求方式,url请求完整地址,host主机域名,uri请求路径,time秒时间戳,timestamp毫秒时间戳,nonce随机值,notify请求回调地址,order_num请求订单号,sign签名信息,aad签名附加数据,query请求查询参数,query_json请求查询参数(json格式),body请求体参数,body_json请求体参数(json格式),header请求头参数,header_json请求头参数(json格式)",
         'tab' => array
         (
-            '基本设置' => 'name,host,method,post_method,api/platform_setting',
-            '标准请求' => 'api/platform_request_header,api/platform_request_body',
-            '标准响应' => 'api/platform_response_header,api/platform_response_body',
-            '响应体状态' => 'response_type,response_data,response_msg,response_code,api/platform_response_code',
-            //'字段转换' => 'api/platform_convert',
-            '签名设置' => 'sign_method,sign_name,sign_col,sign_verify_col,sign_type,sign_split,sign_split_type,sign_sort,sign_encode,sign_empty,sign_after,sign_verify_set,sign_verify_type',
+            '基本设置' => 'name,host,api/platform_setting,api/platform_cert',
+            '标准请求' => 'method,post_method,api/platform_request_header,api/platform_request_body',
+            '标准响应' => 'response_type,api/platform_response_header,api/platform_response_body,api/platform_response_code',
         ),
         'field'    => array
         (
@@ -76,8 +80,15 @@ $config = array
 
             'api/platform_setting' => array
             (
-                'name' => '参数设置',
-                'desc' => '设置对接平台需要的参数',
+                'name' => '账户参数',
+                'desc' => '设置账户需要的参数',
+                'where'  => array('platform_id' => 'id'),
+            ),
+
+            'api/platform_cert' => array
+            (
+                'name' => '账户证书',
+                'desc' => '设置账户需要的证书',
                 'where'  => array('platform_id' => 'id'),
             ),
 
@@ -94,10 +105,12 @@ $config = array
                 'where'  => array('platform_id' => 'id'),
             ),
 
+            'response_type' => 'radio',
+
             'api/platform_response_body' => array
             (
                 'name' => '标准响应体',
-                'desc' => '设置平台标准响应体,只保留填写后的响应体,格式:data[].name,不是列表则为data.name',
+                'desc' => '设置平台标准响应体,填写后,将只保留填写后的响应体,格式:data[].name,不是列表则为data.name,如果填写了“数据字段”,这里仅返回“数据字段”里的数据',
                 'where'  => array('platform_id' => 'id'),
             ),
             'api/platform_response_header' => array
@@ -107,21 +120,6 @@ $config = array
                 'where'  => array('platform_id' => 'id'),
             ),
 
-            'api/platform_convert' => array
-            (
-                'name' => '字段转换',
-                'where'  => array('platform_id' => 'id'),
-                'desc' => '设置之后,所有平台过来的字段,都将按照这个转换规则进行转换',
-            ),
-
-            'response_type' => array
-            (
-                'type' => 'radio',
-                //'control' => true,
-            ),
-            'response_data',
-            'response_msg',
-            'response_code',
             'api/platform_response_code' => array
             (
                 'name' => '响应状态码',
@@ -129,41 +127,12 @@ $config = array
                 'where'  => array('platform_id' => 'id'),
             ),
 
-            'sign_name',
-            'sign_method' => 'radio',
-            'sign_col' => array
-            (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-                'desc' => '按顺序做加密,用+号隔开,为空则所有参数均参与签名',
-            ),
-            'sign_verify_col' => array
-            (
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 2),
-                'desc' => '同上,为空则与签名参数相同',
-            ),
-            'sign_type' => 'radio',
-            'sign_split',
-            'sign_split_type' => 'radio',
-            'sign_sort' => 'radio',
-            'sign_encode' => array
-            (
-                'type' => 'radio',
-                'desc' => '【如果参数中包含有特殊字符,是否进行转码】',
-            ),
-            'sign_empty' => array
-            (
-                'type' => 'radio',
-                'desc' => '【如果参数中有空值,是否参与签名】',
-            ),
-            'sign_after' => 'radio',
-            'sign_verify_type' => array
+            'api/platform_convert' => array
             (
-                'type' => 'radio',
-                'desc' => '【选择对签名解签,必须选择可以解签的签名加密方式】',
+                'name' => '字段转换',
+                'where'  => array('platform_id' => 'id'),
+                'desc' => '设置之后,所有平台过来的字段,都将按照这个转换规则进行转换',
             ),
-            'sign_verify_set' => 'checkbox',
         ),
 
         'control' => array
@@ -176,7 +145,8 @@ $config = array
     ),
 );
 $id = Dever::input('id');
-if (!$id) {
+$load = Dever::input('load');
+if (($load == '/api_manage/platform' || $load == '/api_manage/api') && !$id) {
     $config['update']['desc'] = '';
     unset($config['update']['tab']);
 }

+ 1 - 27
manage/platform_cert.php

@@ -1,40 +1,14 @@
 <?php
-$platform_id = Dever::input('set')['platform_id'] ?? 0;
 return array
 (
-    'list' => array
-    (
-        'where' => array('platform_id' => $platform_id),
-        'field'      => array
-        (
-            'id',
-            'name',
-            'type',
-            'cdate',
-        ),
-        'data_button' => array
-        (
-            '编辑' => 'fastedit',
-        ),
-        'button' => array
-        (
-            '新增' => array('fastadd', array('platform_id' => $platform_id)),
-        ),
-        'search' => array
-        (
-            'platform_id' => 'hidden',
-            'name',
-        ),
-    ),
     'update' => array
     (
         'field'    => array
         (
-            'platform_id' => 'hidden',
             'name',
             'type' => array
             (
-                'desc' => '手动输入即可,用以区分不同类别的证书',
+                'placeholder' => '用以区分不同类别的证书',
             ),
         ),
     ),

+ 14 - 1
manage/platform_request_body.php

@@ -1,4 +1,11 @@
 <?php
+$platform_id = Dever::input('set')['platform_id'] ?? 0;
+if (!$platform_id) {
+    $platform_id = Dever::input('field')['platform_id'] ?? 0;
+}
+if (!$platform_id) {
+    $platform_id = Dever::input('id');
+}
 return array
 (
     'update' => array
@@ -15,7 +22,13 @@ return array
                 'type' => 'textarea',
                 'autosize' => array('minRows' => 2),
             ),
-            'type',
+            'type' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("api/util.fieldType", '.$platform_id.')',
+                'clearable' => true,
+            ),
         ),
+        'drag' => 'sort',
     ),
 );

+ 5 - 0
manage/platform_response_code.php

@@ -5,8 +5,13 @@ return array
     (
         'field'    => array
         (
+            'key',
             'value',
             'type',
+            'msg' => array
+            (
+                'placeholder' => '可以填写字段名',
+            ),
         ),
     ),
 );

+ 104 - 0
manage/platform_sign.php

@@ -0,0 +1,104 @@
+<?php
+$platform_id = Dever::input('set')['platform_id'] ?? 0;
+$platform = include('platform.php');
+$encrypt = array
+(
+    -1 => '无需加密',
+    -2 => 'md5',
+    -3 => 'sha256',
+    -4 => 'sha1',
+);
+$platform_id = Dever::input('set')['platform_id'] ?? 0;
+if (!$platform_id) {
+    $platform_id = Dever::input('field')['platform_id'] ?? 0;
+}
+if ($platform_id) {
+    $info = Dever::db('platform_ssl', 'api')->select(['platform_id' => $platform_id]);
+    if ($info) {
+        foreach ($info as $k => $v) {
+            $encrypt[$v['id']] = $v['name'];
+        }
+    }
+}
+return array
+(
+    'list' => array
+    (
+        'where' => array('platform_id' => $platform_id),
+        'field'      => array
+        (
+            'id',
+            'name',
+            //'sort' => 'input',
+            'cdate',
+        ),
+        'data_button' => array
+        (
+            '编辑' => array('edit', array('platform_id' => $platform_id)),
+            '删除' => 'delete',
+        ),
+        'button' => array
+        (
+            '新增' => array('add', array('platform_id' => $platform_id)),
+        ),
+        'search' => array
+        (
+            'platform_id' => 'hidden',
+            'name',
+        ),
+    ),
+    'update' => array
+    (
+        'desc' => $platform['update']['desc'],
+        'tab' => array
+        (
+            '基本设置' => 'platform_id,name,arg,encrypt,after',
+            '键名键值设置' => 'kv_type,kv_sort,kv_value_empty,kv_key_handle,kv_value_handle,kv_join,kv_join_handle',
+        ),
+        'field'    => array
+        (
+            'platform_id' => 'text',
+            'name' => array
+            (
+                'desc' => '填写后,以{签名名称}形式调用',
+            ),
+            'arg' => array
+            (
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+                'desc' => '按顺序做加密,用换行隔开,为空则所有请求体参数参与签名',
+            ),
+            'encrypt' => array
+            (
+                'type' => 'radio',
+                'option' => $encrypt,
+            ),
+            'after' => array
+            (
+                'type' => 'select',
+                'clearable' => true
+            ),
+
+
+            'kv_type' => 'radio',
+            'kv_sort' => 'radio',
+            'kv_value_empty' => array
+            (
+                'type' => 'radio',
+                'desc' => '【如果参数中有空值,是否参与签名】',
+            ),
+            'kv_key_handle' => array
+            (
+                'type' => 'select',
+                'clearable' => true
+            ),
+            'kv_value_handle' => array
+            (
+                'type' => 'select',
+                'clearable' => true
+            ),
+            'kv_join',
+            'kv_join_handle' => 'radio',
+        ),
+    ),
+);

+ 5 - 5
manage/platform_ssl.php

@@ -53,16 +53,16 @@ return array
             ),
             'iv' => array
             (
-                'desc' => '支持变量,参考平台设置中的变量说明',
+                'desc' => '可以直接使用平台设置中的参数名',
             ),
             'tag' => array
             (
-                'desc' => '支持变量,参考平台设置中的变量说明',
+                'desc' => '可以直接使用平台设置中的参数名',
             ),
             'tag_len',
             'aad' => array
             (
-                'desc' => '支持变量,参考平台设置中的变量说明',
+                'desc' => '可以直接使用平台设置中的参数名',
             ),
             'after' => 'radio',
 
@@ -70,7 +70,7 @@ return array
             'encrypt_cert' => array
             (
                 'type' => 'text',
-                'desc' => '这里支持平台参数',
+                'desc' => '可以直接使用平台设置中的参数名',
             ),
             'encrypt_cert_id' => array
             (
@@ -82,7 +82,7 @@ return array
             'decrypt_cert' => array
             (
                 'type' => 'text',
-                'desc' => '这里支持平台参数',
+                'desc' => '可以直接使用平台设置中的参数名',
             ),
             'decrypt_cert_id' => array
             (

+ 1 - 1
table/account_setting.php

@@ -14,7 +14,7 @@ return array
 
         'platform_setting_id' => array
         (
-            'name'      => '参数描述',
+            'name'      => '参数',
             'type'      => 'int(11)',
         ),
 

+ 2 - 38
table/api.php

@@ -24,12 +24,6 @@ return array
             'type'      => 'varchar(1000)',
         ),
 
-        'sign_col' => array
-        (
-            'name'      => '签名加密参数',
-            'type'      => 'varchar(1000)',
-        ),
-
         'method' => array
         (
             'name'      => '请求方式',
@@ -56,7 +50,7 @@ return array
             ),
         ),
 
-        'notify_type' => array
+        'notify' => array
         (
             'name'      => '是否有回调',
             'type'      => 'tinyint(1)',
@@ -68,37 +62,7 @@ return array
             ),
         ),
 
-        'notify_success' => array
-        (
-            'name'      => '应答成功报文',
-            'type'      => 'varchar(500)',
-        ),
-
-        'notify_error' => array
-        (
-            'name'      => '应答失败报文',
-            'type'      => 'varchar(500)',
-        ),
-
-        'notify_sign_col' => array
-        (
-            'name'      => '签名加密参数',
-            'type'      => 'varchar(1000)',
-        ),
-
-        'spec_type' => array
-        (
-            'name'      => '规格类型',
-            'type'      => 'tinyint(1)',
-            'default'   => 1,
-            'value'     => array
-            (
-                1 => '单规格',
-                2 => '多规格',
-            ),
-        ),
-
-        'env_type' => array
+        'env' => array
         (
             'name'      => '运行环境',
             'type'      => 'tinyint(1)',

+ 51 - 9
table/api_log.php

@@ -5,28 +5,70 @@ return array
     'store' => 'log',
     'struct' => array
     (
+        'platform_id' => array
+        (
+            'name'      => '平台id',
+            'type'      => 'int(11)',
+        ),
+
         'api_id' => array
         (
             'name'      => '接口id',
             'type'      => 'int(11)',
         ),
 
-        'request_id' => array
+        'account_id' => array
+        (
+            'name'      => '账户id',
+            'type'      => 'int(11)',
+        ),
+
+        'account_project' => array
+        (
+            'name'      => '账户所在项目',
+            'type'      => 'varchar(100)',
+        ),
+
+        'url' => array
+        (
+            'name'      => '请求url',
+            'type'      => 'varchar(1000)',
+        ),
+
+        'method' => array
+        (
+            'name'      => '请求方式',
+            'type'      => 'varchar(50)',
+        ),
+
+        'body' => array
+        (
+            'name'      => '请求体',
+            'type'      => 'varchar(1000)',
+        ),
+
+        'header' => array
+        (
+            'name'      => '请求头',
+            'type'      => 'varchar(1000)',
+        ),
+
+        'response_body' => array
         (
-            'name'      => '请求id',
-            'type'      => 'varchar(200)',
+            'name'      => '响应体',
+            'type'      => 'varchar(1000)',
         ),
 
-        'key' => array
+        'response_header' => array
         (
-            'name'      => '数据表字段名',
-            'type'      => 'varchar(150)',
+            'name'      => '响应头',
+            'type'      => 'varchar(1000)',
         ),
 
-        'value' => array
+        'data' => array
         (
-            'name'      => '响应参数名/参数值',
-            'type'      => 'varchar(800)',
+            'name'      => '返回数据',
+            'type'      => 'varchar(1000)',
         ),
     ),
 );

+ 38 - 0
table/api_notify.php

@@ -0,0 +1,38 @@
+<?php
+return array
+(
+    'name' => '接口回调配置',
+    'struct' => array
+    (
+        'api_id' => array
+        (
+            'name'      => '接口id',
+            'type'      => 'int(11)',
+        ),
+
+        'success' => array
+        (
+            'name'      => '应答成功报文',
+            'type'      => 'varchar(500)',
+        ),
+
+        'error' => array
+        (
+            'name'      => '应答失败报文',
+            'type'      => 'varchar(500)',
+        ),
+
+        'sign_id' => array
+        (
+            'name'      => '签名',
+            'type'      => 'int(11)',
+            'default'   => '',
+        ),
+
+        'sign_arg' => array
+        (
+            'name'      => '签名参数',
+            'type'      => 'varchar(2000)',
+        ),
+    ),
+);

+ 7 - 9
table/api_uri.php → table/api_path.php

@@ -1,7 +1,7 @@
 <?php
 return array
 (
-    'name' => '接口地址参数',
+    'name' => '接口路径设置',
     'order' => 'sort asc',
     'struct' => array
     (
@@ -13,28 +13,26 @@ return array
 
         'key' => array
         (
-            'name'      => '参数名',
+            'name'      => '路径参数名',
             'type'      => 'varchar(150)',
         ),
 
         'value' => array
         (
-            'name'      => '参数值',
+            'name'      => '路径参数值',
             'type'      => 'varchar(150)',
         ),
 
         'type' => array
         (
-            'name'      => '参数位置',
+            'name'      => '展示形式',
             'type'      => 'tinyint(1)',
             'default'   => '1',
             'value'     => array
             (
-                1 => '接口路径:value形式',
-                2 => '接口路径:key/value形式',
-                3 => '接口路径:key=value形式',
-                4 => '接口参数:value形式',
-                5 => '接口参数:key=value形式',
+                1 => 'value形式',
+                2 => 'key/value形式',
+                3 => 'key=value形式',
             ),
         ),
 

+ 13 - 0
table/api_query.php

@@ -0,0 +1,13 @@
+<?php
+$config = include('platform_request_body.php');
+unset($config['struct']['platform_id']);
+$config['struct'] += array
+(
+    'api_id' => array
+    (
+        'name'      => '接口id',
+        'type'      => 'int(11)',
+    ),
+);
+$config['name'] = '接口查询参数设置';
+return $config;

+ 13 - 0
table/api_setting.php

@@ -0,0 +1,13 @@
+<?php
+$config = include('platform_request_body.php');
+unset($config['struct']['platform_id']);
+$config['struct'] += array
+(
+    'api_id' => array
+    (
+        'name'      => '接口id',
+        'type'      => 'int(11)',
+    ),
+);
+$config['name'] = '接口参数配置';
+return $config;

+ 13 - 0
table/app_func.php

@@ -61,6 +61,19 @@ return array
             'type'      => 'varchar(800)',
         ),
 
+        'spec_type' => array
+        (
+            'name'      => '规格类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '免费',
+                2 => '单规格',
+                3 => '多规格',
+            ),
+        ),
+
         'status' => array
         (
             'name'      => '状态',

+ 2 - 2
table/api_request_input.php → table/app_func_input.php

@@ -5,9 +5,9 @@ return array
     'order' => 'sort asc',
     'struct' => array
     (
-        'api_id' => array
+        'app_func_id' => array
         (
-            'name'      => '接口id',
+            'name'      => '功能id',
             'type'      => 'int(11)',
         ),
 

+ 2 - 2
table/api_request_output.php → table/app_func_output.php

@@ -5,9 +5,9 @@ return array
     'order' => 'sort asc',
     'struct' => array
     (
-        'api_id' => array
+        'app_func_id' => array
         (
-            'name'      => '接口id',
+            'name'      => '功能id',
             'type'      => 'int(11)',
         ),
 

+ 49 - 0
table/format.php

@@ -0,0 +1,49 @@
+<?php
+return array
+(
+    'name' => '参数格式转换',
+    'order' => 'sort asc, id asc',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '转换名称',
+            'type'      => 'varchar(30)',
+        ),
+
+        'method' => array
+        (
+            'name'      => '转换方式',
+            'type'      => 'varchar(1000)',
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+
+    'default' => array
+    (
+        'field' => 'sort,name,method,cdate',
+        'value' => array
+        (
+            '1,"字符串","strval({value})",' . DEVER_TIME,
+            '2,"整数","intval({value})",' . DEVER_TIME,
+            '3,"浮点数","floatval({value})",' . DEVER_TIME,
+            '4,"uri编码","urlencode({value})",' . DEVER_TIME,
+            '5,"uri编码-RFC3986规则","rawurlencode({value})",' . DEVER_TIME,
+            '6,"转小写","strtolower({value})",' . DEVER_TIME,
+            '7,"转大写","strtoupper({value})",' . DEVER_TIME,
+            '8,"去空值","trim({value})",' . DEVER_TIME,
+
+            '10,"时间戳","strtotime({value})",' . DEVER_TIME,
+            '11,"yyyy-MM-dd HH:mm:ss","date(\'Y-m-d H:i:s\', {value})",' . DEVER_TIME,
+            '12,"yyyy-MM-DDTHH:mm:ss+TIMEZONE","date(\'Y-m-d\\\TH:i:sP\', {value})",' . DEVER_TIME,
+            '13,"yyyy-MM-ddTHH:mm:ssZ","date(\'Y-m-d\\\TH:i:sZ\', {value})",' . DEVER_TIME,
+        ),
+        'num' => 1,
+    ),
+);

+ 31 - 0
table/openid.php

@@ -0,0 +1,31 @@
+<?php
+return array
+(
+    'name' => 'openid表',
+    'struct' => array
+    (
+        'account_id'        => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '账户',
+        ),
+
+        'env' => array
+        (
+            'name'      => '运行环境',
+            'type'      => 'tinyint(1)',
+        ),
+
+        'uid'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '用户ID',
+        ),
+
+        'openid'        => array
+        (
+            'type'      => 'varchar(60)',
+            'name'      => 'openid',
+        ),
+    ),
+);

+ 2 - 169
table/platform.php

@@ -1,21 +1,4 @@
 <?php
-$encrypt = array
-(
-    -1 => '无签名',
-    -2 => 'md5',
-    -3 => 'sha256',
-    -4 => 'sha1',
-);
-$id = Dever::input('id');
-if ($id) {
-    $info = Dever::db('platform_ssl', 'api')->select(['platform_id' => $id]);
-    if ($info) {
-        foreach ($info as $k => $v) {
-            $encrypt[$v['id']] = $v['name'];
-        }
-    }
-}
-
 return array
 (
     'name' => '平台表',
@@ -35,7 +18,7 @@ return array
 
         'method' => array
         (
-            'name'      => '请求方',
+            'name'      => '请求方',
             'type'      => 'tinyint(1)',
             'default'   => '2',
             'value'     => array
@@ -47,7 +30,7 @@ return array
 
         'post_method' => array
         (
-            'name'      => '请求头设置',
+            'name'      => '请求方式',
             'type'      => 'tinyint(1)',
             'default'   => '1',
             'value'     => array
@@ -70,155 +53,5 @@ return array
                 3 => 'XML',
             ),
         ),
-
-        'response_data' => array
-        (
-            'name'      => '数据字段',
-            'type'      => 'varchar(100)',
-        ),
-
-        'response_msg' => array
-        (
-            'name'      => '信息字段',
-            'type'      => 'varchar(100)',
-        ),
-
-        'response_code' => array
-        (
-            'name'      => '状态码字段',
-            'type'      => 'varchar(100)',
-        ),
-
-        'sign_name' => array
-        (
-            'name'      => '签名名称',
-            'type'      => 'varchar(100)',
-            //'default'   => 'sign',
-        ),
-
-        'sign_method' => array
-        (
-            'name'      => '签名加密方式',
-            'type'      => 'int(11)',
-            'default'   => '-1',
-            'value'     => $encrypt,
-        ),
-
-        'sign_col' => array
-        (
-            'name'      => '签名参数',
-            'type'      => 'varchar(1000)',
-        ),
-
-        'sign_verify_col' => array
-        (
-            'name'      => '验签参数',
-            'type'      => 'varchar(1000)',
-        ),
-
-        'sign_verify_type' => array
-        (
-            'name'      => '验签类型',
-            'type'      => 'tinyint(1)',
-            'default'   => '2',
-            'value'     => array
-            (
-                1 => '生成新签名做对比',
-                2 => '对签名解签',
-            ),
-        ),
-
-        'sign_verify_set' => array
-        (
-            'name'      => '验签设置',
-            'type'      => 'varchar(50)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '回调验签',
-                2 => '响应验签',
-            ),
-        ),
-
-        'sign_type' => array
-        (
-            'name'      => '签名形式',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => 'value形式',
-                2 => 'key=value形式',
-                3 => 'keyvalue形式',
-            ),
-        ),
-
-        'sign_split' => array
-        (
-            'name'      => '签名分隔符',
-            'type'      => 'varchar(30)',
-        ),
-
-        'sign_split_type' => array
-        (
-            'name'      => '分隔符处理',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '删除尾部分隔符',
-                2 => '不删除',
-            ),
-        ),
-
-        'sign_sort' => array
-        (
-            'name'      => '签名排序',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '按照签名参数排序',
-                2 => '按照签名参数首字母正序排序',
-                3 => '按照请求体首字母正序排序',
-            ),
-        ),
-
-        'sign_encode' => array
-        (
-            'name'      => '签名转码',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '不处理',
-                2 => 'urlencode编码',
-            ),
-        ),
-
-        'sign_empty' => array
-        (
-            'name'      => '签名空值',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '参与加密',
-                2 => '不参与加密',
-            ),
-        ),
-
-        'sign_after' => array
-        (
-            'name'      => '加密后处理',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '不处理',
-                2 => '转大写',
-                3 => '转小写',
-            ),
-        ),
     ),
 );

+ 11 - 27
table/platform_request_body.php

@@ -1,29 +1,8 @@
 <?php
-$type = array
-(
-    -1 => '字符串',
-    -2 => '数值',
-    //-3 => 'JSON',
-    -4 => '时间戳',
-    -5 => '时间格式:yyyy-MM-dd HH:mm:ss',
-    -6 => '时间格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE',
-);
-$id = Dever::input('id');
-if ($id) {
-    $api = Dever::db('api', 'api')->find($id);
-    if ($api) {
-        $info = Dever::db('platform_ssl', 'api')->select(['platform_id' => $api['platform_id']]);
-        if ($info) {
-            foreach ($info as $k => $v) {
-                $type[$v['id']] = $v['name'];
-            }
-        }
-    }
-}
 return array
 (
     'name' => '请求体通用参数配置',
-    'order' => 'id asc',
+    'order' => 'sort asc,id asc',
     'struct' => array
     (
         'platform_id' => array
@@ -41,15 +20,20 @@ return array
         'value' => array
         (
             'name'      => '参数值',
-            'type'      => 'varchar(150)',
+            'type'      => 'varchar(1000)',
         ),
 
         'type' => array
         (
-            'name'      => '参数类型',
-            'type'      => 'tinyint(1)',
-            'default'   => '-1',
-            'value'     => $type,
+            'name'      => '参数处理',
+            'type'      => 'varchar(100)',
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
         ),
     ),
 );

+ 14 - 2
table/platform_response_code.php

@@ -10,15 +10,21 @@ return array
             'type'      => 'int(11)',
         ),
 
+        'key' => array
+        (
+            'name'      => '状态码名',
+            'type'      => 'varchar(150)',
+        ),
+
         'value' => array
         (
-            'name'      => '返回码值',
+            'name'      => '状态码值',
             'type'      => 'varchar(150)',
         ),
 
         'type' => array
         (
-            'name'      => '参数类型',
+            'name'      => '状态码类型',
             'type'      => 'tinyint(1)',
             'default'   => '1',
             'value'     => array
@@ -27,5 +33,11 @@ return array
                 2 => '失败',
             ),
         ),
+
+        'msg' => array
+        (
+            'name'      => '返回信息',
+            'type'      => 'varchar(150)',
+        ),
     ),
 );

+ 120 - 0
table/platform_sign.php

@@ -0,0 +1,120 @@
+<?php
+return array
+(
+    'name' => '平台签名配置',
+    'order' => 'sort asc, id desc',
+    'struct' => array
+    (
+        'platform_id' => array
+        (
+            'name'      => '平台id',
+            'type'      => 'int(11)',
+        ),
+
+        'name' => array
+        (
+            'name'      => '签名名称',
+            'type'      => 'varchar(150)',
+            'default'   => 'sign',
+        ),
+
+        'arg' => array
+        (
+            'name'      => '签名参数',
+            'type'      => 'varchar(2000)',
+        ),
+
+        'encrypt' => array
+        (
+            'name'      => '加密方式',
+            'type'      => 'int(11)',
+            'default'   => '-1',
+            //'value'     => $encrypt,
+        ),
+
+        'after' => array
+        (
+            'name'      => '最后处理',
+            'type'      => 'int(11)',
+            'value'     => 'api/format',
+        ),
+
+        'kv_type' => array
+        (
+            'name'      => '键名键值形式',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => 'value形式',
+                2 => 'key形式',
+                3 => 'key=value形式',
+                4 => 'keyvalue形式',
+                5 => 'key:value形式',
+            ),
+        ),
+
+        'kv_sort' => array
+        (
+            'name'      => '排序方式',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => '按照签名参数填写的键名顺序排序',
+                2 => '按照签名参数键名字符顺序升序排序',
+            ),
+        ),
+
+        'kv_value_empty' => array
+        (
+            'name'      => '键值空值',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => '参与签名',
+                2 => '不参与签名',
+            ),
+        ),
+
+        'kv_key_handle' => array
+        (
+            'name'      => '健名处理',
+            'type'      => 'int(11)',
+            'value'     => 'api/format',
+        ),
+
+        'kv_value_handle' => array
+        (
+            'name'      => '键值处理',
+            'type'      => 'int(11)',
+            'value'     => 'api/format',
+        ),
+
+        'kv_join' => array
+        (
+            'name'      => '连接符',
+            'type'      => 'varchar(30)',
+        ),
+
+        'kv_join_handle' => array
+        (
+            'name'      => '连接符处理',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => '删除尾部连接符',
+                2 => '不删除',
+            ),
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+);

+ 2 - 2
table/sku.php

@@ -4,9 +4,9 @@ return array
     'name' => '接口规格设置',
     'struct' => array
     (
-        'api_id' => array
+        'app_func_id' => array
         (
-            'name'      => '接口ID',
+            'name'      => '功能id',
             'type'      => 'int(11)',
         ),
 

+ 2 - 2
table/spec.php

@@ -5,9 +5,9 @@ return array
     'order' => 'sort asc',
     'struct' => array
     (
-        'api_id' => array
+        'app_func_id' => array
         (
-            'name'      => '接口ID',
+            'name'      => '功能id',
             'type'      => 'int(11)',
         ),
         'name' => array

+ 2 - 2
table/spec_value.php

@@ -5,9 +5,9 @@ return array
     'order' => 'sort asc',
     'struct' => array
     (
-        'api_id' => array
+        'app_func_id' => array
         (
-            'name'      => '接口ID',
+            'name'      => '功能id',
             'type'      => 'int(11)',
         ),
         'spec_id' => array