rust_wechat_weapp/api/
qrcode.rs1use crate::Client;
2use rust_wechat_codegen::ServerResponse;
3use rust_wechat_core::client::ClientTrait;
4use serde::{Deserialize, Serialize};
5
6const GET_WXA_CODE_URL: &str = "https://api.weixin.qq.com/wxa/getwxacode";
7const GET_WXA_CODE_UNLIMITED_URL: &str = "https://api.weixin.qq.com/wxa/getwxacodeunlimit";
8const CREATE_WXA_QRCODE_URL: &str = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode";
9
10#[derive(Debug, Serialize, Deserialize, Default)]
11pub struct WxaCodeRequest {
12 pub path: String,
13 pub width: Option<u32>,
14 pub auto_color: Option<bool>,
15 pub line_color: Option<LineColor>,
16 pub is_hyaline: Option<bool>,
17 pub env_version: Option<EnvVersion>,
18}
19#[derive(Debug, Serialize, Deserialize, Default)]
20pub struct WxaCodeUnlimitedRequest {
21 pub scene: String,
22 pub page: Option<String>,
23 pub check_path: Option<bool>,
24 pub width: Option<u32>,
25 pub auto_color: Option<bool>,
26 pub line_color: Option<LineColor>,
27 pub is_hyaline: Option<bool>,
28 pub env_version: Option<EnvVersion>,
29}
30#[derive(Debug, Serialize, Deserialize, Default)]
31pub struct WxaQrcodeRequest {
32 pub path: String,
33 pub width: Option<u32>,
34}
35
36#[derive(Debug, Serialize, Deserialize)]
37pub struct LineColor {
38 pub r: String,
39 pub g: String,
40 pub b: String,
41}
42
43#[derive(Debug, Serialize, Deserialize)]
44#[serde(rename_all = "snake_case")]
45pub enum EnvVersion {
46 Release,
47 Trial,
48 Develop,
49}
50
51#[derive(Debug, Serialize, Deserialize, ServerResponse)]
52#[sr(flatten)]
53pub struct WxaCode {
54 pub buffer: Vec<u8>,
55}
56
57impl Client {
58 pub async fn get_wxa_code(&self, request: &WxaCodeRequest) -> crate::Result<WxaCode> {
59 let url = self.authorized_url(GET_WXA_CODE_URL).await?;
60 let response: WxaCodeResponse = self.json(url, request).await?;
61
62 Ok(response.data()?)
63 }
64 pub async fn get_wxa_code_unlimited(
65 &self,
66 request: &WxaCodeUnlimitedRequest,
67 ) -> crate::Result<WxaCode> {
68 let url = self.authorized_url(GET_WXA_CODE_UNLIMITED_URL).await?;
69 let response: WxaCodeResponse = self.json(url, request).await?;
70
71 Ok(response.data()?)
72 }
73 pub async fn create_wxa_qrcode(&self, request: &WxaQrcodeRequest) -> crate::Result<WxaCode> {
74 let url = self.authorized_url(GET_WXA_CODE_UNLIMITED_URL).await?;
75 let response: WxaCodeResponse = self.json(url, request).await?;
76
77 Ok(response.data()?)
78 }
79}