pub struct Client { /* private fields */ }
Implementations
sourceimpl Client
impl Client
sourcepub fn new<S: Into<String>>(
app_id: S,
private_key: S,
app_cert_sn: Option<&str>,
alipay_root_cert_sn: Option<&str>
) -> Client
pub fn new<S: Into<String>>(
app_id: S,
private_key: S,
app_cert_sn: Option<&str>,
alipay_root_cert_sn: Option<&str>
) -> Client
app_id: 可在支付宝控制台 -> 我的应用 中查看
private_key: 支付宝开放平台开发助手生成的应用私钥
app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取
alipay_root_cert_sn: 同上
sourcepub fn neo<S: Into<String>>(
app_id: S,
private_key_path: &str,
app_cert_sn: Option<&str>,
alipay_root_cert_sn: Option<&str>
) -> Client
pub fn neo<S: Into<String>>(
app_id: S,
private_key_path: &str,
app_cert_sn: Option<&str>,
alipay_root_cert_sn: Option<&str>
) -> Client
app_id: 可在支付宝控制台 -> 我的应用 中查看
private_key_path: 支付宝开放平台开发助手生成的应用私钥文件
app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取
alipay_root_cert_sn: 同上
sourcepub fn set_public_params<T: AlipayParam>(&mut self, args: T)
pub fn set_public_params<T: AlipayParam>(&mut self, args: T)
设置公共参数
值为None或者参数不存在会被过滤掉
可设置的参数有 app_id,charset,sign_type,format,version,method,timestamp,sign
Example:
#[derive(AlipayParam)]
struct PublicParams {
app_id: String,
method: Option<String>,
charset: String,
sign_type: String,
sign: Option<String>,
timestamp: Option<String>,
version: String,
}
let public_params = PublicParams {
app_id: "20210xxxxxxxxxxx".to_owned(),
method: None,
charset: "utf-8".to_owned(),
sign_type: "RSA2".to_owned(),
sign: None,
timestamp: None,
version: "1.0".to_owned(),
};
client.set_public_params(public_params);
sourcepub fn add_public_params<T: AlipayParam>(&mut self, args: T)
pub fn add_public_params<T: AlipayParam>(&mut self, args: T)
添加公共参数
#[derive(AlipayParam)]
struct ImageUpload {
image_type: String,
image_name: String,
}
...
let image = ImageUpload {
image_type: "png".to_owned(),
image_name: "test".to_owned(),
};
...
client.add_public_params(image);
sourcepub async fn post<S: Into<String>, T: Serialize, R: DeserializeOwned>(
self,
method: S,
biz_content: T
) -> AlipayResult<R>
pub async fn post<S: Into<String>, T: Serialize, R: DeserializeOwned>(
self,
method: S,
biz_content: T
) -> AlipayResult<R>
异步请求
支付宝的官方接口都可以使用此函数访问
Example:
let client = alipay_rs::Client::new(
"20210xxxxxxxxxxx",
include_str!("../私钥.txt"),
Some(include_str!("../appCertPublicKey_20210xxxxxxxxxxx.crt")),
Some(include_str!("../alipayRootCert.crt"))
);
let data:serde_json::Value = client
.post("alipay.fund.trans.uni.transfer", transfer)
.await.unwrap();
sourcepub async fn no_param_post<S: Into<String>, R: DeserializeOwned>(
self,
method: S
) -> AlipayResult<R>
pub async fn no_param_post<S: Into<String>, R: DeserializeOwned>(
self,
method: S
) -> AlipayResult<R>
没有参数的异步请求
sourcepub fn sync_post<S: Into<String>, T: Serialize, R: DeserializeOwned>(
self,
method: S,
biz_content: T
) -> AlipayResult<R>
pub fn sync_post<S: Into<String>, T: Serialize, R: DeserializeOwned>(
self,
method: S,
biz_content: T
) -> AlipayResult<R>
同步请求
sourcepub async fn post_file<'a, S: Into<String>, D: DeserializeOwned>(
self,
method: S,
key: &'a str,
file_name: &'a str,
file_content: &[u8]
) -> AlipayResult<D>
pub async fn post_file<'a, S: Into<String>, D: DeserializeOwned>(
self,
method: S,
key: &'a str,
file_name: &'a str,
file_content: &[u8]
) -> AlipayResult<D>
文件上传
method: 接口名称
key: 文件参数名
file_name: 文件名
file_content: 文件内容
#[derive(AlipayParam)]
struct Image {
image_type: String,
image_name: String,
}
let file = std::fs::read("./test.png").unwrap();
let image = Image {
image_type: "png".to_owned(),
image_name: "test".to_owned(),
};
let mut client = ...;
client.add_public_params(image);
let data:serde_json::Value = client.post_file("alipay.offline.material.image.upload", "image_content", "test.png", file.as_ref()).await.unwrap();
println!("{:?}", data);
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl !Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more