代码优化

This commit is contained in:
Billy 2025-10-27 16:31:36 +08:00
parent 8af3d400d3
commit cd983a25c3
2 changed files with 31 additions and 43 deletions

View File

@ -42,37 +42,17 @@ return [
// ========== 密钥配置 (从.env读取) ==========
/**
* 商户私钥 (商户自己生成的RSA私钥)
* 用途:
* - API请求签名MD5(明文 + 私钥)
* - 解密建行返回的加密数据(ccbParamSJ等)
* - 解密建行API响应报文
* 格式: BASE64格式(不含PEM头尾) PEM格式(含头尾)
*
* ⚠️ 安全提示: 私钥必须严格保密,不得泄露!
* 服务方私钥
*/
'private_key' => $envVars['private_key'] ?? '',
/**
* 服务方公钥 (服务方自己生成的RSA公钥)
* 用途:
* - 支付下单的MD5签名计算(PLATFORMPUB字段)
* - 用于加密商户公钥生成ENCPUB
* 格式: BASE64格式(不含PEM头尾) PEM格式(含头尾)
*
* 📌 注意: 这是参与支付签名计算的服务方公钥
* 服务方公钥
*/
'public_key' => $envVars['public_key'] ?? '',
/**
* 商户公钥 (商户自己生成的RSA公钥,与上面的private_key对应)
* 用途:
* - 生成ENCPUB密文(使用服务方公钥加密商户公钥后30位)
* - 提交给建行用于验证商户签名
* 格式: BASE64格式(不含PEM头尾) PEM格式(含头尾)
*
* 📌 注意: 需要将此公钥提交给建行进行配置
* 📌 如果已上架建行生活并同步公钥可以不再上送ENCPUB
*/
'merchant_public_key' => $envVars['merchant_public_key'] ?? '',

View File

@ -164,26 +164,46 @@ class CcbPaymentService
$macParams['ACCOUNTBITMAP'] = $this->config['account_bitmap'];
}
// 积分相关
// ✅ 严格按照文档4.1表格顺序添加参数第27-40位
// 积分活动编号第27位
if (!empty($this->config['point_avy_id'])) {
$macParams['POINTAVYID'] = $this->config['point_avy_id'];
}
if (!empty($this->config['fixed_point_val'])) {
$macParams['FIXEDPOINTVAL'] = $this->config['fixed_point_val'];
}
if (!empty($this->config['min_point_limit'])) {
$macParams['MINPOINTLIMIT'] = $this->config['min_point_limit'];
// 数字人民币收款钱包编号第28位
if (!empty($this->config['dcep_dep_acc_no'])) {
$macParams['DCEPDEPACCNO'] = $this->config['dcep_dep_acc_no'];
}
// 有价券相关
// 有价券活动编号第29位
if (!empty($this->config['coupon_avy_id'])) {
$macParams['COUPONAVYID'] = $this->config['coupon_avy_id'];
}
// 限制信用卡支付标志第30位
if (!empty($this->config['only_credit_pay_flag'])) {
$macParams['ONLY_CREDIT_PAY_FLAG'] = $this->config['only_credit_pay_flag'];
}
// 数字人民币参数
// 固定抵扣积分值第31位
if (!empty($this->config['fixed_point_val'])) {
$macParams['FIXEDPOINTVAL'] = $this->config['fixed_point_val'];
}
// 最小使用积分抵扣限制第32位
if (!empty($this->config['min_point_limit'])) {
$macParams['MINPOINTLIMIT'] = $this->config['min_point_limit'];
}
// 特殊字段中石化专用第33-34位
if (!empty($this->config['identity_code'])) {
$macParams['IDENTITYCODE'] = $this->config['identity_code'];
}
if (!empty($this->config['notify_url'])) {
$macParams['NOTIFY_URL'] = $this->config['notify_url'];
}
// 数字人民币商户类型第35-38位
if (!empty($this->config['dcep_mct_type'])) {
$macParams['DCEP_MCT_TYPE'] = $this->config['dcep_mct_type'];
if ($this->config['dcep_mct_type'] == '2') {
@ -198,9 +218,6 @@ class CcbPaymentService
$macParams['DCEP_BRANCHID'] = $this->config['dcep_branch_id'];
}
}
if (!empty($this->config['dcep_dep_acc_no'])) {
$macParams['DCEPDEPACCNO'] = $this->config['dcep_dep_acc_no'];
}
}
// 二级商户参数
@ -214,21 +231,12 @@ class CcbPaymentService
$macParams['SUB_MCT_MCC'] = $this->config['sub_mct_mcc'];
}
// 扩展域
// 扩展域第43位
if (!empty($this->config['extend_params'])) {
// ⚠️ 不要在这里urlencode会在构建最终支付串时统一编码
$macParams['EXTENDPARAMS'] = $this->config['extend_params'];
}
// 特殊字段(中石化专用)
if (!empty($this->config['identity_code'])) {
$macParams['IDENTITYCODE'] = $this->config['identity_code'];
}
if (!empty($this->config['notify_url'])) {
// ⚠️ 不要在这里urlencode会在构建最终支付串时统一编码
$macParams['NOTIFY_URL'] = $this->config['notify_url'];
}
// 2. 手动构建签名字符串不能用http_build_query避免URL编码破坏escape格式
// ⚠️ 关键按照建行文档4.2示例签名字符串不进行URL编码
$signParts = [];