diff --git a/app/controller/InstallController.php b/app/controller/InstallController.php index f5e780b..b286e25 100644 --- a/app/controller/InstallController.php +++ b/app/controller/InstallController.php @@ -149,7 +149,7 @@ EOT; `password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码', `state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '启用', `pattern` tinyint(4) NOT NULL DEFAULT '1' COMMENT '账号监听模式', - `params` text NOT NULL DEFAULT '' COMMENT '自定义查询', + `params` text NOT NULL COMMENT '自定义查询', `delete_time` timestamp NULL DEFAULT NULL COMMENT '软删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;"; diff --git a/app/controller/PayController.php b/app/controller/PayController.php index 4796bd7..8012fa6 100644 --- a/app/controller/PayController.php +++ b/app/controller/PayController.php @@ -227,6 +227,9 @@ class PayController $params = $config['params']; // 实例监听客户端 $payclient_name = $config['payclass']; + // 插件类文件是否存在 + $payclient_path = root_path() . '/extend/payclient/' . $payclient_name . '.php'; + if (!file_exists($payclient_path)) return json(['code' => 5, 'msg' => '监听客户端文件不存在']); $payclient_path = "\\payclient\\{$payclient_name}"; $Payclient = new $payclient_path($pay_config); // 获取支付明细 diff --git a/app/controller/api/PluginController.php b/app/controller/api/PluginController.php index be52126..f3edb39 100644 --- a/app/controller/api/PluginController.php +++ b/app/controller/api/PluginController.php @@ -25,42 +25,76 @@ class PluginController extends BaseController return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); } } + // 安装插件 + public function installPlugin() + { + $platform = $this->request->post('platform'); + if (!$platform) return json(backMsg(1, '请选择插件')); + $intall_info = \Plugin::installPlugin($platform); + if ($intall_info['code'] !== 0) return json(backMsg(1, $intall_info['msg'])); + // 需要授权 + if ($intall_info['data']['status'] === 0) { + return json(['code' => 0, 'msg' => '请支付', 'state' => 0, 'data' => $intall_info['data']]); + } + $saved = $this->saveNewPluginConfig($intall_info['data']); + if ($saved['code'] !== 0) return json(backMsg(1, $saved['msg'])); + return json(['code' => 0, 'msg' => '授权成功', 'state' => 1]); + } + // 更新插件 + public function updatePlugin() + { + $platform = $this->request->post('platform'); + if (!$platform) return json(backMsg(1, '请选择插件')); + $update_info = \Plugin::updatePlugin($platform); + if ($update_info['code'] !== 0) return json(backMsg(1, $update_info['msg'])); + $saved = $this->saveNewPluginConfig($update_info['data']); + if ($saved['code'] !== 0) return json(backMsg(1, $saved['msg'])); + return json(['code' => 0, 'msg' => '更新成功']); + } + // 保存全部插件信息 + private function saveNewPluginConfig(array $config = []) + { + $plugin_config = $config['config']; + $plugin_auth = $config['authcode']; + $plugin_file = $config['file']; + if (!$this->savePluginFile($plugin_file, $plugin_config)) return backMsg(1, '保存插件文件失败'); + if (!$this->saveAuthCode($plugin_auth, $plugin_config)) return backMsg(1, '保存插件授权码失败'); + if (!$this->addPlugin($plugin_config)) return backMsg(1, '保存插件配置失败'); + return backMsg(0, 'ok'); + } + // 卸载插件 public function uninstallPlugin() { $platform = $this->request->post('platform'); - $classname = $this->request->post('classname'); - if (!$platform || !$classname) { - return json(backMsg(1, '请选择插件')); - } + if (!$platform) return json(backMsg(1, '请选择插件')); + $res2 = $this->delPluginFile($platform); + if (!$res2) return json(backMsg(1, '插件文件不存在')); $res1 = $this->delPlugin($platform); - $res2 = $this->delPluginFile($classname); - if ($res1 && $res2) { - return json(backMsg(0, '卸载成功')); - } else { - return json(backMsg(1, '插件不存在')); - } + if (!$res1) return json(backMsg(1, '插件配置不存在')); + return json(backMsg(0, '卸载成功')); } - // 添加插件 + // 添加或更新插件 public function addPlugin(array $option = []) { - $keys = ['platform', 'name', 'class_name', 'price', 'describe', 'website', 'state']; + $keys = ['platform', 'name', 'class_name', 'price', 'describe', 'website', 'helplink', 'version']; $config = []; foreach ($option as $key => $value) { - if (in_array($key, $keys)) { - $config[$key] = $value; - } + if (in_array($key, $keys)) $config[$key] = $value; } + $config['state'] = 1; $plugin_config = self::getPluginConfig(); $plugin_platform = $config['platform'] ?: ''; - foreach ($plugin_config as $value) { + foreach ($plugin_config as $i => $value) { if ($plugin_platform == $value['platform']) { - return 1; //'插件已存在' + $plugin_config[$i] = $config; + $this->savePluginConfig($plugin_config, '支付插件列表'); + return true; } } $plugin_config[] = $config; $this->savePluginConfig($plugin_config, '支付插件列表'); - return 0; + return true; } // 删除插件配置 private function delPlugin(string $plugin_name = '') @@ -70,37 +104,31 @@ class PluginController extends BaseController foreach ($plugin_config as $i => $value) { if ($value['platform'] == $plugin_name) { $index = $i; + break; } } - if ($index === null) { - return false; // 插件不存在 - } + if ($index === null) return false; unset($plugin_config[$index]); $config = array_values($plugin_config); $this->savePluginConfig($config, '支付插件列表'); return true; } // 删除插件类库文件 - private function delPluginFile(string $file_name = '') + private function delPluginFile(string $platform = '') { + $file_name = self::getPluginInfo($platform)['class_name']; + if (!$file_name) return false; $plugin_path = root_path() . '/extend/payclient/' . $file_name . '.php'; - if (file_exists($plugin_path)) { - unlink($plugin_path); - return true; - } else { - return false; - } + if (!file_exists($plugin_path)) return false; + unlink($plugin_path); + return true; } // 修改插件 public function setPlugin($platform = '', $option = []) { $config = self::getPluginConfig(); - if (!$platform) { - return 1; // 请选择插件 - } - if (!$option) { - return 2; // 请添加插件配置 - } + if (!$platform) return 1; + if (!$option) return 2; foreach ($config as $index => $options) { if ($options['platform'] == $platform) { foreach ($options as $key => $value) { @@ -166,6 +194,25 @@ class PluginController extends BaseController } return $info; } + // 保存授权码 + private function saveAuthCode(string $authcode = '', array $config = []) + { + $dir_path = runtime_path() . "auth/"; + if (!is_dir($dir_path)) mkdir($dir_path, 755, true); + $auth_path = $dir_path . md5($config['platform'] . $config['class_name']) . '.json'; + return file_put_contents($auth_path, json_encode(['authcode' => $authcode])) !== false ? true : false; + } + // 保存插件类库文件 + private function savePluginFile($file_url = '', array $config = []) + { + if (empty($file_url)) return false; + $file_content = @file_get_contents($file_url); + if ($file_content === false) return false; + $save_dir = root_path() . 'extend/payclient/'; + if (!is_dir($save_dir)) mkdir($save_dir, 0755, true); + $save_path = $save_dir . $config['class_name'] . '.php'; + return file_put_contents($save_path, $file_content) !== false ? true : false; + } // 获取插件配置 private static function getPluginConfig(): array { diff --git a/config/extend/payplugin.php b/config/extend/payplugin.php index bbaaf3b..ed8cb53 100644 --- a/config/extend/payplugin.php +++ b/config/extend/payplugin.php @@ -3,4 +3,29 @@ // | 支付插件列表 // +---------------------------------------------------------------------- -return array(); +return array ( + 0 => + array ( + 'platform' => 'wxpay', + 'name' => '微信支付', + 'class_name' => 'WxPay', + 'price' => NULL, + 'describe' => '支持微信个人收款码、赞赏码、经营码、商家码收款,监听回调', + 'website' => 'https://weixin.qq.com', + 'helplink' => '', + 'version' => '1.0', + 'state' => 1, + ), + 1 => + array ( + 'platform' => 'ysepay', + 'name' => '小Y经营', + 'class_name' => 'YsePay', + 'price' => NULL, + 'describe' => '为商户和消费者提供安全、便捷、高效的支付产品与服务助力商户提升运营效率,实现数字化运营', + 'website' => 'https://xym.ysepay.com', + 'helplink' => '', + 'version' => '1.0', + 'state' => 1, + ), +); diff --git a/extend/Plugin.php b/extend/Plugin.php index d26dcbf..13fdcda 100644 --- a/extend/Plugin.php +++ b/extend/Plugin.php @@ -54,7 +54,7 @@ class Plugin { $app_plugin = cache('app_plugin'); if ($app_plugin) return $app_plugin; - $app_plugin = self::getHttpResponse(self::$siteUrl . '/mpayapi', ['action' => 'getPluginList']); + $app_plugin = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'getPluginList']); $info = json_decode($app_plugin, true); if ($info['code'] === 0) cache('app_plugin', $info['data'], 36000); return $info['data']; @@ -63,13 +63,24 @@ class Plugin public static function getNotifyMessage(): array { $message = cache('message'); - if ($message) { - return json_decode($message, true); - } - $message = self::getHttpResponse(self::$siteUrl . '/mpay/message'); + if ($message) return json_decode($message, true); + $message = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'message']); cache('message', $message, 36000); return json_decode($message, true); } + // 安装插件 + public static function installPlugin($platform): array + { + $res = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'installPlugin', 'platform' => $platform, 'host' => parse_url(request()->domain(), PHP_URL_HOST)]); + // halt($res); + return json_decode($res, true); + } + // 更新插件 + public static function updatePlugin($platform): array + { + $res = self::getHttpResponse(self::$siteUrl . '/MpayApi', ['action' => 'updatePlugin', 'platform' => $platform, 'host' => parse_url(request()->domain(), PHP_URL_HOST)]); + return json_decode($res, true); + } // 请求外部资源 private static function getHttpResponse($url, $post = null, $header = [], $timeout = 10) { diff --git a/extend/payclient.zip b/extend/payclient.zip index 7537b58..74d9221 100644 Binary files a/extend/payclient.zip and b/extend/payclient.zip differ diff --git a/view/order/index.html b/view/order/index.html index 6466abd..4c22786 100644 --- a/view/order/index.html +++ b/view/order/index.html @@ -349,7 +349,8 @@ type: 2, title: '订单详细', shade: 0.1, - area: [common.isModile() ? '100%' : '500px', common.isModile() ? '100%' : '800px'], + offset: '10px', + area: [common.isModile() ? '100%' : '500px', common.isModile() ? '100%' : '640px'], content: `/Order/showOrder?id=${id}`, }); } diff --git a/view/plugin/index.html b/view/plugin/index.html index 0f375bf..9472261 100644 --- a/view/plugin/index.html +++ b/view/plugin/index.html @@ -57,15 +57,36 @@ 立即安装 {{# } }} + +