时间:2021-07-01 10:21:17 帮助过:32人阅读
支付宝异步通知数据形式如下,
$arr=array (
'discount' => '0.00',
'payment_type' => '1',
'subject' => '测试02',
'trade_no' => '2016031.............2958619',
'buyer_email' => '18776152065',
'gmt_create' => '2016-03-14 17:04:52',
'notify_type' => 'trade_status_sync',
'quantity' => '1',
'out_trade_no' => '16031238100064254059',
'seller_id' => '2099122451677261',
'notify_time' => '2016-03-14 17:04:53',
'body' => '测试02',
'trade_status' => 'TRADE_SUCCESS',
'is_total_fee_adjust' => 'N',
'total_fee' => '0.01',
'gmt_payment' => '2016-03-14 17:04:52',
'seller_email' => 'xxx@126.com',
'price' => '0.01',
'buyer_id' => '2065912804441725',
'notify_id' => '2cf4b6638.............c176e3f3lk2',
'use_coupon' => 'N',
'sign_type' => 'RSA',
'sign' => 'Q3uCDyyCs/nODpHaUeCb1HqGINlQ3AxOr40MUN.............Br40MU=',
)
对数组按KEY首字母排序
ksort($arr);
按官方文档做法,排除掉sign_type
,sign
然后拼成下面形式的待签名支付串 $SemiFinishedSign
body=Hello&buyer_email=13788888888&buyer_id=2088002007013600
.................................................................................
trade_no=2014040311001004361525&trade_status=TRADE_FINISHED&use_coupon=N
执行下面代码验签!
$pukey=file_get_contents('alipay_public_key.pem');
$publickey=openssl_pkey_get_public($pukey);
$verify=(bool)openssl_verify($SemiFinishedSign, base64_decode($arr['sign']), $publickey);
echo $verify?'验签成功':'验签失败';
用于支付的公私钥都没有问题,对任意字符,
openssl_sign()
;openssl_verify()
;都能通过
但是验签总是失败,求指导!!
--------------------------更新 2016-03-15-----------------------------------------
已解决,文档中说,验签用的是支付宝公钥
,并不是RSA公钥,申请接口的人没有给我支付宝公钥,我一直以为用RSA公钥,我用错了,
支付宝异步通知数据形式如下,
$arr=array (
'discount' => '0.00',
'payment_type' => '1',
'subject' => '测试02',
'trade_no' => '2016031.............2958619',
'buyer_email' => '18776152065',
'gmt_create' => '2016-03-14 17:04:52',
'notify_type' => 'trade_status_sync',
'quantity' => '1',
'out_trade_no' => '16031238100064254059',
'seller_id' => '2099122451677261',
'notify_time' => '2016-03-14 17:04:53',
'body' => '测试02',
'trade_status' => 'TRADE_SUCCESS',
'is_total_fee_adjust' => 'N',
'total_fee' => '0.01',
'gmt_payment' => '2016-03-14 17:04:52',
'seller_email' => 'xxx@126.com',
'price' => '0.01',
'buyer_id' => '2065912804441725',
'notify_id' => '2cf4b6638.............c176e3f3lk2',
'use_coupon' => 'N',
'sign_type' => 'RSA',
'sign' => 'Q3uCDyyCs/nODpHaUeCb1HqGINlQ3AxOr40MUN.............Br40MU=',
)
对数组按KEY首字母排序
ksort($arr);
按官方文档做法,排除掉sign_type
,sign
然后拼成下面形式的待签名支付串 $SemiFinishedSign
body=Hello&buyer_email=13788888888&buyer_id=2088002007013600
.................................................................................
trade_no=2014040311001004361525&trade_status=TRADE_FINISHED&use_coupon=N
执行下面代码验签!
$pukey=file_get_contents('alipay_public_key.pem');
$publickey=openssl_pkey_get_public($pukey);
$verify=(bool)openssl_verify($SemiFinishedSign, base64_decode($arr['sign']), $publickey);
echo $verify?'验签成功':'验签失败';
用于支付的公私钥都没有问题,对任意字符,
openssl_sign()
;openssl_verify()
;都能通过
但是验签总是失败,求指导!!
--------------------------更新 2016-03-15-----------------------------------------
已解决,文档中说,验签用的是支付宝公钥
,并不是RSA公钥,申请接口的人没有给我支付宝公钥,我一直以为用RSA公钥,我用错了,
https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103927&docType=1
仔细看文档,代签名串组装方式:把所有数组值以key="value"进行组合,之后用“&”字符连接起来,不是key=value
$pukey=file_get_contents('alipay_public_key.pem');
证书这个要绝对路径
谢谢,我也遇到这样的问题,搞定了
我遇到个问题
$pukey=file_get_contents('alipay_public_key.pem');
$publickey=openssl_pkey_get_public($pukey);
到这一步的时候
打印$publickey返回false
不知道是不是公钥格式的问题
应该是哪种存法?
一、
-----BEGIN PUBLIC KEY-----
内容
-----END PUBLIC KEY-----
二、
-----BEGIN PUBLIC KEY-----内容-----END PUBLIC KEY-----
三、
内容