1 个不稳定版本
0.0.1 | 2023年11月11日 |
---|
#9 in #wechat
1.5MB
22K SLoC
Ruipay
lib.rs
:
此库提供:
- 便捷的主流第三方服务客户端
- 方便快捷地在 Rust 中使用相应的服务
功能
taobao
- 淘宝客户相关服务alipay
- 支付宝相关服务pdd
- 拼多多相关服务jd
- 京东相关服务wechat
- 微信相关服务
安装
将所需版本的 crate 放入您的 Cargo.toml
文件的 dependencies
部分
[dependencies]
ruipay = "0.1.0"
示例
与微信(微信开放平台、包含微信支付)
use ruipay::{WechatPayClient, SimpleStorage, TradeType, WechatPayRequestV3, Amount, Payer};
use chrono::{Local, SecondsFormat};
#[tokio::main]
async fn main() {
let c = WechatPayClient::new("appid", "secret");
let mut client =c.wxpay();
let date = Local::now().to_rfc3339_opts(SecondsFormat::Secs, false);
let result = client.unified_order_v3(TradeType::Jsapi, WechatPayRequestV3 {
appid: "appid".to_string().into(),
mch_id: "mchid".to_string(),
description: "测试商品支付".to_string(),
out_trade_no: "1602920235sdfsdfas32234234".to_string(),
time_expire: date,
attach: None,
notify_url: "https:xxx.cn/trade/notify".to_string(),
amount: Amount {
total: 1,
currency: String::from("CNY").into(),
payer_total: None,
payer_currency: None
},
payer: Payer {
openid: "oUVZc6S_uGx3bsNPUA-davo4Dt7Us".to_string()
}.into(),
detail: None,
scene_info: None,
settle_info: None
});
match result.await {
Ok(res) => {}
Err(err) => {}
}
}
与支付宝
use ruipay::{AlipayTradeWapPayRequest, AlipayClient};
#[tokio::main]
async fn main() {
let param = AlipayTradeWapPayRequest::default();
let client = AlipayClient::new("appKey", false);
match client.wap_pay("POST".into(), param).await {
Ok(res) => {}
Err(err) => {}
}
match result.await {
Ok(res) => {}
Err(err) => {}
}
}
与淘宝(淘宝客相关)
use ruipay::{TbItemDetailRequest, TaobaoClient, SimpleStorage};
#[tokio::main]
async fn main() {
let client = TaobaoClient::<SimpleStorage>::new("appkey", "secret");
let req = TbItemDetailRequest {
num_iids: Some("597649283190".to_string()),
platform: None,
ip: None
};
let result = client.get_item_detail(req);
match result.await {
Ok(res) => {
}
Err(err) => {
}
}
}
与京东(京东,目前暂时只支持联盟相关)
use ruipay::{JDClient, JdOrderRawQueryParam, SimpleStorage};
use chrono::{Local, SecondsFormat};
#[tokio::main]
async fn main() {
let client = JDClient::<SimpleStorage>::new("appkey", "secert");
let param = JdOrderRawQueryParam {
page_index: 1.into(),
page_size: 10.into(),
bill_type: 1,
start_time: "2022-08-02 21:23:00".to_string(),
end_time: "2022-08-02 21:43:00".to_string(),
child_union_id: None,
key: None,
fields: None
};
let result = client.query_raw_order(param);
match result.await {
Ok(res) => {
}
Err(err) => {
}
}
}
使用自定义请求
您可以实现此 trait 并使用自定义请求
- AlipayRequest - 用于支付宝
- JDRequest - 用于京东
- TaobaoRequest - 用于淘宝
功能
我们将逐步改进相应的 API
依赖项
~20–37MB
~732K SLoC