diff --git a/Cargo.toml b/Cargo.toml
index a17ee6b..5573be8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "labrador"
-version = "0.1.8"
+version = "0.1.9"
authors = ["mrpan <1049058427@qq.com>"]
edition = "2018"
description = "Labrador - Mini thirdpart client for rust."
diff --git a/README.md b/README.md
index 2a395fa..329d8f1 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Labrador [![Build Status]][actions] [![Latest Version]][crates.io] [![labrador: rustc 1.13+]][Rust 1.13]
+# Labrador [![Docs][docs-image]][docs-url] [![Build Status]][actions] [![Latest Version]][crates.io] [![labrador: rustc 1.13+]][Rust 1.13]
[Build Status]: https://img.shields.io/docsrs/labrador/0.1.0?style=plastic
[actions]: https://github.com/wslongchen/labrador/actions?query=branch%3Amaster
@@ -7,7 +7,8 @@
[labrador: rustc 1.13+]: https://img.shields.io/badge/labrador-rustc__1.31%2B-lightgrey
[Rust 1.13]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
-
+[docs-image]: https://img.shields.io/badge/文档-中文-blue.svg
+[docs-url]: https://github.com/wslongchen/labrador/blob/master/README_CN.md
```Labrador - Mini client for rust ```
@@ -70,15 +71,15 @@ labrador = { version = "0.1.0", features = ["wechat", "alipay"] }
### With Wechat(微信开放平台、包含微信支付)
```rust
-use labrador::{WeChatPayClient, SimpleStorage, TradeType, WeChatPayRequestV3, Amount, Payer};
+use labrador::{WechatPayClient, SimpleStorage, TradeType, WechatPayRequestV3, Amount, Payer};
use chrono::{Local, SecondsFormat};
#[tokio::main]
async fn main() {
- let c = WeChatPayClient::new("appid", "secret", SimpleStorage::new());
+ let c = WechatPayClient::new("appid", "secret", SimpleStorage::new());
let mut client =c.wxpay();
let date = Local::now().to_rfc3339_opts(SecondsFormat::Secs, false);
- let result = client.unified_order_v3(TradeType::Jsapi, WeChatPayRequestV3 {
+ let result = client.unified_order_v3(TradeType::Jsapi, WechatPayRequestV3 {
appid: "appid".to_string().into(),
mch_id: "mchid".to_string(),
description: "测试商品支付".to_string(),
diff --git a/README_CN.md b/README_CN.md
new file mode 100644
index 0000000..6429dba
--- /dev/null
+++ b/README_CN.md
@@ -0,0 +1,233 @@
+# Labrador [![Docs][docs-image]][docs-url] [![Build Status]][actions] [![Latest Version]][crates.io] [![labrador: rustc 1.13+]][Rust 1.13]
+
+[Build Status]: https://img.shields.io/docsrs/labrador/0.1.0?style=plastic
+[actions]: https://github.com/wslongchen/labrador/actions?query=branch%3Amaster
+[Latest Version]: https://img.shields.io/crates/v/labrador?style=plastic
+[crates.io]: https://crates.io/crates/labrador
+[labrador: rustc 1.13+]: https://img.shields.io/badge/labrador-rustc__1.31%2B-lightgrey
+[Rust 1.13]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html
+[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
+[docs-image]: https://img.shields.io/badge/文档-英文-blue.svg
+[docs-url]: https://github.com/wslongchen/labrador/blob/master/README.md
+```Labrador - 一个迷你的便捷的第三方服务客户端SDK ```
+
+
+Features:
+
+* ```taobao``` - 淘宝客
+* ```alipay``` - 支付宝
+* ```pdd``` - 拼多多
+* ```jd``` - 京东
+* ```wechat``` - 微信
+
+### Supported Platform
+
+| 平台 | 是否支持 |
+|----------------------------------------------------|------|
+| Wechat:mp(微信公众号),cp(企业微信),miniapp(微信小程序),pay(微信支付) | √ |
+| Alipay(支付宝) | √ |
+| Taobao(淘宝客) | √ |
+| JD(京东联盟) | √ |
+| PDD(拼多多-多多客) | √ |
+
+
+---
+
+如下:
+
+- [An overview of Labrador](https://crates.io/crates/labrador)
+- [Examples](https://github.com/wslongchen/labrador/blob/0.1.0/example/simple.rs)
+- [API documentation](https://docs.rs/labrador/0.1.0/labrador/)
+- [Release notes](https://github.com/wslongchen/labrador/releases)
+
+## 使用
+
+
+
+Click to show Cargo.toml.
+Run this code in the playground.
+
+
+```toml
+[dependencies]
+
+# The core APIs
+labrador = { version = "0.1.0", features = ["wechat", "alipay"] }
+
+```
+
+
+
+
+## 文档
+
+## 示例
+
+### 微信开放平台、包含微信支付
+
+ ```rust
+use labrador::{WechatPayClient, SimpleStorage, TradeType, WechatPayRequestV3, Amount, Payer};
+use chrono::{Local, SecondsFormat};
+
+ #[tokio::main]
+ async fn main() {
+ let c = WechatPayClient::new("appid", "secret", SimpleStorage::new());
+ 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) => {}
+ }
+ }
+ ```
+
+### 支付宝
+
+ ```rust
+use labrador::{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) => {}
+ }
+ }
+ ```
+
+### 淘宝客相关
+
+ ```rust
+use labrador::{TbItemDetailRequest, TaobaoClient};
+
+ #[tokio::main]
+ async fn main() {
+ let client = TaobaoClient::::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) => {
+ }
+ }
+ }
+ ```
+
+
+### 京东,目前暂时只支持联盟相关
+
+ ```rust
+use labrador::{JDClient, JdOrderRawQueryParam};
+use chrono::{Local, SecondsFormat};
+
+ #[tokio::main]
+ async fn main() {
+ let client = JDClient::::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) => {
+ }
+ }
+ }
+ ```
+
+### 自定义请求
+
+You can implement this trait and then use the custom request
+
++ AlipayRequest - 支付宝
++ JDRequest - 京东
++ TaobaoRequest - 淘宝
+
+
+## 未来
+
+我们将逐步完善相应的API
+1. 首先非常欢迎和感谢对本项目发起 `Pull Request` 的热心小伙伴们。
+1. **特别提示:请务必在 `develop` 分支提交 `PR`,`release` 分支目前仅是正式版的代码,即发布正式版本后才会从 `develop` 分支进行合并。**
+1. 本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。
+1. **提交代码前,请检查代码是否已经格式化,并且保证新增加或者修改的方法都有完整的参数说明,而pub方法必须拥有相应的单元测试并通过测试。**
+
+## 开发
+
+To setup the development envrionment run `cargo run`.
+
+## 贡献者
+
+ MrPan <1049058427@qq.com>
+
+## Getting help
+
+拉布拉多是个人项目。一开始,我只是喜欢拉布拉多犬,因为我的爱好。
+我希望这个项目会变得越来越可爱。许多实用的其他函数将
+将在将来添加。我希望你能积极帮助这个项目成长并提出建议。
+我相信未来会越来越好。
+
+[#general]: https://discord.com/channels/273534239310479360/274215136414400513
+[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281
+[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
+[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
+[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
+[/r/rust]: https://www.reddit.com/r/rust
+[discourse]: https://users.rust-lang.org
+
+
+
+#### License
+
+
+Licensed under either of Apache License, Version
+2.0 or MIT license at your option.
+
+
+
+
+
+Unless you explicitly state otherwise, any contribution intentionally submitted
+for inclusion in Labrador by you, as defined in the Apache-2.0 license, shall be
+dual licensed as above, without any additional terms or conditions.
+
\ No newline at end of file
diff --git a/src/client.rs b/src/client.rs
index aa898a5..77b3c45 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -1,6 +1,6 @@
use serde::Serialize;
-use crate::{request::{LabraResponse, LabraRequest}, session::{SessionStore, SimpleStorage}, LabradorResult};
+use crate::{request::{LabraResponse, LabraRequest}, session::{SessionStore, SimpleStorage}, LabradorResult, RequestMethod, RequestType, Method};
/// API請求
#[derive(Debug, Clone)]
@@ -89,6 +89,19 @@ impl APIClient {
}
req.request().await
}
+
+ /// 发送POST请求
+ pub async fn post(&self, method: R, mut querys: Vec<(String, String)>, data: D, request_type: RequestType) -> LabradorResult {
+ let req = LabraRequest::new().url(method.get_method()).params(querys).method(Method::Post).json(data).req_type(request_type);
+ self.request(req).await
+ }
+
+ /// 发送GET请求
+ pub async fn get(&self, method: R, params: Vec<(&str, &str)>, request_type: RequestType) -> LabradorResult {
+ let querys = params.into_iter().map(|(k, v)| (k.to_string(), v.to_string())).collect::>();
+ let req = LabraRequest::::new().url(method.get_method()).params(querys).method(Method::Get).req_type(request_type);
+ self.request(req).await
+ }
}
diff --git a/src/lib.rs b/src/lib.rs
index 5eb0ab8..7f29911 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -35,15 +35,15 @@
//! ### With Wechat(微信开放平台、包含微信支付)
//!
//! ```rust
-//! use labrador::{WeChatPayClient, SimpleStorage, TradeType, WeChatPayRequestV3, Amount, Payer};
+//! use labrador::{WechatPayClient, SimpleStorage, TradeType, WechatPayRequestV3, Amount, Payer};
//! use chrono::{Local, SecondsFormat};
//!
//! #[tokio::main]
//! async fn main() {
-//! let c = WeChatPayClient::new("appid", "secret", SimpleStorage::new());
+//! let c = WechatPayClient::new("appid", "secret", SimpleStorage::new());
//! let mut client =c.wxpay();
//! let date = Local::now().to_rfc3339_opts(SecondsFormat::Secs, false);
-//! let result = client.unified_order_v3(TradeType::Jsapi, WeChatPayRequestV3 {
+//! let result = client.unified_order_v3(TradeType::Jsapi, WechatPayRequestV3 {
//! appid: "appid".to_string().into(),
//! mch_id: "mchid".to_string(),
//! description: "测试商品支付".to_string(),
@@ -198,7 +198,7 @@ pub use session::*;
pub use util::*;
pub use client::APIClient;
pub use request::*;
-pub use reqwest::multipart::Form;
+pub use reqwest::multipart::{Form, Part};
pub use bytes;
pub use serde_urlencoded;
diff --git a/src/session.rs b/src/session.rs
index 18830aa..8dd0d8a 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -51,9 +51,9 @@ impl ToRedisArgs for Store {
fn write_redis_args(&self, out: &mut W)
where
W: ?Sized + redis::RedisWrite {
- // let encoded: Vec = bincode::serialize(&self).unwrap();
- let encoded = serde_json::to_string(&self).unwrap_or_default();
- out.write_arg(encoded.as_bytes())
+ let encoded: Vec = bincode::serialize(&self).unwrap();
+ // let encoded = serde_json::to_string(&self).unwrap_or_default();
+ out.write_arg(&encoded[..])
}
}
@@ -61,14 +61,8 @@ impl FromRedisValue for Store {
fn from_redis_value(v: &redis::Value) -> redis::RedisResult {
match *v {
redis::Value::Data(ref bytes) => {
- let data = String::from_utf8(bytes.to_vec()).unwrap_or_default();
- match serde_json::from_str::(&data) {
- Ok(decoded) => Ok(decoded),
- Err(_err) => {
- // 出错了则直接返回该字符串
- Ok(Store::String(data))
- }
- }
+ let data = bincode::deserialize::(bytes).unwrap_or(Store::Null);
+ Ok(data)
},
redis::Value::Okay => Ok(Store::Null),
_ => Err(redis::RedisError::from((
@@ -450,7 +444,7 @@ pub mod redis_store {
- fn del>(&self, key: K) -> LabradorResult<()> {
+ pub fn del>(&self, key: K) -> LabradorResult<()> {
let mut client = self.client_pool.get()?;
if !client.check_connection() {
return Err(LabraError::ApiError("error to get redis connection".to_string()))
@@ -459,7 +453,7 @@ pub mod redis_store {
Ok(())
}
- fn zlcount, T: ToRedisArgs>(&self, key: K, min: T, max: T) -> LabradorResult