Struct alipay_rs::Client

source ·
pub struct Client { /* private fields */ }

Implementations§

source§

impl Client

source

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: 同上

source

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: 同上

source

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

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

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,

异步请求

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

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,

没有参数的异步请求 此函数后期考虑放弃,请调用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,

同步请求

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,

文件上传 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);
source§

fn generate_url_data<'a, S, T>( &'a self, method: S, biz_content: T ) -> AlipayResult<Vec<(String, String)>>where S: Into<String> + Send + 'a, T: AlipayParams + Send + 'a,

source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Sign for Client

source§

fn sign(&self, params: &str) -> AlipayResult<String>

source§

fn verify(&self, source: &str, signature: &str) -> AlipayResult<bool>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Typeable for Twhere T: Any,

§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> DebugAny for Twhere T: Any + Debug,

§

impl<T> UnsafeAny for Twhere T: Any,