Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「支付宝转账」证书序列号问题 #334

Closed
iiDestiny opened this issue Mar 25, 2020 · 4 comments
Closed

「支付宝转账」证书序列号问题 #334

iiDestiny opened this issue Mar 25, 2020 · 4 comments

Comments

@iiDestiny
Copy link
Contributor

iiDestiny commented Mar 25, 2020

包版本号

{
"yansongda/laravel-pay":" v2.2"
"yansongda":"v2.9.2"
"php":"7.4"
"openssl":"1.1"
}

FPM 运行环境

问题描述

支付宝开放平台开发助手申请的:RSA2、PKCS1(非 JAVA 适用) 的 csr 文件,并且已经成功上传和下载证书

image

image

无论怎么请求都是:「isv.invalid-alipay-root-cert-sn」「无效支付宝根证书序列号」,可以确保的是证书文件肯定没动,配置检查过很多遍,所以有点怀疑是生成序列号有点问题

你的代码

配置

image

实际请求代码

image

报错详情

{
    "alipay_fund_trans_uni_transfer_response": {
        "code": "40002",
        "msg": "Invalid Arguments",
        "sub_code": "isv.invalid-alipay-root-cert-sn",
        "sub_msg": "无效支付宝根证书序列号"
    },
    "alipay_cert_sn": "785f3229711cac640e81afbf6310e530",
    "sign": "A4iTP+oXl49AszUFOh5XVwV50lg/gzb+c9iGDhnpxm7c7WqdO5hY0M1LEA8m1VLPEalFr+YeKKyncK09tzhbcevlkGEMRjej3d/Md/TjLqmJexEbPqZcdUlYJG60QOpp3Pkrz6cHIOckKof9Zkoz+VXFxrVz996Cv+dtl1SQAxPQ41dHcCX5XRpTu7az54pOabIcfTQ0XaIIRU04N4WVY96ydhMWJs0fchAbhHyKzqU8EhOAFat/yFrGq4IXFd6fWyYxCLqkfPIXYjuWvXiBRct9GYO4LNrloMaZxS/1FAawRkewmrCQzorc59hXBEFi5nSOeq7xhTscSz5QHFNtBQ=="
}

sdk 日志

image

[
    "https://openapi.alipay.com/gateway.do?charset=utf-8",
    {
        "app_id": "2021001101684515",
        "format": "JSON",
        "charset": "utf-8",
        "sign_type": "RSA2",
        "version": "1.0",
        "notify_url": "https://api.zhongjieyou.com/alipay/notification",
        "timestamp": "2020-03-25 19:52:28",
        "biz_content": "{\"out_biz_no\":\"20200325195228495e7b45fc7f48b\",\"trans_amount\":1.98,\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",\"payee_info\":{\"identity\":\"17611309003\",\"identity_type\":\"ALIPAY_LOGON_ID\",\"name\":\"\\u7f57\\u5f66\"}}",
        "app_cert_sn": "8226aa55613e4f4747e1718cde444f38",
        "alipay_root_cert_sn": "687b59193f3f462dd5336e5abf83c5d8_3d2f41e001793a1519855fcf4ab70f6e",
        "method": "alipay.fund.trans.uni.transfer",
        "sign": "rL6b/BO4gvGi3jMtjQaAz2tARx16GTdsCxfoaIODdm+Yja60A45zF9KbtIhskNpne9UovGBE7jCvPQM7kwItYvl0hwatC5ZNj+rP4ZcTGUdM/N72ZAZFHzRrRKQdmqa6Tu/+s/N0dASgP9fCWImZBuCE/jUxoS5EcCO6AbMmP0r2DlZpN7Icq18BoP9TgVMwSAwWgClsRqyCxMt92FCcDw4Cp/c12HI2EPUTd95zLksLrmGDD85vyowQJWYFEEjXB4cATdHy232PCl25RifCO0YvIMcb1kiJy35vNCvStdB/v4lzcBm0l9pnk023aJLK1GOGDVLRYy/Cf+dXl/dMSA=="
    }
]
{
    "alipay_fund_trans_uni_transfer_response": {
        "code": "40002",
        "msg": "Invalid Arguments",
        "sub_code": "isv.invalid-alipay-root-cert-sn",
        "sub_msg": "无效支付宝根证书序列号"
    },
    "alipay_cert_sn": "785f3229711cac640e81afbf6310e530",
    "sign": "A4iTP+oXl49AszUFOh5XVwV50lg/gzb+c9iGDhnpxm7c7WqdO5hY0M1LEA8m1VLPEalFr+YeKKyncK09tzhbcevlkGEMRjej3d/Md/TjLqmJexEbPqZcdUlYJG60QOpp3Pkrz6cHIOckKof9Zkoz+VXFxrVz996Cv+dtl1SQAxPQ41dHcCX5XRpTu7az54pOabIcfTQ0XaIIRU04N4WVY96ydhMWJs0fchAbhHyKzqU8EhOAFat/yFrGq4IXFd6fWyYxCLqkfPIXYjuWvXiBRct9GYO4LNrloMaZxS/1FAawRkewmrCQzorc59hXBEFi5nSOeq7xhTscSz5QHFNtBQ=="
}

nginx/apache 日志

涉及到 异步通知、同步通知 的问题,请贴出来

实时请求无通知

@iiDestiny
Copy link
Contributor Author

@yansongda

已找到问题所在

https://github.com/yansongda/pay/blob/master/src/Gateways/Alipay/Support.php#L439-L450

private static function bchexdec($hex)
    {
        $dec = 0;
        $len = strlen($hex);
        for ($i = 1; $i <= $len; ++$i) {
            if (ctype_xdigit($hex[$i - 1])) {
                $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i))));
            }
        }

        return $dec;
    }

https://github.com/yansongda/pay/blob/master/src/Gateways/Alipay/Support.php#L373

根据我的根证书
PHP 7.1 得到的 serialNumber:95790491425698859646659490580052089075020051350
PHP 7.2 得到的 serialNumber:95790491425698859646659490580052089075020051350.00

由此可得出,BC 函数库 PHP7.1 之后有浮点数,处理一下浮点数就行。
解决方案:

private static function bchexdec($hex)
    {
        $dec = 0;
        $len = strlen($hex);
        for ($i = 1; $i <= $len; ++$i) {
            if (ctype_xdigit($hex[$i - 1])) {
                $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i))));
            }
        }

        return str_replace('.00', '', $dec);
    }

@gyp719
Copy link

gyp719 commented Apr 11, 2020

Yansongda \ Pay \ Exceptions \ GatewayException (4)
ERROR_GATEWAY: Get Alipay API Error:Business Failed - INVALID_PARAMETER

怎么参数错误?

@cnx7
Copy link

cnx7 commented May 25, 2020

ERROR_GATEWAY: Get Alipay API Error:Business Failed - INVALID_PARAMETER

@shaolinah
Copy link

非常棒啊,我也遇到了这个问题,完美解决,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants