diff --git a/!.env b/!.env new file mode 100644 index 0000000..3410a9b --- /dev/null +++ b/!.env @@ -0,0 +1,12 @@ +APP_DEBUG = true + +DB_TYPE = mysql +DB_HOST = 127.0.0.1 +DB_NAME = mpay +DB_USER = admin +DB_PASS = Aa123456 +DB_PORT = 3306 +DB_CHARSET = utf8 +DB_PREFIX = mpay_ + +DEFAULT_LANG = zh-cn \ No newline at end of file diff --git a/app/controller/api/PayManageController.php b/app/controller/api/PayManageController.php index e0da182..fc0c58b 100644 --- a/app/controller/api/PayManageController.php +++ b/app/controller/api/PayManageController.php @@ -116,20 +116,39 @@ class PayManageController extends BaseController { $platform = Platform::where('platform', $acc->getData('platform'))->find(); $user = User::where('pid', $acc->pid)->find(); - $query = \unserialize($platform->query); - $data = [ - 'pid' => $user->pid, - 'key' => $user->secret_key, - 'aid' => $acc->id, - 'platform' => $acc->getData('platform'), - 'account' => $acc->account, - 'password' => $acc->password, - 'payclass' => $platform->class_name, - 'query' => \var_export($query, \true) - ]; - $config = View::fetch('tpl/account_config', $data); - $name = "{$data['pid']}_{$data['aid']}"; - $path = "../config/payconfig/{$name}.php"; + $query = var_export(\unserialize($platform->query), \true); + $config = << [ + 'pid' => {$user->pid}, + 'key' => '$user->secret_key' + ], + // 收款平台账号配置 + 'pay' => [ + // 账号id + 'aid' => $acc->id, + // 收款平台 + 'platform' => '{$acc->getData('platform')}', + // 插件类名 + 'payclass' => '{$platform->class_name}', + // 账号 + 'account' => '{$acc->account}', + // 密码 + 'password' => '{$acc->password}', + // 订单查询参数配置 + 'query' => {$query}, + ] +]; + +EOF; + $name = "{$user->pid}_{$acc->id}"; + $path = config_path() . "/payconfig/{$name}.php"; \file_put_contents($path, $config); } } diff --git a/app/controller/api/PluginController.php b/app/controller/api/PluginController.php index 4398bb1..db89c17 100644 --- a/app/controller/api/PluginController.php +++ b/app/controller/api/PluginController.php @@ -10,36 +10,103 @@ use think\facade\View; class PluginController extends BaseController { - // 插件列表 + // 获取插件列表 public function getPluginList() { - $query = $this->request->get(); - $data = Platform::order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]); - if ($data) { - return json(['code' => 0, 'msg' => 'OK', 'count' => $data->total(), 'data' => $data->items()]); + $plugin_config = $this->getPluginConfig(); + if ($plugin_config) { + return json(['code' => 0, 'msg' => 'OK', 'count' => \count($plugin_config), 'data' => $plugin_config]); } else { return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); } } + // 测试 + public function test() + { + // $res = $this->addPlugin(['platform' => 'haopay', 'name' => '好支付', 'class_name' => 'Haopay', 'price' => 99, 'describe' => '好支付', 'website' => 'https://store.zhihuijingyingba.com/', 'state' => 1, 'query' => []]); + // $res = $this->delPlugin('haopay'); + $res = $this->setPlugin('haopay', ['state' => 0]); + return $res; + } + // 添加插件 + public function addPlugin(array $option = []) + { + $keys = ['platform', 'name', 'class_name', 'price', 'describe', 'website', 'state', 'query']; + $config = []; + foreach ($option as $key => $value) { + if (in_array($key, $keys)) { + $config[$key] = $value; + } + } + $plugin_config = $this->getPluginConfig(); + $plugin_platform = $config['platform'] ?: ''; + foreach ($plugin_config as $value) { + if ($plugin_platform == $value['platform']) { + return 1; //'插件已存在' + } + } + $plugin_config[] = $config; + $this->savePluginConfig($plugin_config, '支付插件列表'); + return 0; + } + // 删除插件 + public function delPlugin($plugin_name = '') + { + $plugin_config = $this->getPluginConfig(); + $keys = []; + foreach ($plugin_config as $index => $value) { + if ($value['platform'] == $plugin_name) { + $keys[] = $index; + } + } + foreach ($keys as $index) { + unset($plugin_config[$index]); + } + $config = \array_values($plugin_config); + $this->savePluginConfig($config, '支付插件列表'); + return 0; + } + // 修改插件 + public function setPlugin($platform = '', $option = []) + { + $config = $this->getPluginConfig(); + if (!$platform) { + return 1; //'请选择插件' + } + if (!$option) { + return 2; //请添加插件配置 + } + foreach ($config as $index => $options) { + if ($options['platform'] == $platform) { + foreach ($options as $key => $value) { + if (\array_key_exists($key, $option)) { + $config[$index][$key] = $option[$key]; + } + } + $this->savePluginConfig($config, '支付插件列表'); + return 0; + } + } + } // 插件启用 public function pluginEnable() { $info = $this->request->post(); - $up_res = Platform::update($info); + $up_res = $this->setPlugin($info['platform'], ['state' => $info['state']]); if ($up_res) { - return json(\backMsg(0, '成功')); - } else { return json(\backMsg(1, '失败')); + } else { + return json(\backMsg(0, '成功')); } } // 插件选项 public function pluginOption() { // 加载平台配置 - $platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig'); + $config = $this->getPluginConfig(); $option = []; - foreach ($platform as $key => $value) { - $option[] = ['platform' => $key, 'name' => $value]; + foreach ($config as $value) { + $option[] = ['platform' => $value['platform'], 'name' => $value['name']]; } return json($option); } @@ -60,4 +127,27 @@ class PluginController extends BaseController return \json(\backMsg(1, '创建成功')); } } + // 获取插件配置 + private function getPluginConfig(): array + { + $payplugin_path = config_path() . '/extendconfig/payplugin.php'; + if (!file_exists($payplugin_path)) { + return []; + } + // 加载插件配置 + $payplugin_config = require_once $payplugin_path; + return $payplugin_config; + } + // 保存插件配置 + private function savePluginConfig(array $config, string $note = '说明') + { + $payplugin_path = config_path() . '/extendconfig/payplugin.php'; + $note_tpl = << + array ( + 'platform' => 'sqbpay', + 'name' => '收钱吧', + 'class_name' => 'ShouQianBa', + 'price' => '99.00', + 'describe' => '主流移动支付全能收 信用卡,花呗都能用,生意帮手收钱吧,移动收款就用它!', + 'website' => 'https://www.shouqianba.com/', + 'state' => 1, + 'query' => 'a:8:{s:8:"date_end";N;s:10:"date_start";N;s:4:"page";i:1;s:9:"page_size";i:10;s:13:"upayQueryType";i:0;s:6:"status";s:4:"2000";s:8:"store_sn";s:0:"";s:4:"type";s:2:"30";}', + ), + 1 => + array ( + 'platform' => 'storepay', + 'name' => '数字门店', + 'class_name' => 'ZhiHuiJingYing', + 'price' => '99.00', + 'describe' => '数字门店', + 'website' => 'https://store.zhihuijingyingba.com/', + 'state' => 1, + 'query' => 'a:7:{s:6:"pageNo";i:1;s:8:"pageSize";i:10;s:9:"payClient";i:4;s:6:"status";i:2;s:2:"_t";N;s:16:"createTime_begin";N;s:14:"createTime_end";N;}', + ), + 2 => + array ( + 'platform' => 'ysepay', + 'name' => '小Y经营', + 'class_name' => 'Ysepay', + 'price' => '99.00', + 'describe' => '为商户和消费者提供安全、便捷、高效的支付产品与服务助力商户提升运营效率,实现数字化运营', + 'website' => 'https://xym.ysepay.com/', + 'state' => 1, + 'query' => 'a:10:{s:7:"storeNo";s:0:"";s:7:"bizType";i:3;s:7:"payType";s:0:"";s:11:"orderStatus";i:3;s:5:"trmNo";s:0:"";s:12:"operatorUser";s:0:"";s:13:"codeBoardCode";s:0:"";s:8:"pageSize";i:10;s:6:"pageNo";i:1;s:7:"orderNo";s:0:"";}', + ), + 3 => + array ( + 'platform' => 'mqpay', + 'name' => '码钱', + 'class_name' => 'MaQian', + 'price' => '99.00', + 'describe' => '码钱商管平台', + 'website' => 'https://m.hkrt.cn/', + 'state' => 0, + 'query' => 'a:12:{s:12:"terminalType";s:0:"";s:7:"payType";s:0:"";s:7:"payMode";s:0:"";s:11:"tradeStatus";s:1:"1";s:7:"tradeNo";s:0:"";s:7:"storeId";s:0:"";s:4:"page";i:1;s:4:"rows";i:10;s:7:"endDate";N;s:7:"endTime";N;s:9:"startDate";N;s:9:"startTime";N;}', + ), + 4 => + array ( + 'platform' => 'lklpay', + 'name' => '拉卡拉', + 'class_name' => 'LaKaLa', + 'price' => '99.00', + 'describe' => '数字支付,更安全,更高效', + 'website' => 'https://customer.lakala.com/', + 'state' => 0, + 'query' => '', + ), + 5 => + array ( + 'platform' => 'sftpay', + 'name' => '盛付通', + 'class_name' => 'ShengPay', + 'price' => '99.00', + 'describe' => '轻松生活 放心支付', + 'website' => 'https://b.shengpay.com/', + 'state' => 0, + 'query' => '', + ), + 6 => + array ( + 'platform' => 'haopay', + 'name' => '好支付', + 'class_name' => 'Haopay', + 'price' => 99, + 'describe' => '好支付', + 'website' => 'https://store.zhihuijingyingba.com/', + 'state' => 0, + 'query' => + array ( + ), + ), +); diff --git a/config/extendconfig/platform.php b/config/extendconfig/platform.php deleted file mode 100644 index 096c668..0000000 --- a/config/extendconfig/platform.php +++ /dev/null @@ -1,13 +0,0 @@ - '收钱吧', - 'storepay' => '数字门店', - 'ysepay' => '小Y经营', - 'mqpay' => '码钱', - 'lklpay' => '拉卡拉', - 'sftpay' => '盛付通', -); diff --git a/config/payconfig/1001_1.php b/config/payconfig/1001_1.php index b428b9d..234f50d 100644 --- a/config/payconfig/1001_1.php +++ b/config/payconfig/1001_1.php @@ -2,6 +2,7 @@ // +---------------------------------------------------------------------- // | 支付监听配置,一个文件,一个账号 // +---------------------------------------------------------------------- + return [ // 用户账号配置 'user' => [ @@ -14,7 +15,7 @@ return [ 'aid' => 1, // 收款平台 'platform' => 'sqbpay', - // 收款平台 + // 插件类名 'payclass' => 'ShouQianBa', // 账号 'account' => '14725836911', diff --git a/view/plugin/index.html b/view/plugin/index.html index 6daf71e..b66314f 100644 --- a/view/plugin/index.html +++ b/view/plugin/index.html @@ -43,7 +43,7 @@