diff --git a/db/schema_split_master_account.sql b/db/schema_split_master_account.sql
index 0948f95..a7d7efb 100644
--- a/db/schema_split_master_account.sql
+++ b/db/schema_split_master_account.sql
@@ -202,10 +202,11 @@ DROP PROCEDURE IF EXISTS `sp_split_master_account_migrate`$$
DELIMITER ;
-- ============================================================================
--- 6. 后台 Web 端可视化配置项(常规管理 -> 系统配置 -> 小程序与支付配置)
+-- 6. 后台 Web 端可视化配置项(常规管理 -> 系统配置 -> 小程序配置)
+-- 注:微信支付商户号、APIv3密钥、公钥ID、证书、回调根域名及转账场景ID统一在「插件管理 -> 微信支付宝整合(epay)」配置
-- ============================================================================
UPDATE `fa_config`
-SET `value` = JSON_SET(IF(JSON_VALID(`value`), `value`, '{}'), '$.wechat', '小程序与支付配置')
+SET `value` = JSON_SET(IF(JSON_VALID(`value`), `value`, '{}'), '$.wechat', '小程序配置')
WHERE `name` = 'configgroup';
INSERT INTO `fa_config` (`name`, `group`, `title`, `tip`, `type`, `visible`, `value`, `content`, `rule`, `extend`, `setting`)
@@ -213,12 +214,7 @@ VALUES
('wechat_user_appid', 'wechat', '用户端小程序AppID', '优匠优服用户端微信小程序 AppID(用于微信登录、下单支付及师傅端跨小程序跳转)', 'string', '', 'wx40ca4b02d4d1cb58', '', '', '', NULL),
('wechat_user_secret', 'wechat', '用户端小程序Secret', '优匠优服用户端微信小程序 AppSecret(妥善保管,仅服务端登录鉴权与获取手机号使用)', 'string', '', 'f661146ce627e2c57770b7d80164dd65', '', '', '', NULL),
('wechat_master_appid', 'wechat', '师傅端小程序AppID', '优匠师傅端微信小程序 AppID(用于师傅端微信登录、提现收款确认及用户端跨小程序跳转)', 'string', '', 'wx140d90ceda786107', '', '', '', NULL),
-('wechat_master_secret', 'wechat', '师傅端小程序Secret', '优匠师傅端微信小程序 AppSecret(妥善保管,仅服务端登录鉴权与获取手机号使用)', 'string', '', '18ee42db1b8c4c2a6ce15138de5803fd', '', '', '', NULL),
-('wechat_mch_id', 'wechat', '微信支付商户号', '关联绑定用户端与师傅端小程序的微信支付商户号(mch_id)', 'string', '', '1119105317', '', '', '', NULL),
-('wechat_key_v3', 'wechat', '微信支付APIv3密钥', '微信支付 APIv3 32位密钥,用于支付与商家转账签名及回调解密', 'string', '', 'ffyqcyyszhdhi398672363efnwvikxlv', '', '', '', NULL),
-('wechat_public_key_id', 'wechat', '微信支付公钥ID', '微信支付公钥验签模式 ID(PUB_KEY_ID_...)', 'string', '', 'PUB_KEY_ID_0111191053172026102200381630000600', '', '', '', NULL),
-('wechat_notify_domain', 'wechat', '微信回调根域名', '支付、退款与商家转账 V3 异步通知 HTTPS 根域名(如 https://yjyf.gzyakj.com.cn)', 'string', '', 'https://yjyf.gzyakj.com.cn', '', '', '', NULL),
-('wechat_transfer_scene_id', 'wechat', '商家转账场景ID', '新版微信商家转账场景ID(默认 1005 佣金报酬)', 'string', '', '1005', '', '', '', NULL)
+('wechat_master_secret', 'wechat', '师傅端小程序Secret', '优匠师傅端微信小程序 AppSecret(妥善保管,仅服务端登录鉴权与获取手机号使用)', 'string', '', '18ee42db1b8c4c2a6ce15138de5803fd', '', '', '', NULL)
ON DUPLICATE KEY UPDATE
`group` = VALUES(`group`),
`title` = VALUES(`title`),
@@ -226,4 +222,6 @@ ON DUPLICATE KEY UPDATE
`type` = VALUES(`type`),
`value` = IF(TRIM(COALESCE(`value`, '')) = '', VALUES(`value`), `value`);
+DELETE FROM `fa_config` WHERE `name` IN ('wechat_mch_id', 'wechat_key_v3', 'wechat_public_key_id', 'wechat_notify_domain', 'wechat_transfer_scene_id');
+
SET FOREIGN_KEY_CHECKS = 1;
diff --git a/server/addons/epay/config.html b/server/addons/epay/config.html
index 325f89b..4aab35c 100644
--- a/server/addons/epay/config.html
+++ b/server/addons/epay/config.html
@@ -52,11 +52,22 @@
- | 小程序的app_id |
+ 用户端小程序app_id |
+ |
+
+
+ | 师傅端小程序app_id |
+
+
@@ -229,12 +240,34 @@
|
+
+ | 微信回调根域名 |
+
+
+ |
+
+
+ | 商家转账场景ID |
+
+
+ |
+
| 回调通知地址 |
diff --git a/server/addons/epay/config.php b/server/addons/epay/config.php
index 50b01bd..af2dda4 100644
--- a/server/addons/epay/config.php
+++ b/server/addons/epay/config.php
@@ -19,24 +19,27 @@ return [
'type' => 'array',
'content' => [],
'value' => [
- 'appid' => 'wx40ca4b02d4d1cb58',
- 'app_id' => 'wx40ca4b02d4d1cb58',
- 'app_secret' => 'f661146ce627e2c57770b7d80164dd65',
- 'miniapp_id' => 'wx40ca4b02d4d1cb58',
- 'mch_id' => '1119105317',
- 'key' => 'ffyqcyyszhdhi398672363efnwvikxlv',
- 'key_v3' => 'ffyqcyyszhdhi398672363efnwvikxlv',
- 'public_key_id' => 'PUB_KEY_ID_0111191053172026102200381630000600',
- 'public_key' => '/addons/epay/certs/public_key.pem',
- 'cert_client' => '/addons/epay/certs/apiclient_cert.pem',
- 'cert_key' => '/addons/epay/certs/apiclient_key.pem',
- 'mode' => 'normal',
- 'sub_mch_id' => '',
- 'sub_appid' => '',
- 'sub_app_id' => '',
- 'sub_miniapp_id' => '',
- 'notify_url' => '/addons/epay/api/notifyx/paytype/wechat',
- 'log' => '1',
+ 'appid' => 'wx40ca4b02d4d1cb58',
+ 'app_id' => 'wx40ca4b02d4d1cb58',
+ 'app_secret' => 'f661146ce627e2c57770b7d80164dd65',
+ 'miniapp_id' => 'wx40ca4b02d4d1cb58',
+ 'master_miniapp_id' => 'wx140d90ceda786107',
+ 'mch_id' => '1119105317',
+ 'key' => 'ffyqcyyszhdhi398672363efnwvikxlv',
+ 'key_v3' => 'ffyqcyyszhdhi398672363efnwvikxlv',
+ 'public_key_id' => 'PUB_KEY_ID_0111191053172026102200381630000600',
+ 'public_key' => '/addons/epay/certs/public_key.pem',
+ 'cert_client' => '/addons/epay/certs/apiclient_cert.pem',
+ 'cert_key' => '/addons/epay/certs/apiclient_key.pem',
+ 'mode' => 'normal',
+ 'sub_mch_id' => '',
+ 'sub_appid' => '',
+ 'sub_app_id' => '',
+ 'sub_miniapp_id' => '',
+ 'notify_domain' => 'https://yjyf.gzyakj.com.cn',
+ 'transfer_scene_id' => '1005',
+ 'notify_url' => '/addons/epay/api/notifyx/paytype/wechat',
+ 'log' => '1',
],
'rule' => 'required',
'msg' => '',
diff --git a/server/application/api/controller/Wxpay.php b/server/application/api/controller/Wxpay.php
index 4abecb3..ece7399 100644
--- a/server/application/api/controller/Wxpay.php
+++ b/server/application/api/controller/Wxpay.php
@@ -103,7 +103,7 @@ class Wxpay extends Api
public function transferNotify()
{
try {
- $parsed = $this->parseAndVerifyCallback();
+ $parsed = $this->parseAndVerifyCallback('master');
$data = $parsed['data'];
$outBillNo = trim((string)($data['out_bill_no'] ?? ''));
@@ -126,15 +126,16 @@ class Wxpay extends Api
/**
* 读取原始报文并使用微信支付公钥验签 + AES-256-GCM 解密
+ * @param string $side user|master
*/
- protected function parseAndVerifyCallback()
+ protected function parseAndVerifyCallback($side = 'user')
{
$rawBody = file_get_contents('php://input');
if ($rawBody === false || $rawBody === '') {
$rawBody = (string)$this->request->getInput();
}
$headers = $this->request->header();
- $wxSvc = new WxPayV3Service();
+ $wxSvc = new WxPayV3Service(['side' => $side]);
return $wxSvc->verifyAndDecryptNotify((string)$rawBody, is_array($headers) ? $headers : []);
}
diff --git a/server/application/common/library/WxLogin.php b/server/application/common/library/WxLogin.php
index 0e245bb..cac627c 100644
--- a/server/application/common/library/WxLogin.php
+++ b/server/application/common/library/WxLogin.php
@@ -38,7 +38,7 @@ class WxLogin
$secret = $cfg['secret'];
if ($appid === '' || $secret === '') {
$label = $side === 'master' ? '师傅端' : '用户端';
- return ['error' => "{$label}微信登录参数未配置完整(请在后台「常规管理 -> 系统配置 -> 小程序与支付配置」填写 AppID 与 Secret)", 'errcode' => -1001];
+ return ['error' => "{$label}微信登录参数未配置完整(请在后台「常规管理 -> 系统配置 -> 小程序配置」填写 AppID 与 Secret)", 'errcode' => -1001];
}
$code = trim((string)$code);
if ($code === '') {
diff --git a/server/application/common/library/WxPayV3Service.php b/server/application/common/library/WxPayV3Service.php
index 8d2d12a..359a462 100644
--- a/server/application/common/library/WxPayV3Service.php
+++ b/server/application/common/library/WxPayV3Service.php
@@ -50,27 +50,79 @@ class WxPayV3Service
public function __construct(array $overrideConfig = [])
{
+ $epay = $this->loadEpayWechatConfig();
$side = isset($overrideConfig['side']) && $overrideConfig['side'] === 'master' ? 'master' : 'user';
+
if (isset($overrideConfig['appid'])) {
$this->appId = trim((string)$overrideConfig['appid']);
} else {
- $miniCfg = WxLogin::getMiniAppConfig($side);
- $this->appId = $miniCfg['appid'];
+ $epayAppId = $side === 'master'
+ ? trim((string)($epay['master_miniapp_id'] ?? ''))
+ : trim((string)($epay['miniapp_id'] ?? ''));
+ if ($epayAppId !== '') {
+ $this->appId = $epayAppId;
+ } else {
+ $miniCfg = WxLogin::getMiniAppConfig($side);
+ $this->appId = $miniCfg['appid'];
+ }
}
- $this->mchId = trim((string)($overrideConfig['mch_id'] ?? Config::get('site.wechat_mch_id')));
- $this->keyV3 = trim((string)($overrideConfig['key_v3'] ?? Config::get('site.wechat_key_v3')));
- $this->publicKeyId = trim((string)($overrideConfig['public_key_id'] ?? Config::get('site.wechat_public_key_id')));
- $certRel = trim((string)($overrideConfig['cert_client'] ?? '/addons/epay/certs/apiclient_cert.pem'));
- $keyRel = trim((string)($overrideConfig['cert_key'] ?? '/addons/epay/certs/apiclient_key.pem'));
- $pubRel = trim((string)($overrideConfig['public_key'] ?? '/addons/epay/certs/public_key.pem'));
+ $this->mchId = $this->pickConfig($overrideConfig, 'mch_id', $epay, 'mch_id', 'site.wechat_mch_id');
+ $this->keyV3 = $this->pickConfig($overrideConfig, 'key_v3', $epay, 'key_v3', 'site.wechat_key_v3');
+ $this->publicKeyId = $this->pickConfig($overrideConfig, 'public_key_id', $epay, 'public_key_id', 'site.wechat_public_key_id');
+
+ $certRel = trim((string)($overrideConfig['cert_client'] ?? (!empty($epay['cert_client']) ? $epay['cert_client'] : '/addons/epay/certs/apiclient_cert.pem')));
+ $keyRel = trim((string)($overrideConfig['cert_key'] ?? (!empty($epay['cert_key']) ? $epay['cert_key'] : '/addons/epay/certs/apiclient_key.pem')));
+ $pubRel = trim((string)($overrideConfig['public_key'] ?? (!empty($epay['public_key']) ? $epay['public_key'] : '/addons/epay/certs/public_key.pem')));
$this->certClientPath = $this->resolveCertPath($certRel);
$this->certKeyPath = $this->resolveCertPath($keyRel);
$this->publicKeyPath = $this->resolveCertPath($pubRel);
- $this->notifyDomain = rtrim(trim((string)($overrideConfig['notify_domain'] ?? Config::get('site.wechat_notify_domain'))), '/');
- $this->transferSceneId = trim((string)($overrideConfig['transfer_scene_id'] ?? (Config::get('site.wechat_transfer_scene_id') ?: '1005')));
+ $this->notifyDomain = rtrim($this->pickConfig($overrideConfig, 'notify_domain', $epay, 'notify_domain', 'site.wechat_notify_domain'), '/');
+ $sceneId = $this->pickConfig($overrideConfig, 'transfer_scene_id', $epay, 'transfer_scene_id', 'site.wechat_transfer_scene_id');
+ $this->transferSceneId = $sceneId !== '' ? $sceneId : '1005';
+ }
+
+ /**
+ * 优先从 epay 插件配置读取微信支付参数
+ */
+ protected function loadEpayWechatConfig()
+ {
+ if (function_exists('get_addon_config')) {
+ $addonCfg = get_addon_config('epay');
+ if (is_array($addonCfg) && !empty($addonCfg['wechat']) && is_array($addonCfg['wechat'])) {
+ return $addonCfg['wechat'];
+ }
+ }
+ $root = defined('ROOT_PATH') ? rtrim(ROOT_PATH, '/\\') : dirname(__DIR__, 3);
+ $configFile = $root . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'epay' . DIRECTORY_SEPARATOR . 'config.php';
+ if (is_file($configFile)) {
+ $raw = include $configFile;
+ if (is_array($raw)) {
+ foreach ($raw as $item) {
+ if (is_array($item) && ($item['name'] ?? '') === 'wechat' && isset($item['value']) && is_array($item['value'])) {
+ return $item['value'];
+ }
+ }
+ }
+ }
+ return [];
+ }
+
+ /**
+ * 按「调用方覆盖 > epay插件配置 > site系统配置兜底」优先级取值
+ */
+ protected function pickConfig(array $overrideConfig, $overrideKey, array $epay, $epayKey, $siteKey)
+ {
+ if (isset($overrideConfig[$overrideKey])) {
+ return trim((string)$overrideConfig[$overrideKey]);
+ }
+ $epayVal = trim((string)($epay[$epayKey] ?? ''));
+ if ($epayVal !== '') {
+ return $epayVal;
+ }
+ return trim((string)Config::get($siteKey));
}
/**
@@ -106,7 +158,7 @@ class WxPayV3Service
$domain = trim((string)$domain);
if ($domain === '') {
throw new WxPayException(
- '微信支付公网回调域名(wechat.notify_domain)未配置,请在 server/.env 的 [wechat] 段补充正确的 HTTPS 公网域名',
+ '微信支付公网回调域名(notify_domain)未配置,请在后台「插件管理 -> 微信支付宝整合 -> 配置」补充正确的 HTTPS 公网域名',
'CONFIG_NOTIFY_DOMAIN_EMPTY'
);
}
@@ -463,7 +515,7 @@ class WxPayV3Service
public function decryptResource(array $resource)
{
if (strlen($this->keyV3) !== 32) {
- throw new WxPayException('微信 APIv3 密钥长度必须为 32 位,请检查 server/.env 的 [wechat] key_v3', 'CONFIG_KEY_V3_INVALID', 500);
+ throw new WxPayException('微信 APIv3 密钥长度必须为 32 位,请检查后台「插件管理 -> 微信支付宝整合 -> 配置」中的商户APIv3密钥', 'CONFIG_KEY_V3_INVALID', 500);
}
$ciphertextB64 = (string)($resource['ciphertext'] ?? '');
$nonce = (string)($resource['nonce'] ?? '');
@@ -788,7 +840,7 @@ class WxPayV3Service
}
if (!empty($missing)) {
throw new WxPayException(
- '微信支付配置缺失或不完整:' . implode('、', $missing) . ',请检查 server/.env 的 [wechat] 配置段',
+ '微信支付配置缺失或不完整:' . implode('、', $missing) . ',请检查后台「插件管理 -> 微信支付宝整合 -> 配置」',
'CONFIG_INCOMPLETE'
);
}
diff --git a/server/application/extra/site.php b/server/application/extra/site.php
index 067ba62..8d60d65 100755
--- a/server/application/extra/site.php
+++ b/server/application/extra/site.php
@@ -25,7 +25,7 @@ return array (
'user' => '会员配置',
'basic' => '基础配置',
'email' => '邮箱配置',
- 'wechat' => '小程序与支付配置',
+ 'wechat' => '小程序配置',
'dictionary' => '字典配置',
),
'mail_type' => '1',
@@ -67,9 +67,4 @@ return array (
'wechat_user_secret' => 'f661146ce627e2c57770b7d80164dd65',
'wechat_master_appid' => 'wx140d90ceda786107',
'wechat_master_secret' => '18ee42db1b8c4c2a6ce15138de5803fd',
- 'wechat_mch_id' => '1119105317',
- 'wechat_key_v3' => 'ffyqcyyszhdhi398672363efnwvikxlv',
- 'wechat_public_key_id' => 'PUB_KEY_ID_0111191053172026102200381630000600',
- 'wechat_notify_domain' => 'https://yjyf.gzyakj.com.cn',
- 'wechat_transfer_scene_id' => '1005',
);
|