This commit is contained in:
Billy 2025-10-27 14:40:19 +08:00
parent 80f2cdd84a
commit ec201fe0f4

View File

@ -267,27 +267,30 @@ class CcbPaymentService
$encpub = $this->encryptPublicKeyLast30();
// 7. 组装最终支付串传给建行收银台的URL参数
// ⚠️ 注意最终支付串需要对特殊字符进行URL编码
// ⚠️ 重要修复最终支付串不进行URL编码与MAC签名字符串保持一致
// 原因escape编码的字段PROINFO、REGINFO如果再URL编码会导致MAC验证失败
// 例如:%u6F2B 会被编码成 %25u6F2B与签名时的 %u6F2B 不一致
// 格式参与MAC的参数 + 不参与MAC的参数 + MAC + PLATFORMID + ENCPUB
// 7.1 构建参与MAC的参数部分需要URL编码
// 7.1 构建参与MAC的参数部分不URL编码与签名字符串保持一致
$finalParts = [];
foreach ($macParams as $key => $value) {
// 对值进行URL编码建行收银台需要
$finalParts[] = $key . '=' . urlencode($value);
// ✅ 不进行URL编码保持与MAC签名字符串一致
$finalParts[] = $key . '=' . $value;
}
// 7.2 添加不参与MAC的参数
if (!empty($nonMacParams)) {
foreach ($nonMacParams as $key => $value) {
$finalParts[] = $key . '=' . urlencode($value);
// ✅ 不URL编码
$finalParts[] = $key . '=' . $value;
}
}
// 7.3 添加MAC、PLATFORMID、ENCPUBENCPUB已经是base64需要URL编码
// 7.3 添加MAC、PLATFORMID、ENCPUB
$finalParts[] = 'MAC=' . $mac;
$finalParts[] = 'PLATFORMID=' . $this->config['service_id'];
$finalParts[] = 'ENCPUB=' . urlencode($encpub);
$finalParts[] = 'ENCPUB=' . $encpub; // ✅ ENCPUB是BASE64不需要额外编码
// 7.4 拼接最终支付串
$finalPaymentString = implode('&', $finalParts);