Crates.io | alipay-f2f |
lib.rs | alipay-f2f |
version | 0.1.0 |
source | src |
created_at | 2020-12-28 08:10:17.574904 |
updated_at | 2020-12-28 08:10:17.574904 |
description | Alipay face 2 face pay support |
homepage | |
repository | https://github.com/tianenchen/alipay-f2f |
max_upload_size | |
id | 328160 |
size | 18,490 |
支付宝当面付api对接,加解密采用RSA2,忽略了部分非必选参数.可以作为对接参考. 具体参考alipay官方校验规则
调用Alipay Precreate接口并校验应答
let biz_content = BizContent::new("16089520029516", "5", "测试商品", 0.2f32);
let req = PreCreateRequest::new(
"2021002116638987",
"20201228 14:33:22",
"http://api.test.alipay.net/atinterface/receive_notify.htm",
biz_content,
);
//读取自己生成的私钥
let pk = private_key("./app_private_key_pkcs8.pem");
//生成签名
assert!(req.sign(pk).is_ok());
//生成最终的请求报文
let url = format!("https://openapi.alipaydev.com/gateway.do?{}", req);
//使用任意支持Https请求的客户端发送请求
let resp = ureq::post(&url).call();
let resp = resp
.into_json_deserialize::<PrecreateResponseWrap>()
.unwrap();
assert_eq!(resp.alipay_trade_precreate_response.msg, "Success");
let pk = public_key("./alipay_public_key.pem");
//通过Alipay提供的公钥验证PrecreateResponse的正确性
assert!(resp.varify(pk).is_ok());
收到来自Alipay的Notify请求后取出query_str后通过Alipay公钥进行校验
let req_query = "total_amount=2.00&buyer_id=2088102116773037&body=大乐透2.1&trade_no=2016071921001003030200089909&refund_fee=0.00¬ify_time=2016-07-19 14:10:49&subject=大乐透2.1&sign_type=RSA2&charset=utf-8¬ify_type=trade_status_sync&out_trade_no=0719141034-6418&gmt_close=2016-07-19 14:10:46&gmt_payment=2016-07-19 14:10:47&trade_status=TRADE_SUCCESS&version=1.0&sign=kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=&gmt_create=2016-07-19 14:10:44&app_id=2015102700040153&seller_id=2088102119685838¬ify_id=4a91b7a78a503640467525113fb7d8bg8e";
let nq = NotifyQuery::from(req_query);
let pk = public_key("./alipay_public_key.pem");
assert!(nq.varify(pk).is_ok());