mirror of
https://gitee.com/liuxioabin/fengketrade.git
synced 2026-04-17 21:03:17 +08:00
代码优化
This commit is contained in:
parent
16e3078104
commit
198421778b
@ -445,35 +445,16 @@ class CcbPaymentService
|
|||||||
throw new \Exception('服务方公钥未配置');
|
throw new \Exception('服务方公钥未配置');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 关键修复:提取商户公钥模数的十六进制表示的后30位
|
// ✅ 关键修复:直接取商户公钥十六进制字符串的后30位
|
||||||
try {
|
try {
|
||||||
// 格式化商户公钥为PEM格式
|
// 商户公钥已经是十六进制格式,直接取后30位
|
||||||
$merchantPemKey = $this->formatPublicKeyToPem($merchantPublicKey);
|
$last30Chars = substr($merchantPublicKey, -30);
|
||||||
|
|
||||||
// 解析商户公钥,提取模数(modulus)
|
|
||||||
$keyResource = openssl_pkey_get_public($merchantPemKey);
|
|
||||||
if (!$keyResource) {
|
|
||||||
throw new \Exception('商户公钥格式错误: ' . openssl_error_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
$keyDetails = openssl_pkey_get_details($keyResource);
|
|
||||||
openssl_free_key($keyResource);
|
|
||||||
|
|
||||||
if (!isset($keyDetails['rsa']['n'])) {
|
|
||||||
throw new \Exception('无法提取商户公钥RSA模数');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将模数转换为十六进制字符串(去掉前导0x)
|
|
||||||
$modulusHex = bin2hex($keyDetails['rsa']['n']);
|
|
||||||
|
|
||||||
// 取后30位十六进制字符
|
|
||||||
$last30Chars = substr($modulusHex, -30);
|
|
||||||
|
|
||||||
if (strlen($last30Chars) < 30) {
|
if (strlen($last30Chars) < 30) {
|
||||||
throw new \Exception('商户公钥模数长度不足30位');
|
throw new \Exception('商户公钥长度不足30位');
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info('[建行支付] 商户公钥模数后30位: ' . $last30Chars);
|
Log::info('[建行支付] 商户公钥后30位: ' . $last30Chars);
|
||||||
|
|
||||||
// 使用服务方公钥加密这30位十六进制字符串
|
// 使用服务方公钥加密这30位十六进制字符串
|
||||||
// CcbRSA::encrypt 会自动进行base64编码
|
// CcbRSA::encrypt 会自动进行base64编码
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user