Crates.io | wx_pay |
lib.rs | wx_pay |
version | 0.2.3 |
source | src |
created_at | 2022-08-19 03:50:57.739926 |
updated_at | 2024-10-06 10:31:09.151047 |
description | 微信支付 api |
homepage | |
repository | |
max_upload_size | |
id | 648516 |
size | 49,557 |
目前版本 apiv3 jsapi
let wx_pay = WxPay {
appid: WECHAT_MINI_APP_ID,
mchid: WECHAT_PAY_MCH_ID,
private_key: WECHAT_PRIVATE_KEY,
serial_no: WECHAT_PAY_SERIAL,
apiv3_private_key: WECHAT_PAY_APIV3,
notify_url: WECHAT_PAY_NOTIFY_URL,
};
wx_pay.jsapi
wx_pay.get_transactions_by_id
wx_pay.get_transactions_by_out_trade_no
wx_pay.close
wx_pay.refund
wx_pay.get_refund
后台接口,以actix-web为例
use wx_pay::{decode_wx_pay, Amount, Jsapi, Payer, WxPayData, WxPay, WxPayNotify};
#[post("/pay/wx/v3/test")]
pub async fn pay_wx_v3_test() -> Result<impl Responder> {
let wxpay = WxPay {
appid: WECHAT_MINI_APP_ID,
mchid: WECHAT_PAY_MCH_ID,
private_key: WECHAT_PRIVATE_KEY,
serial_no: WECHAT_PAY_SERIAL,
apiv3_private_key: WECHAT_PAY_APIV3,
notify_url: WECHAT_PAY_NOTIFY_URL,
};
let data: WxPayData = wxpay
.jsapi(&Jsapi {
description: "测试122".to_string(),
out_trade_no: rand_string(16),
amount: Amount {
total: 1,
..Default::default()
},
payer: Payer { openid },
..Default::default()
})
.await
.unwrap();
return Ok(web::Json(data));
}
/// 微信支付 回调
#[post("/pay/notify_url/action")]
pub async fn pay_notify_url_action(params: web::Json<WxPayNotify>) -> Result<impl Responder> {
let params = params.0;
let data = decode_wx_pay(WECHAT_PAY_APIV3, params).unwrap();
Ok(web::Json(()))
}
公众号/小程序端:
let res = await post("/pay/wx/v3/test");
wx.requestPayment({
timeStamp: res.data.time_stamp,
nonceStr: res.data.nonce_str,
package: res.data.package,
signType: res.data.sign_type,
paySign: res.data.pay_sign,
success(res2) {
console.log("支付返回", res2);
},
});