支付寶異步通知數據形式以下,html
$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首字母排序segmentfault
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公鑰,我用錯了,上傳公鑰,而後複製支付寶公鑰下來用於驗證簽名。
code
轉載:https://segmentfault.com/q/1010000004607880htm
參考:blog
https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103927&docType=1排序
https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.F1IOBD&treeId=58&articleId=103596&docType=1接口
支付寶pc端支付接入PHP實現
http://www.cnblogs.com/jiqing9006/p/5846207.html