pub struct Client { /* private fields */ }
Implementations§
source§impl Client
impl Client
sourcepub fn new<S: Into<String>>(
app_id: S,
public_key: S,
private_key: S,
app_cert_sn: Option<S>,
alipay_root_cert_sn: Option<S>,
sandbox: bool
) -> Client
pub fn new<S: Into<String>>( app_id: S, public_key: S, private_key: S, app_cert_sn: Option<S>, alipay_root_cert_sn: Option<S>, sandbox: bool ) -> Client
app_id: 可在支付宝控制台 -> 我的应用 中查看 public_key: 支付宝开放平台开发助手生成的应用公钥钥文件 private_key: 支付宝开放平台开发助手生成的应用私钥 app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取 alipay_root_cert_sn: 同上
sourcepub fn neo<S: Into<String>>(
app_id: S,
public_key_path: S,
private_key_path: S,
app_cert_sn: Option<S>,
alipay_root_cert_sn: Option<S>,
sandbox: bool
) -> Client
pub fn neo<S: Into<String>>( app_id: S, public_key_path: S, private_key_path: S, app_cert_sn: Option<S>, alipay_root_cert_sn: Option<S>, sandbox: bool ) -> Client
app_id: 可在支付宝控制台 -> 我的应用 中查看 public_key_path: 支付宝开放平台开发助手生成的应用公钥钥文件 private_key_path: 支付宝开放平台开发助手生成的应用私钥文件 app_cert_sn: 在应用的 开发设置 -> 开发信息 -> 接口加签方式 中获取 alipay_root_cert_sn: 同上
sourcepub fn builder<'a>() -> ClientBuilder<'a>
pub fn builder<'a>() -> ClientBuilder<'a>
let client = alipay_rs::Client::builder()
.app_id("2021002199679230")
.public_key(include_str!("../公钥.txt"))
.private_key(include_str!("../私钥.txt"))
.app_cert_sn(include_str!("../appCertPublicKey_2021002199679230.crt"))
.alipay_root_cert_sn(include_str!("../alipayRootCert.crt"))
.finish();
sourcepub fn set_public_params<T>(&self, args: T) -> ClientWithParamswhere
T: AlipayParams,
pub fn set_public_params<T>(&self, args: T) -> ClientWithParamswhere T: AlipayParams,
设置/添加公共参数
Example:
#[derive(AlipayParams)]
struct PublicParams {
app_id: String,
charset: String,
sign_type: String,
version: String,
}
......
let public_params = PublicParams {
app_id: "20210xxxxxxxxxxx".to_owned(),
charset: "utf-8".to_owned(),
sign_type: "RSA2".to_owned(),
version: "1.0".to_owned(),
};
// 也可以通过vec, hashmap, array, tuple来设置公共参数
let public_params = ("app_id", "20210xxxxxxxxxxx");
let public_params = [("image_type", "png"), ("image_name", "test")];
let public_params = vec![("image_type", "png"), ("image_name", "test")];
let public_params = HashMap::from([("image_type", "png"), ("image_name", "test")]);
client.set_public_params(public_params);
Trait Implementations§
source§impl Cli for Client
impl Cli for Client
source§fn post<'a, S, T>(
&'a self,
method: S,
biz_content: T
) -> BoxFuture<'a, AlipayResult<Response>>where
S: Into<String> + Send + 'a,
T: AlipayParams + Send + 'a,
fn post<'a, S, T>( &'a self, method: S, biz_content: T ) -> BoxFuture<'a, AlipayResult<Response>>where S: Into<String> + Send + 'a, T: AlipayParams + Send + 'a,
异步请求
支付宝的官方接口都可以使用此函数访问
Example:
let client = alipay_rs::Client::new(
"20210xxxxxxxxxxx",
include_str!("../公钥.txt"),
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().into_json().unwrap();
// 现在除了AlipayParams宏来设置参数外,还可以通过vec, hashmap, array, tuple来存储参数
// 如果没有参数可以传“()”,比如:client.post("method", ())
let params = ("app_id", "20210xxxxxxxxxxx");
let params = [("image_type", "png"), ("image_name", "test")];
let params = vec![("image_type", "png"), ("image_name", "test")];
let params = HashMap::from([("image_type", "png"), ("image_name", "test")]);
source§fn no_param_post<'a, S>(
&'a self,
method: S
) -> BoxFuture<'a, AlipayResult<Response>>where
S: Into<String> + Send + 'a,
fn no_param_post<'a, S>( &'a self, method: S ) -> BoxFuture<'a, AlipayResult<Response>>where S: Into<String> + Send + 'a,
没有参数的异步请求 此函数后期考虑放弃,请调用post函数。 如果没有参数,可以这样调用post,post(“method”, ()) 或 post(“method”, None)
source§fn sync_post<'a, S, T>(
&'a self,
method: S,
biz_content: T
) -> AlipayResult<Response>where
S: Into<String> + Send + 'a,
T: AlipayParams + Send + 'a,
fn sync_post<'a, S, T>( &'a self, method: S, biz_content: T ) -> AlipayResult<Response>where S: Into<String> + Send + 'a, T: AlipayParams + Send + 'a,
同步请求
source§fn post_file<'a, S>(
&'a self,
method: S,
key: &'a str,
file_name: &'a str,
file_content: &'a [u8]
) -> BoxFuture<'a, AlipayResult<Response>>where
S: Into<String> + Send + 'a,
fn post_file<'a, S>( &'a self, method: S, key: &'a str, file_name: &'a str, file_content: &'a [u8] ) -> BoxFuture<'a, AlipayResult<Response>>where S: Into<String> + Send + 'a,
文件上传 method: 接口名称 key: 文件参数名 file_name: 文件名 file_content: 文件内容
#[derive(AlipayParams)]
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 client = ...;
let mut client_with_params = client.set_public_params(image);
let data:serde_json::Value = client_with_params.post_file("alipay.offline.material.image.upload", "image_content", "test.png", file.as_ref()).await.unwrap().into_json().unwrap();
println!("{:?}", data);