pub struct Client { /* private fields */ }

Implementations

app_id: 可在支付宝控制台 -> 我的应用 中查看
private_key: 支付宝开放平台开发助手生成的应用私钥
app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取
alipay_root_cert_sn: 同上

app_id: 可在支付宝控制台 -> 我的应用 中查看
private_key_path: 支付宝开放平台开发助手生成的应用私钥文件
app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取
alipay_root_cert_sn: 同上

设置公共参数

值为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);

添加公共参数

#[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);

异步请求

支付宝的官方接口都可以使用此函数访问

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();
source

pub async fn no_param_post<S: Into<String>, R: DeserializeOwned>(
    self,
    method: S
) -> AlipayResult<R>

没有参数的异步请求

source

pub fn sync_post<S: Into<String>, T: Serialize, R: DeserializeOwned>(
    self,
    method: S,
    biz_content: T
) -> AlipayResult<R>

同步请求

文件上传
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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Get the TypeId of this object.