rabin 2 днів тому
батько
коміт
52d63ce372

+ 19 - 4
app/Api/Notify.php

@@ -21,24 +21,39 @@ class Notify extends Api
             $this->error('error');
         }
         $s = \Dever\Helper\Str::decode($input['s']);
+        $param = [];
         if ($s) {
             $data = explode('|', $s);
             $api_id = $data[0];
+            $account_project = $data[1];
+            $account_id = $data[2];
             if (!$api_id) {
                 $this->error('error');
             }
-            if (isset($data[1])) {
-                $method = $data[1];
+            if (!$account_project) {
+                $this->error('error');
+            }
+            if (!$account_id) {
+                $this->error('error');
+            }
+            if (isset($data[3])) {
+                $method = $data[3];
                 unset($data[0]);
                 unset($data[1]);
+                unset($data[2]);
+                unset($data[3]);
                 $param = array_values($data);
+                Dever::call($method . '_start', $param);
             }
         } else {
             $this->error('error');
         }
         unset($input['s']);
         unset($input['l']);
-        $state = $this->setting($api_id);
+        $setting['account_project'] = $account_project;
+        $setting['account_id'] = $account_id;
+
+        $state = $this->setting($api_id, $setting);
         if (!$state) {
             $this->error('error');
         }
@@ -62,7 +77,7 @@ class Notify extends Api
         if ($status < 3 && isset($method)) {
             $param[] = $status;
             $param[] = $body;
-            $msg = Dever::call($method, $param);
+            $msg = Dever::call($method . '_end', $param);
             if ($msg) {
                 $this->error($msg);
             }

+ 15 - 0
app/Lib/Account.php

@@ -29,6 +29,20 @@ class Account
         } else {
             $where = ['key' => $account];
         }
+        $account = Dever::db($project . '/account')->find($where);
+        if (!$account) {
+            Dever::error('账户无效');
+        }
+        if ($project != 'api') {
+            $info = Dever::db('api/account')->find(['key' => $account['key']]);
+            if (!$info) {
+                Dever::error('账户无效');
+            }
+            $account['app_id'] = $info['app_id'];
+            $account['platform_id'] = $info['platform_id'];
+        }
+        return $account;
+        /*
         $account = Dever::db('api/account')->find($where);
         if ($project != 'api') {
             $info = Dever::db($project . '/account')->find(['key' => $account['key']]);
@@ -41,6 +55,7 @@ class Account
             }
         }
         return $account;
+        */
     }
 
     public function run($account, $func, $param = [], $env = 1, $method = 'run', $project = 'api')

+ 1 - 1
app/Lib/Api.php

@@ -27,7 +27,7 @@ class Api extends Platform
     # 生成回调
     protected function createNotify($field)
     {
-        $encode = $this->info['id'];
+        $encode = $this->info['id'] . '|' . $field['account_project'] . '|' . $field['account_id'];
         if (isset($field['notify'])) {
             $encode .= '|' . $field['notify'];
         }

+ 2 - 2
app/Lib/App.php

@@ -46,9 +46,9 @@ class App
         return Dever::db('api/platform_setting')->select(['platform_id' => $platform_id]);
     }
 
-    public function getCert($account_id)
+    public function getCert($account_id, $project = 'api')
     {
-        $account = Dever::db('api/account')->find($account_id);
+        $account = Dever::load(Account::class)->get($account_id, $project);
         return Dever::db('api/platform_cert')->select(['platform_id' => $account['platform_id']]);
     }
 

+ 4 - 1
app/Lib/Platform.php

@@ -39,6 +39,9 @@ class Platform
         if ($this->info['method'] == 1) {
             $this->info['post_method'] = 1;
         }
+        if ($this->info['response_type'] == -1) {
+            $this->info['response_type'] = $this->platform['response_type'];
+        }
     }
 
     protected function field($field)
@@ -98,7 +101,7 @@ class Platform
         $curl->setResultHeader(true);
         $response_body = $curl->result();
         $response_header = $curl->header();
-        $response_config = ['id' => $this->platform['id'], 'type' => $this->platform['response_type']];
+        $response_config = ['id' => $this->platform['id'], 'type' => $this->info['response_type']];
         $response = Dever::load(Response::class)->init($response_body, $response_header, $this->field, $response_config, $this->type, $this->info['id']);
         $result = $response->out();
         $log = [];

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

@@ -63,6 +63,8 @@ class Response
             $this->body = Dever::json_decode($this->body);
         } elseif ($this->config['type'] == 3) {
             $this->body = (array) simplexml_load_string($this->body, null, LIBXML_NOCDATA);
+        } elseif ($this->config['type'] == 4) {
+            
         } else {
             if (strstr($this->body, ',')) {
                 $this->body = explode(',', $this->body);

+ 1 - 1
app/Lib/Util.php

@@ -72,7 +72,7 @@ class Util
         $appid = $this->setting($appid, $account['id'], $project);
         $secret = $this->setting($secret, $account['id'], $project);
         if ($account && $appid && $secret) {
-            $param = ['appid' => $appid, 'appsecret' => $secret];
+            $param = ['appid' => $appid, 'secret' => $secret];
             $info = Dever::db('api/token')->find($param);
             if ($info && time() <= $info['edate']) {
                 $result = $info['token'];

+ 9 - 3
manage/api.php

@@ -1,4 +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_info.php');
 $config = [
     'list' => [
@@ -18,12 +22,12 @@ $config = [
             ],
         ],
         'data_button' => [
-            '设置' => ['edit'],
+            '设置' => ['edit', ['platform_id' => $platform_id]],
             //'删除' => 'delete',
             '复制' => ['api', 'api/manage.copyApi'],
         ],
         'button' => [
-            '新增' => ['fastadd', ['field' => 'name,env,platform_id,uri']],
+            '新增' => ['fastadd', ['platform_id' => $platform_id, 'field' => 'name,env,platform_id,uri']],
         ],
         'search' => [
             'name',
@@ -38,7 +42,7 @@ $config = [
             '基本设置' => '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',
+            '响应参数' => 'response_type,api/api_response_header,api/api_response_body',
             
             '存储设置' => 'api/api_save',
             '回调设置' => 'notify,api/api_notify,api/api_notify_body,api/api_notify_code',
@@ -86,6 +90,8 @@ $config = [
                 'where'  => ['api_id' => 'id'],
             ],
 
+            'response_type' => 'radio',
+
             'api/api_response_body' => [
                 'name' => '响应体',
                 'desc' => '填写后,平台中的标准响应体将失效,并且只保留填写后的响应体,格式:data[].name,不是列表则为data.name',

+ 1 - 1
manage/app_func.php

@@ -37,7 +37,7 @@ return [
             '输入输出' => 'api/app_func_input,api/app_func_output',
         ],
         'field'    => [
-            'app_id' => 'hidden',
+            'app_id' => 'text',
             'name',
             'type',
             'key' => [

+ 4 - 4
manage/platform_info.php

@@ -12,19 +12,19 @@ $config = [
             '加密' => ['route', [
                 'path' => 'api_manage/platform_ssl',
                 'param' => [
-                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform_info', 'parent' => 'api_manage/platform_info'],
                 ],
             ]],
             '签名' => ['route', [
                 'path' => 'api_manage/platform_sign',
                 'param' => [
-                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform_info', 'parent' => 'api_manage/platform_info'],
                 ],
             ]],
             '接口' => ['route', [
                 'path' => 'api_manage/api',
                 'param' => [
-                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform_info', 'parent' => 'api_manage/platform_info'],
                 ],
             ]],
         ],
@@ -33,7 +33,7 @@ $config = [
             '定义格式转换' => ['route', [
                 'path' => 'api_manage/format',
                 'param' => [
-                    'set' => ['menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                    'set' => ['menu' => 'api_manage/platform_info', 'parent' => 'api_manage/platform_info'],
                 ],
             ]],
         ],

+ 1 - 1
manage/platform_request_body.php

@@ -16,7 +16,7 @@ return [
             ],
             'type' => [
                 'type' => 'cascader',
-                'option'    => 'Dever::call("Api/Lib/Util.fieldType", "{platform_id}")',
+                'option'    => 'Dever::call("Api/Lib/Util.fieldType", Dever::call("Api/Manage/Lib/Platform.getId"))',
                 'clearable' => true,
             ],
         ],

+ 1 - 1
manage/platform_ssl.php

@@ -67,7 +67,7 @@ return [
             'decrypt_cert_id' => [
                 'type' => 'select',
                 'clearable' => true,
-                'option'     => 'Dever::call("Api/Lib/Cert.list", "{platform_id}"))',
+                'option'     => 'Dever::call("Api/Lib/Cert.list", "{platform_id}")',
             ],
         ],
 

+ 13 - 0
table/api.php

@@ -41,6 +41,19 @@ return [
             ],
         ],
 
+        'response_type' => [
+            'name'      => '响应数据类型',
+            'type'      => 'tinyint(1)',
+            'default'   => '-1',
+            'value'     => [
+                -1 => '使用平台标准请求方式',
+                //1 => '无标准响应',
+                2 => 'JSON',
+                3 => 'XML',
+                4 => 'Buffer',
+            ],
+        ],
+
         'notify' => [
             'name'      => '是否有回调',
             'type'      => 'tinyint(1)',

+ 1 - 0
table/platform.php

@@ -41,6 +41,7 @@ return [
                 //1 => '无标准响应',
                 2 => 'JSON',
                 3 => 'XML',
+                4 => 'Buffer',
             ],
         ],
     ],