refactor(pay): 将微信支付配置统一收敛至epay插件管理
- epay插件配置:在config.php/config.html中增加微信支付公钥ID、APIv3密钥、回调根域名、转账场景ID等完整字段 - WxPayV3Service:读取微信支付配置时优先从epay插件读取,保留site配置兜底降级能力 - WxLogin与Wxpay:更新配置读取与错误提示说明 - site.php与SQL:系统配置聚焦维护用户端与师傅端小程序AppID与Secret,避免配置分散冲突
这个提交包含在:
@@ -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;
|
||||
|
||||
@@ -52,11 +52,22 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>小程序的app_id</td>
|
||||
<td>用户端小程序app_id</td>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<input type="text" name="row[wechat][miniapp_id]" value="{$item.value.miniapp_id|default=''|htmlentities}" class="form-control" data-rule="appid" data-tip="仅在小程序支付时使用"/>
|
||||
<input type="text" name="row[wechat][miniapp_id]" value="{$item.value.miniapp_id|default=''|htmlentities}" class="form-control" data-rule="appid" data-tip="用户端小程序下单支付时使用"/>
|
||||
</div>
|
||||
<div class="col-sm-4"></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>师傅端小程序app_id</td>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<input type="text" name="row[wechat][master_miniapp_id]" value="{$item.value.master_miniapp_id|default=''|htmlentities}" class="form-control" data-rule="appid" data-tip="师傅端小程序商家转账提现收款时使用(与用户端共用同一商户号)"/>
|
||||
</div>
|
||||
<div class="col-sm-4"></div>
|
||||
</div>
|
||||
@@ -229,12 +240,34 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>微信回调根域名</td>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<input type="text" name="row[wechat][notify_domain]" value="{$item.value.notify_domain|default=''|htmlentities}" class="form-control" data-rule="" data-tip="APIv3 支付、退款与商家转账异步通知 HTTPS 根域名(如 https://yjyf.gzyakj.com.cn)"/>
|
||||
</div>
|
||||
<div class="col-sm-4"></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>商家转账场景ID</td>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<input type="text" name="row[wechat][transfer_scene_id]" value="{$item.value.transfer_scene_id|default='1005'|htmlentities}" class="form-control" data-rule="" data-tip="新版微信商家转账场景ID(默认 1005 佣金报酬)"/>
|
||||
</div>
|
||||
<div class="col-sm-4"></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>回调通知地址</td>
|
||||
<td>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<input type="text" name="row[wechat][notify_url]" value="{$item.value.notify_url|default=''|htmlentities}" class="form-control" data-rule="" data-tip="请勿随意修改,实际以逻辑代码中请求的为准"/>
|
||||
<input type="text" name="row[wechat][notify_url]" value="{$item.value.notify_url|default=''|htmlentities}" class="form-control" data-rule="" data-tip="epay 兼容字段,请勿随意修改,实际以 V3 回调根域名拼接路径为准"/>
|
||||
</div>
|
||||
<div class="col-sm-4"></div>
|
||||
</div>
|
||||
|
||||
@@ -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' => '',
|
||||
|
||||
@@ -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 : []);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 === '') {
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
|
||||
在新工单中引用
屏蔽一个用户