wx_rust_open/api/wx_open_ma_basic_service.rs
1//! 小程序基础信息服务接口。
2//!
3//! 对应 Java `me.chanjar.weixin.open.api.WxOpenMaBasicService`。
4//! 微信第三方平台 小程序基础信息接口(小程序名称、头像、描述、类目等
5//! 信息设置),文档:
6//! <https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/category/getallcategories.html>
7//!
8//! URL 常量见 [`crate::enums::url_ma_domain`](`ma_*_url`,api_host
9//! 前缀模式;`component_rebind_admin_url` 为 mp.weixin.qq.com 固定
10//! 格式化串)。
11
12use async_trait::async_trait;
13
14use wx_rust_common::error::WxErrorException;
15
16use crate::bean::WxFastMaAccountBasicInfoResult;
17use crate::bean::WxFastMaBeenSetCategoryResult;
18use crate::bean::WxFastMaCategory;
19use crate::bean::WxFastMaCheckNickameResult;
20use crate::bean::WxFastMaQueryNicknameStatusResult;
21use crate::bean::WxFastMaSetNickameResult;
22use crate::bean::WxOpenGetAllCategoriesByTypeResult;
23use crate::bean::WxOpenMaCategoryNameListResult;
24use crate::bean::WxOpenMaGetOrderPathResult;
25use crate::bean::WxOpenResult;
26
27/// 微信第三方平台 小程序基础信息服务(对应 Java `WxOpenMaBasicService`)。
28#[async_trait]
29pub trait WxOpenMaBasicService: Send + Sync {
30 /// 获取小程序的信息(对应 Java `getAccountBasicInfo()`,GET 请求)。
31 async fn get_account_basic_info(
32 &self,
33 ) -> Result<WxFastMaAccountBasicInfoResult, WxErrorException>;
34
35 /// 小程序名称设置及改名(对应 Java `setNickname(String nickname,
36 /// String idCard, String license, String namingOtherStuff1, String
37 /// namingOtherStuff2)`)。
38 ///
39 /// 若接口未返回 audit_id,说明名称已直接设置成功,无需审核;若返回
40 /// audit_id 则名称正在审核中。`id_card` 身份证照片临时素材 mediaid
41 /// (个人号必填);`license` 组织机构代码证或营业执照临时素材 mediaid
42 /// (组织号必填);`naming_other_stuff_1/2` 其他证明材料 mediaid。
43 async fn set_nickname(
44 &self,
45 nickname: &str,
46 id_card: &str,
47 license: &str,
48 naming_other_stuff1: &str,
49 naming_other_stuff2: &str,
50 ) -> Result<WxFastMaSetNickameResult, WxErrorException>;
51
52 /// 小程序改名审核状态查询(对应 Java
53 /// `querySetNicknameStatus(String auditId)`)。
54 async fn query_set_nickname_status(
55 &self,
56 audit_id: &str,
57 ) -> Result<WxFastMaQueryNicknameStatusResult, WxErrorException>;
58
59 /// 微信认证名称检测(对应 Java
60 /// `checkWxVerifyNickname(String nickname)`)。
61 async fn check_wx_verify_nickname(
62 &self,
63 nickname: &str,
64 ) -> Result<WxFastMaCheckNickameResult, WxErrorException>;
65
66 /// 修改头像(对应 Java `modifyHeadImage(String headImgMediaId, float
67 /// x1, float y1, float x2, float y2)`)。
68 ///
69 /// 图片格式只支持 BMP/JPEG/JPG/GIF/PNG,大小不超过 2M;实际头像
70 /// 始终为正方形。`x1/y1` 裁剪框左上角坐标、`x2/y2` 右下角坐标
71 /// (取值范围 [0, 1])。
72 async fn modify_head_image(
73 &self,
74 head_img_media_id: &str,
75 x1: f32,
76 y1: f32,
77 x2: f32,
78 y2: f32,
79 ) -> Result<WxOpenResult, WxErrorException>;
80
81 /// 修改功能介绍(对应 Java `modifySignature(String signature)`,
82 /// 简介 4-120 字)。
83 async fn modify_signature(&self, signature: &str) -> Result<WxOpenResult, WxErrorException>;
84
85 /// 获取换绑管理员 URL(对应 Java
86 /// `getComponentRebindAdminUrl(String redirectUri, String appId)`)。
87 ///
88 /// Java 以 `URLEncoder.encode(redirectUri, "UTF-8")`(表单编码:
89 /// 空格 → `+`)编码后按 `URL_COMPONENT_REBIND_ADMIN` 格式化
90 /// (`%s`:appid / component_appid / 编码后 redirect_uri),纯字符串
91 /// 构建不抛错(Java `@SneakyThrows` 吞掉 UnsupportedEncodingException)。
92 fn get_component_rebind_admin_url(&self, redirect_uri: &str, app_id: &str) -> String;
93
94 /// 管理员换绑(对应 Java `componentRebindAdmin(String taskId)`;
95 /// `task_id` 为公众平台最终点击提交回跳到第三方平台时携带的换绑
96 /// 管理员任务序列号)。
97 async fn component_rebind_admin(&self, task_id: &str)
98 -> Result<WxOpenResult, WxErrorException>;
99
100 /// 获取账号可以设置的所有类目(对应 Java `getAllCategories()`,
101 /// 直接返回原始字符串)。
102 ///
103 /// 因为不同类目含有特定字段,目前没有完整的类目信息数据,为保证
104 /// 兼容性,Java 放弃将 response 转换为实体。
105 async fn get_all_categories(&self) -> Result<String, WxErrorException>;
106
107 /// 获取不同类型主体可设置的类目(对应 Java
108 /// `getAllCategoriesByType(String verifyType)`)。
109 async fn get_all_categories_by_type(
110 &self,
111 verify_type: &str,
112 ) -> Result<WxOpenGetAllCategoriesByTypeResult, WxErrorException>;
113
114 /// 添加类目(对应 Java `addCategory(List<WxFastMaCategory>
115 /// categoryList)`)。
116 async fn add_category(
117 &self,
118 category_list: &[WxFastMaCategory],
119 ) -> Result<WxOpenResult, WxErrorException>;
120
121 /// 删除类目(对应 Java `deleteCategory(int first, int second)`;
122 /// `first` 一级类目 ID,`second` 二级类目 ID)。
123 async fn delete_category(
124 &self,
125 first: i32,
126 second: i32,
127 ) -> Result<WxOpenResult, WxErrorException>;
128
129 /// 获取账号已经设置的所有类目(对应 Java `getCategory()`,GET 请求)。
130 async fn get_category(&self) -> Result<WxFastMaBeenSetCategoryResult, WxErrorException>;
131
132 /// 修改类目(对应 Java `modifyCategory(WxFastMaCategory category)`)。
133 async fn modify_category(
134 &self,
135 category: &WxFastMaCategory,
136 ) -> Result<WxOpenResult, WxErrorException>;
137
138 /// 获取类目名称信息(对应 Java `getAllCategoryName()`,GET 请求;
139 /// 用于给用户展示选择)。
140 async fn get_all_category_name(
141 &self,
142 ) -> Result<WxOpenMaCategoryNameListResult, WxErrorException>;
143
144 /// 获取订单页 path 信息(对应 Java `getOrderPathInfo(int infoType)`;
145 /// `info_type`:0 线上版,1 审核版)。
146 async fn get_order_path_info(
147 &self,
148 info_type: i32,
149 ) -> Result<WxOpenMaGetOrderPathResult, WxErrorException>;
150}