Skip to content

Commit 014fb28

Browse files
Hipplebinarywang
authored andcommitted
#932 增加第三方平台快速创建小程序接口及相关的信息设置接口
* Add 接收API创建小程序成功的消息推送 实现快速创建小程序的新建、查询接口 增加WxOpenFastMaService(API创建的小程序专用的接口) * Add 实现小程序名称设置及改名、微信认证名称检测、修改头像、修改功能介绍接口 * Add 实现所有通过API创建的小程序专属接口及相关结果类 * Add 添加三个复杂实体的单体测试 * Update 修复WxFastMaService 8.1接口:因为不同类目含有特定字段,目前没有完整的类目信息数据,为保证兼容性,放弃将response转换为实体 * Update 将快速创建小程序接口返回值更改为WxOpenResult
1 parent cf549ea commit 014fb28

20 files changed

+1247
-12
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java

+49
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
1111
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
1212
import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
13+
import me.chanjar.weixin.open.bean.result.WxOpenResult;
1314

1415
import java.util.List;
1516

@@ -26,6 +27,7 @@ public interface WxOpenComponentService {
2627
String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option";
2728

2829
String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s";
30+
2931
/**
3032
* 手机端打开授权链接
3133
*/
@@ -45,6 +47,13 @@ public interface WxOpenComponentService {
4547

4648
String CREATE_OPEN_URL= "https://api.weixin.qq.com/cgi-bin/open/create";
4749

50+
/**
51+
* 快速创建小程序接口
52+
*/
53+
String FAST_REGISTER_WEAPP_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=create";
54+
String FAST_REGISTER_WEAPP_SEARCH_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=search";
55+
56+
4857
WxMpService getWxMpServiceByAppid(String appid);
4958

5059
/**
@@ -55,6 +64,13 @@ public interface WxOpenComponentService {
5564
*/
5665
WxOpenMaService getWxMaServiceByAppid(String appid);
5766

67+
/**
68+
* 获取指定appid的快速创建的小程序服务
69+
* @param appid
70+
* @return
71+
*/
72+
WxOpenFastMaService getWxFastMaServiceByAppid(String appid);
73+
5874
WxOpenConfigStorage getWxOpenConfigStorage();
5975

6076
boolean checkSignature(String timestamp, String nonce, String signature);
@@ -182,4 +198,37 @@ public interface WxOpenComponentService {
182198
* @return
183199
*/
184200
WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException;
201+
202+
/**
203+
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
204+
* 第三方平台快速创建小程序
205+
* <pre>
206+
* 注意:创建任务逻辑串行,单次任务结束后才可以使用相同信息下发第二次任务,请注意规避任务阻塞
207+
* </pre>
208+
* @param name 企业名(需与工商部门登记信息一致)
209+
* @param code 企业代码
210+
* @param codeType 企业代码类型 1:统一社会信用代码(18位) 2:组织机构代码(9位xxxxxxxx-x) 3:营业执照注册号(15位)
211+
* @param legalPersonaWechat 法人微信号
212+
* @param legalPersonaName 法人姓名(绑定银行卡)
213+
* @param componentPhone 第三方联系电话(方便法人与第三方联系)
214+
* @return
215+
* @throws WxErrorException
216+
*/
217+
WxOpenResult fastRegisterWeapp(String name, String code, String codeType, String legalPersonaWechat, String legalPersonaName, String componentPhone) throws WxErrorException;
218+
219+
/**
220+
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
221+
* 查询第三方平台快速创建小程序的任务状态
222+
* <pre>
223+
* 注意:该接口只提供当下任务结果查询,不建议过分依赖该接口查询所创建小程序。
224+
* 小程序的成功状态可在第三方服务器中自行对账、查询。
225+
* 不要频繁调用search接口,消息接收需通过服务器查看。调用search接口会消耗接口整体调用quato
226+
* </pre>
227+
*
228+
* @param name 企业名(需与工商部门登记信息一致)
229+
* @param legalPersonaWechat 法人微信号
230+
* @param legalPersonaName 法人姓名(绑定银行卡)
231+
* @throws WxErrorException
232+
*/
233+
WxOpenResult fastRegisterWeappSearch(String name, String legalPersonaWechat, String legalPersonaName) throws WxErrorException;
185234
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
package me.chanjar.weixin.open.api;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaService;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.open.bean.fastma.WxFastMaCategory;
6+
import me.chanjar.weixin.open.bean.result.*;
7+
8+
import java.util.List;
9+
10+
/**
11+
* <pre>
12+
* 微信开放平台【快速创建小程序】的专用接口
13+
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21528465979XX32V&token=&lang=zh_CN
14+
* 注意:该类的接口仅限通过快速创建小程序接口的小程序使用
15+
* </pre>
16+
* TODO 完善相应API的respons实体
17+
*
18+
* @author Hipple
19+
* @date 2019/01/23
20+
*/
21+
public interface WxOpenFastMaService extends WxMaService {
22+
23+
/**
24+
* 1 获取帐号基本信息
25+
*/
26+
String OPEN_GET_ACCOUNT_BASIC_INFO = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo";
27+
28+
/**
29+
* 2 小程序名称设置及改名
30+
*/
31+
String OPEN_SET_NICKNAME = "https://api.weixin.qq.com/wxa/setnickname";
32+
33+
/**
34+
* 3 小程序改名审核状态查询
35+
*/
36+
String OPEN_API_WXA_QUERYNICKNAME = "https://api.weixin.qq.com/wxa/api_wxa_querynickname";
37+
38+
/**
39+
* 4 微信认证名称检测
40+
*/
41+
String OPEN_CHECK_WX_VERIFY_NICKNAME = "https://api.weixin.qq.com/cgi-bin/wxverify/checkwxverifynickname";
42+
43+
/**
44+
* 5 修改头像
45+
*/
46+
String OPEN_MODIFY_HEADIMAGE = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage";
47+
48+
/**
49+
* 6修改功能介绍
50+
*/
51+
String OPEN_MODIFY_SIGNATURE = "https://api.weixin.qq.com/cgi-bin/account/modifysignature";
52+
53+
/**
54+
* 7 换绑小程序管理员接口
55+
*/
56+
String OPEN_COMPONENT_REBIND_ADMIN = "https://api.weixin.qq.com/cgi- bin/account/componentrebindadmin";
57+
58+
/**
59+
* 8.1 获取账号可以设置的所有类目
60+
*/
61+
String OPEN_GET_ALL_CATEGORIES = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategories";
62+
/**
63+
* 8.2 添加类目
64+
*/
65+
String OPEN_ADD_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/addcategory";
66+
/**
67+
* 8.3 删除类目
68+
*/
69+
String OPEN_DELETE_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory";
70+
/**
71+
* 8.4 获取账号已经设置的所有类目
72+
*/
73+
String OPEN_GET_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/getcategory";
74+
/**
75+
* 8.5 修改类目
76+
*/
77+
String OPEN_MODIFY_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory";
78+
79+
80+
/**
81+
* 1.获取小程序的信息
82+
*
83+
* @return
84+
* @throws WxErrorException
85+
*/
86+
WxFastMaAccountBasicInfoResult getAccountBasicInfo() throws WxErrorException;
87+
88+
/**
89+
* 2.小程序名称设置及改名
90+
* <pre>
91+
* 若接口未返回audit_id,说明名称已直接设置成功,无需审核;若返回audit_id则名称正在审核中。
92+
* </pre>
93+
* @param nickname 昵称
94+
* @param idCard 身份证照片–临时素材mediaid(个人号必填)
95+
* @param license 组织机构代码证或营业执照–临时素材mediaid(组织号必填)
96+
* @param namingOtherStuff1 其他证明材料---临时素材 mediaid
97+
* @param namingOtherStuff2 其他证明材料---临时素材 mediaid
98+
* @throws WxErrorException
99+
*/
100+
WxFastMaSetNickameResult setNickname(String nickname, String idCard, String license, String namingOtherStuff1, String namingOtherStuff2) throws WxErrorException;
101+
102+
/**
103+
* 3 小程序改名审核状态查询
104+
* @param auditId 审核单id
105+
* @return
106+
* @throws WxErrorException
107+
*/
108+
WxFastMaQueryNicknameStatusResult querySetNicknameStatus(String auditId) throws WxErrorException;
109+
110+
/**
111+
* 4. 微信认证名称检测
112+
* @param nickname 名称
113+
* @throws WxErrorException
114+
*/
115+
WxFastMaCheckNickameResult checkWxVerifyNickname(String nickname) throws WxErrorException;
116+
117+
/**
118+
* 5.修改头像
119+
* <pre>
120+
* 图片格式只支持:BMP、JPEG、JPG、GIF、PNG,大小不超过2M
121+
* 注:实际头像始终为正方形
122+
* </pre>
123+
* @param headImgMediaId 头像素材media_id
124+
* @param x1 裁剪框左上角x坐标(取值范围:[0, 1])
125+
* @param y1 裁剪框左上角y坐标(取值范围:[0, 1])
126+
* @param x2 裁剪框右下角x坐标(取值范围:[0, 1])
127+
* @param y2 裁剪框右下角y坐标(取值范围:[0, 1])
128+
* @throws WxErrorException
129+
*/
130+
WxOpenResult modifyHeadImage(String headImgMediaId, float x1, float y1, float x2, float y2) throws WxErrorException;
131+
132+
/**
133+
* 6.修改功能介绍
134+
* @param signature 简介:4-120字
135+
* @throws WxErrorException
136+
*/
137+
WxOpenResult modifySignature(String signature) throws WxErrorException;
138+
139+
/**
140+
* 7.3 管理员换绑
141+
* @param taskid 换绑管理员任务序列号(公众平台最终点击提交回跳到第三方平台时携带)
142+
* @return
143+
* @throws WxErrorException
144+
*/
145+
WxOpenResult componentRebindAdmin(String taskid) throws WxErrorException;
146+
147+
/**
148+
* 8.1 获取账号可以设置的所有类目
149+
* <pre>
150+
* 因为不同类目含有特定字段
151+
* 目前没有完整的类目信息数据
152+
* 为保证兼容性,放弃将response转换为实体
153+
* </pre>
154+
* @return
155+
*/
156+
String getAllCategories() throws WxErrorException;
157+
158+
/**
159+
*8.2添加类目
160+
* @return
161+
* @throws WxErrorException
162+
*/
163+
WxOpenResult addCategory(List<WxFastMaCategory> categoryList) throws WxErrorException;
164+
165+
/**
166+
* 8.3删除类目
167+
* @param first 一级类目ID
168+
* @param second 二级类目ID
169+
* @return
170+
* @throws WxErrorException
171+
*/
172+
WxOpenResult deleteCategory(int first, int second) throws WxErrorException;
173+
174+
/**
175+
* 8.4获取账号已经设置的所有类目
176+
* @return
177+
* @throws WxErrorException
178+
*/
179+
WxFastMaBeenSetCategoryResult getCategory() throws WxErrorException;
180+
181+
/**
182+
* 8.5修改类目
183+
* @param category 实体
184+
* @return
185+
* @throws WxErrorException
186+
*/
187+
WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException;
188+
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java

+50-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
1212
import me.chanjar.weixin.mp.api.WxMpService;
1313
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
14-
import me.chanjar.weixin.open.api.WxOpenComponentService;
15-
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
16-
import me.chanjar.weixin.open.api.WxOpenMaService;
17-
import me.chanjar.weixin.open.api.WxOpenService;
14+
import me.chanjar.weixin.open.api.*;
1815
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
1916
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
2017
import me.chanjar.weixin.open.bean.WxOpenCreateResult;
@@ -24,6 +21,7 @@
2421
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
2522
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
2623
import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
24+
import me.chanjar.weixin.open.bean.result.WxOpenResult;
2725
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
2826
import org.apache.commons.lang3.StringUtils;
2927
import org.slf4j.Logger;
@@ -40,6 +38,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
4038
private static final JsonParser JSON_PARSER = new JsonParser();
4139
private static final Map<String, WxOpenMaService> WX_OPEN_MA_SERVICE_MAP = new Hashtable<>();
4240
private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new Hashtable<>();
41+
private static final Map<String, WxOpenFastMaService> WX_OPEN_FAST_MA_SERVICE_MAP = new Hashtable<>();
4342

4443
protected final Logger log = LoggerFactory.getLogger(this.getClass());
4544
private WxOpenService wxOpenService;
@@ -79,6 +78,21 @@ public WxOpenMaService getWxMaServiceByAppid(String appId) {
7978
return wxOpenMaService;
8079
}
8180

81+
@Override
82+
public WxOpenFastMaService getWxFastMaServiceByAppid(String appId) {
83+
WxOpenFastMaService fastMaService = WX_OPEN_FAST_MA_SERVICE_MAP.get(appId);
84+
if (fastMaService == null) {
85+
synchronized (WX_OPEN_FAST_MA_SERVICE_MAP) {
86+
fastMaService = WX_OPEN_FAST_MA_SERVICE_MAP.get(appId);
87+
if (fastMaService == null) {
88+
fastMaService = new WxOpenFastMaServiceImpl(this, appId, getWxOpenConfigStorage().getWxMaConfig(appId));
89+
WX_OPEN_FAST_MA_SERVICE_MAP.put(appId, fastMaService);
90+
}
91+
}
92+
}
93+
return fastMaService;
94+
}
95+
8296
public WxOpenService getWxOpenService() {
8397
return wxOpenService;
8498
}
@@ -238,14 +252,22 @@ public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException {
238252
getWxOpenConfigStorage().setComponentVerifyTicket(wxMessage.getComponentVerifyTicket());
239253
return "success";
240254
}
241-
//新增、跟新授权
255+
//新增、更新授权
242256
if (StringUtils.equalsAnyIgnoreCase(wxMessage.getInfoType(), "authorized", "updateauthorized")) {
243257
WxOpenQueryAuthResult queryAuth = wxOpenService.getWxOpenComponentService().getQueryAuth(wxMessage.getAuthorizationCode());
244258
if (queryAuth == null || queryAuth.getAuthorizationInfo() == null || queryAuth.getAuthorizationInfo().getAuthorizerAppid() == null) {
245259
throw new NullPointerException("getQueryAuth");
246260
}
247261
return "success";
248262
}
263+
//快速创建小程序
264+
if (StringUtils.equalsIgnoreCase(wxMessage.getInfoType(), "notify_third_fasteregister") && wxMessage.getStatus () == 0) {
265+
WxOpenQueryAuthResult queryAuth = wxOpenService.getWxOpenComponentService().getQueryAuth(wxMessage.getAuthCode ());
266+
if (queryAuth == null || queryAuth.getAuthorizationInfo() == null || queryAuth.getAuthorizationInfo().getAuthorizerAppid() == null) {
267+
throw new NullPointerException("getQueryAuth");
268+
}
269+
return "success";
270+
}
249271
return "";
250272
}
251273

@@ -398,4 +420,27 @@ public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorExceptio
398420

399421
return WxOpenCreateResult.fromJson(json);
400422
}
423+
424+
@Override
425+
public WxOpenResult fastRegisterWeapp(String name, String code, String codeType, String legalPersonaWechat, String legalPersonaName, String componentPhone) throws WxErrorException{
426+
JsonObject jsonObject = new JsonObject();
427+
jsonObject.addProperty("name",name);
428+
jsonObject.addProperty("code", code);
429+
jsonObject.addProperty("code_type", codeType);
430+
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat);
431+
jsonObject.addProperty("legal_persona_name", legalPersonaName);
432+
jsonObject.addProperty("component_phone", componentPhone);
433+
String response = post(FAST_REGISTER_WEAPP_URL, jsonObject.toString (), "component_access_token");
434+
return WxOpenGsonBuilder.create ().fromJson (response, WxOpenResult.class);
435+
}
436+
437+
@Override
438+
public WxOpenResult fastRegisterWeappSearch(String name, String legalPersonaWechat, String legalPersonaName) throws WxErrorException{
439+
JsonObject jsonObject = new JsonObject();
440+
jsonObject.addProperty("name",name);
441+
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat);
442+
jsonObject.addProperty("legal_persona_name", legalPersonaName);
443+
String response = post(FAST_REGISTER_WEAPP_SEARCH_URL, jsonObject.toString (), "component_access_token");
444+
return WxOpenGsonBuilder.create ().fromJson (response, WxOpenResult.class);
445+
}
401446
}

0 commit comments

Comments
 (0)