rabin 17 godzin temu
rodzic
commit
8d955f539b

+ 25 - 3
lib/Account.php

@@ -19,11 +19,33 @@ class Account
         return $data;
     }
 
-    public function run($account, $func, $param = [], $env = 1, $method = 'run', $project = 'api')
+    public function get($account, $project = 'api')
     {
-        if (!is_array($account)) {
-            $account = Dever::db('account', 'api')->find(['key' => $account]);
+        if (is_array($account)) {
+            return $account;
+        }
+        if (is_numeric($account)) {
+            $where = ['id' => $account];
+        } else {
+            $where = ['key' => $account];
+        }
+        $account = Dever::db('account', 'api')->find($where);
+        if ($project != 'api') {
+            $info = Dever::db('account', $project)->find(['key' => $account['key']]);
+            if ($info) {
+                $info['app_id'] = $account['app_id'];
+                $info['platform_id'] = $account['platform_id'];
+                return $info;
+            } else {
+                Dever::error('账户无效');
+            }
         }
+        return $account;
+    }
+
+    public function run($account, $func, $param = [], $env = 1, $method = 'run', $project = 'api')
+    {
+        $account = $this->get($account, $project);
         if (!$account) {
             Dever::error('账户无效');
         }

+ 3 - 3
lib/App.php

@@ -31,12 +31,12 @@ class App
     {
         $set['join'] = [
             [
-                'table' => 'platform',
+                'table' => 'api_platform',
                 'type' => 'left join',
-                'on' => 'platform.id=app_platform.platform_id',
+                'on' => 't0.id=main.platform_id',
             ],
         ];
-        $set['col'] = 'platform.id as id,platform.name as name';
+        $set['col'] = 't0.id as id,t0.name as name';
         $platform = Dever::db('app_platform', 'api')->select(['app_id' => $app], $set);
         return $platform;
     }

+ 4 - 0
lib/Platform.php

@@ -56,8 +56,12 @@ class Platform
                             $v['value'] = $field[$v['key']];
                         }
                         $field[$v['key']] = $v['value'];
+                    } else {
+                        Dever::error('account error');
                     }
                 }
+            } else {
+                Dever::error('account error');
             }
         } else {
             Dever::error('account error');

+ 2 - 2
lib/Platform/Field.php

@@ -6,11 +6,11 @@ class Field
     public $ssl;
     public function __construct($data)
     {
+        $this->data = $data;
         $this->ssl = new Ssl($this);
         $this->set('time', time());
         $this->set('timestamp', \Dever\Helper\Secure::timestamp());
         $this->set('nonce', \Dever\Helper\Secure::nonce());
-        $this->data = $data;
     }
 
     public function add($index, $value, $key = 'body')
@@ -115,7 +115,7 @@ class Field
 
     public function value($source, $type = '', $state = true)
     {
-        $value = trim($source);
+        $value = trim($source, " ");
         if ($this->data && isset($this->data[$value])) {
             $value = $this->data[$value];
         } elseif (strstr($value, 'key=') && strstr($value, '&')) {

+ 0 - 1
lib/Platform/Sign.php

@@ -110,7 +110,6 @@ class Sign
     {
         $string = '';
         foreach ($this->info as $k => $v) {
-            
             if ($this->config['kv_value_empty'] == 2 && null === $v) {
                 continue;
             }

+ 22 - 1
lib/Platform/Value.php

@@ -129,7 +129,28 @@ class Value
                 if (empty($temp[1])) {
                     $temp[1] = '';
                 }
-                $data[$k] = $this->field->value($temp[0], $temp[1], false);
+                $state = false;
+                # 临时特殊处理,以后封装
+                if (strstr($temp[0], '\n')) {
+                    $array = explode('\n', $temp[0]);
+                    foreach ($array as &$v1) {
+                        if (isset($data[$v1])) {
+                            $v1 = $data[$v1];
+                        }
+                    }
+                    $temp[0] = implode("\n", $array);
+                    $state = true;
+                } elseif (strstr($temp[0], '+')) {
+                    $array = explode('+', $temp[0]);
+                    foreach ($array as &$v1) {
+                        if (isset($data[$v1])) {
+                            $v1 = $data[$v1];
+                        }
+                    }
+                    $temp[0] = implode('', $array);
+                    $state = true;
+                }
+                $data[$k] = $this->field->value($temp[0], $temp[1], $state);
                 $this->field->set($k, $data[$k]);
             }
         }

+ 35 - 17
lib/Sku.php

@@ -10,7 +10,7 @@ class Sku
             $where['key'] = '-1';
             $sku = Dever::db('sku', $app)->find($where);
         } elseif ($spec_type == 3) {
-            $sku = Dever::db('sku', $app)->find($where, ['order' => 'price asc,id desc']);
+            $sku = Dever::db('sku', $app)->find($where, ['order' => 'price asc']);
         }
         if (isset($sku) && $sku && $sku['key']) {
             $result['price'] = $sku['price'];
@@ -26,28 +26,41 @@ class Sku
         return $result;
     }
 
-    # 多规格获取多个价格
+    # 获取价格信息
+    public function getInfo($where, $app)
+    {
+        $where['state'] = 1;
+        $info = Dever::db('sku', $app)->find($where);
+        if ($info) {
+            $info['name'] = $this->getName($info['key'], $app);
+            if (!$info['pic']) {
+                $key = explode(',', $info['key']);
+                $value = Dever::db('spec_value', $app)->find($key[0], ['col' => 'id,value,pic']);
+                if ($value && $value['pic']) {
+                    $info['pic'] = $value['pic'];
+                }
+            }
+        }
+        return $info;
+    }
+
+    # 获取价格列表
     public function getList($where, $sku_id, $app)
     {
         $result = [];
+        $where['state'] = 1;
         $sku = Dever::db('sku', $app)->select($where);
         if ($sku) {
             $spec = [];
             $result['info'] = [];
             foreach ($sku as $k => $v) {
-                $t = $where;
-                $k = str_replace(',', '_', $v['key']);
-                $t['id'] = $v['id'];
-                $t['key'] = $k;
-                $t['pic'] = $v['pic'];
-                $t['price'] = $v['price'];
-                if (isset($v['unum'])) {
-                    $t['unum'] = $v['unum'];
-                }
-                $t['name'] = $this->getName($v['key'], $app);
-                $result['price'][$k] = $t;
+                unset($v['state']);
+                unset($v['cdate']);
+                $k = $v['key'];
+                $v['name'] = $this->getName($v['key'], $app);
+                $result['price'][$k] = $v;
                 if ($sku_id && $sku_id == $v['id']) {
-                    $result['info'] = $t;
+                    $result['info'] = $v;
                     $spec = explode(',', $v['key']);
                 }
             }
@@ -57,7 +70,7 @@ class Sku
     }
 
     # 获取某个sku的名称
-    public function getName($key, $app)
+    public function getName($key, $app, $show = false)
     {
         if (!$key || $key == '-1') {
             return '默认规格';
@@ -68,11 +81,16 @@ class Sku
             if ($data) {
                 foreach ($data as $k => $v) {
                     $info = Dever::db('spec', $app)->find($v['spec_id']);
-                    //$name[] = $info['name'] . ':' . $v['value'];
-                    $name[] = $v['value'];
+                    if ($show) {
+                        $name[] = $info['name'] . ':' . $v['value'];
+                    } else {
+                        $name[] = $v['value'];
+                    }
                 }
             }
             return implode(' & ', $name);
         }
     }
+
+    # 获取
 }

+ 1 - 1
lib/Spec.php

@@ -45,7 +45,7 @@ class Spec
                 $w = $where;
                 $w['spec_id'] = $v['id'];
                 unset($v['id']);
-                $v['value'] = Dever::db('spec_value', $app)->select($w, ['col' => 'id,value']);
+                $v['value'] = Dever::db('spec_value', $app)->select($w, ['col' => 'id,value,pic']);
                 if ($select) {
                     foreach ($v['value'] as &$v1) {
                         $v1['selected'] = false;

+ 46 - 4
lib/Util.php

@@ -14,10 +14,19 @@ class Util
         return $this->createNumber($prefix, $table, $where, $key);
     }
 
+    # 获取某个setting值
+    public function setting($key, $account, $project = 'api')
+    {
+        $setting = Dever::db('platform_setting', 'api')->find(['key' => $key]);
+        $setting = Dever::db('account_setting', $project)->find(['account_id' => $account, 'platform_setting_id' => $setting['id']]);
+        $value = $setting['value'] ?? 0;
+        return $value;
+    }
+
     # 获取openid 仅jspai和小程序需要openid
-    public function openid($account, $env, $uid, $result = [])
+    public function openid($account, $env, $uid, $result = [], $project = 'api')
     {
-        $account = Dever::db('account', 'api')->find(['key' => $account]);
+        $account = Dever::load('account', 'api')->get($account, $project);
         if ($account) {
             $info = Dever::db('openid', 'api')->find(['account_id' => $account['id'], 'uid' => $uid, 'env' => $env]);
             if ($info) {
@@ -33,7 +42,7 @@ class Util
                 } elseif ($env == 5) {
                     # 小程序
                     $param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
-                    $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env);
+                    $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env, 'run', $project);
                     if (isset($data['openid'])) {
                         $result['openid'] = $data['openid'];
                         $update['uid'] = $uid;
@@ -48,6 +57,39 @@ class Util
         return $result;
     }
 
+    # 获取token
+    public function token($account, $env, $project = 'api')
+    {
+        $account = Dever::load('account', 'api')->get($account, $project);
+        $result = '';
+        if ($env == 5) {
+            $appid = 'applet_appid';
+            $secret = 'applet_secret';
+        }
+        $appid = $this->setting($appid, $account['id'], $project);
+        $secret = $this->setting($secret, $account['id'], $project);
+        if ($account && $appid && $secret) {
+            $param = ['appid' => $appid, 'appsecret' => $secret];
+            $info = Dever::db('token', 'api')->find($param);
+            if ($info && time() <= $info['edate']) {
+                $result = $info['token'];
+            } else {
+                $data = Dever::load('account', 'api')->run($account, 'access_token', $param, 1, 'run', $project);
+                if (isset($data['access_token'])) {
+                    $result = $data['access_token'];
+                    $param['token'] = $result;
+                    $param['edate'] = time() + $data['expires_in'];
+                    if ($info) {
+                        Dever::db('token', 'api')->update($info['id'], $param);
+                    } else {
+                        Dever::db('token', 'api')->insert($param);
+                    }
+                }
+            }
+        }
+        return $result;
+    }
+
     # 获取参数类型
     public function fieldType($platform_id)
     {
@@ -88,7 +130,7 @@ class Util
     {
         $info = Dever::db('format', 'api')->find($id);
         if ($info) {
-            $info['method'] = str_replace('{value}', "'{value}'", $info['method']);
+            //$info['method'] = str_replace('{value}', "'{value}'", $info['method']);
             $value = \Dever\Helper\Str::val($info['method'], ['value' => $value]);
         }
         return $value;

+ 13 - 2
manage/account.php

@@ -31,7 +31,7 @@ return [
             '新增' => ['fastadd', 'name,key,app_platform'],
         ],
         'data_button' => [
-            '设置' => ['edit', 'name,key,app_platform_name,api/account_setting'],
+            '设置' => ['edit', 'name,key,app_platform_name,api/account_setting,desc'],
             '证书' => ['route', [
                 'path' => 'api_manage/account_cert',
                 'param' => [
@@ -72,8 +72,19 @@ return [
                 'where'  => ['account_id' => 'id'],
                 'default' => $account_setting,
             ],
+
+            'desc' => [
+                'desc' => '如果该账户要推给客户使用,需要加一下介绍说明,方便客户填写参数配置',
+                'type' => 'textarea',
+                'autosize' => ['minRows' => 4],
+                'type' => 'editor',
+                'editorMenu' => [
+                    'uploadImage' => 1,
+                    'uploadVideo' => 3,
+                ],
+            ],
         ],
         'check' => 'key',
-        'start' => ['manage/common.updateKey', 'api/account.update'],
+        'start' => ['manage/util.updateKey', 'api/account.update'],
     ],
 ];

+ 124 - 0
manage/platform_http.php

@@ -0,0 +1,124 @@
+<?php
+$config = [
+    'source' => 'api/platform',
+    'list' => [
+        'field'      => [
+            'id',
+            'name',
+            'host',
+        ],
+        'data_button' => [
+            '设置' => 'edit',
+            '加密' => ['route', [
+                'path' => 'api_manage/platform_ssl',
+                'param' => [
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                ],
+            ]],
+            '签名' => ['route', [
+                'path' => 'api_manage/platform_sign',
+                'param' => [
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                ],
+            ]],
+            '接口' => ['route', [
+                'path' => 'api_manage/api',
+                'param' => [
+                    'set' => ['platform_id' => 'id', 'menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                ],
+            ]],
+        ],
+        'button' => [
+            '新增' => ['fastadd', 'name,host'],
+            '定义格式转换' => ['route', [
+                'path' => 'api_manage/format',
+                'param' => [
+                    'set' => ['menu' => 'api_manage/platform', 'parent' => 'api_manage/platform'],
+                ],
+            ]],
+        ],
+        'search' => [
+            'name',
+        ],
+    ],
+    'update' => [
+        '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' => [
+            '基本设置' => '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'    => [
+            'name',
+            'host',
+            'method' => [
+                'type' => 'radio',
+                'control' => true,
+            ],
+            'post_method' => [
+                'type' => 'radio',
+            ],
+
+            'api/platform_setting' => [
+                'name' => '账户参数',
+                'desc' => '设置账户需要的参数',
+                'where'  => ['platform_id' => 'id'],
+            ],
+
+            'api/platform_cert' => [
+                'name' => '账户证书',
+                'desc' => '设置账户需要的证书',
+                'where'  => ['platform_id' => 'id'],
+            ],
+
+            'api/platform_request_body' => [
+                'name' => '请求体设置',
+                'desc' => '设置平台标准请求体',
+                'where'  => ['platform_id' => 'id'],
+            ],
+            'api/platform_request_header' => [
+                'name' => '请求头设置',
+                'desc' => '设置平台标准请求头',
+                'where'  => ['platform_id' => 'id'],
+            ],
+
+            'response_type' => 'radio',
+
+            'api/platform_response_body' => [
+                'name' => '标准响应体',
+                'desc' => '设置平台标准响应体,填写后,将只保留填写后的响应体,格式:data[].name,不是列表则为data.name,如果填写了“数据字段”,这里仅返回“数据字段”里的数据',
+                'where'  => ['platform_id' => 'id'],
+            ],
+            'api/platform_response_header' => [
+                'name' => '标准响应头',
+                'desc' => '设置平台标准响应头,不填写不保留响应头,格式:data[].name,不是列表则为data.name',
+                'where'  => ['platform_id' => 'id'],
+            ],
+
+            'api/platform_response_code' => [
+                'name' => '响应状态码',
+                'desc' => '设置标准的响应状态码,也可以只设置成功值,其他值均为失败',
+                'where'  => ['platform_id' => 'id'],
+            ],
+
+            'api/platform_convert' => [
+                'name' => '字段转换',
+                'where'  => ['platform_id' => 'id'],
+                'desc' => '设置之后,所有平台过来的字段,都将按照这个转换规则进行转换',
+            ],
+        ],
+
+        'control' => [
+            'post_method' => [
+                'method' => 2,
+            ],
+        ],
+    ],
+];
+$id = Dever::input('id');
+$load = Dever::input('load');
+if (($load == '/api_manage/platform' || $load == '/api_manage/api') && !$id) {
+    $config['update']['desc'] = '';
+    unset($config['update']['tab']);
+}
+return $config;

+ 2 - 0
manage/platform_ssl.php

@@ -59,6 +59,7 @@ return [
             ],
             'encrypt_cert_id' => [
                 'type' => 'select',
+                'clearable' => true,
                 'option'     => 'Dever::call("api/cert.list", ['.$platform_id.'])',
             ],
 
@@ -69,6 +70,7 @@ return [
             ],
             'decrypt_cert_id' => [
                 'type' => 'select',
+                'clearable' => true,
                 'option'     => 'Dever::call("api/cert.list", ['.$platform_id.'])',
             ],
         ],

+ 5 - 0
table/account.php

@@ -12,6 +12,11 @@ return [
             'name'      => '账户标识',
         ],
 
+        'desc' => [
+            'name'      => '账户介绍',
+            'type'      => 'text',
+        ],
+
         'app_platform'       => [
             'type'      => 'varchar(30)',
             'name'      => '应用与平台',

+ 1 - 0
table/api_log.php

@@ -1,6 +1,7 @@
 <?php
 return [
     'name' => 'api日志',
+    'partition' => 'Dever::call("manage/util.system")',
     'store' => 'log',
     'struct' => [
         'platform_id' => [

+ 1 - 0
table/openid.php

@@ -1,6 +1,7 @@
 <?php
 return [
     'name' => 'openid表',
+    'partition' => 'Dever::call("manage/util.system")',
     'struct' => [
         'account_id'        => [
             'type'      => 'int(11)',

+ 24 - 0
table/token.php

@@ -0,0 +1,24 @@
+<?php
+return [
+    'name' => 'token表',
+    'struct' => [
+        'appid'        => [
+            'type'      => 'varchar(100)',
+            'name'      => 'appid',
+        ],
+
+        'token'        => [
+            'type'      => 'varchar(1000)',
+            'name'      => 'token值',
+        ],
+
+        'edate'        => [
+            'type'      => 'int(11)',
+            'name'      => '过期时间',
+        ],
+    ],
+
+    'index' => [
+        'search' => 'appid',
+    ],
+];