11
11
import me .chanjar .weixin .common .util .json .WxGsonBuilder ;
12
12
import me .chanjar .weixin .mp .api .WxMpService ;
13
13
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 .*;
18
15
import me .chanjar .weixin .open .bean .WxOpenAuthorizerAccessToken ;
19
16
import me .chanjar .weixin .open .bean .WxOpenComponentAccessToken ;
20
17
import me .chanjar .weixin .open .bean .WxOpenCreateResult ;
24
21
import me .chanjar .weixin .open .bean .result .WxOpenAuthorizerInfoResult ;
25
22
import me .chanjar .weixin .open .bean .result .WxOpenAuthorizerOptionResult ;
26
23
import me .chanjar .weixin .open .bean .result .WxOpenQueryAuthResult ;
24
+ import me .chanjar .weixin .open .bean .result .WxOpenResult ;
27
25
import me .chanjar .weixin .open .util .json .WxOpenGsonBuilder ;
28
26
import org .apache .commons .lang3 .StringUtils ;
29
27
import org .slf4j .Logger ;
@@ -40,6 +38,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
40
38
private static final JsonParser JSON_PARSER = new JsonParser ();
41
39
private static final Map <String , WxOpenMaService > WX_OPEN_MA_SERVICE_MAP = new Hashtable <>();
42
40
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 <>();
43
42
44
43
protected final Logger log = LoggerFactory .getLogger (this .getClass ());
45
44
private WxOpenService wxOpenService ;
@@ -79,6 +78,21 @@ public WxOpenMaService getWxMaServiceByAppid(String appId) {
79
78
return wxOpenMaService ;
80
79
}
81
80
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
+
82
96
public WxOpenService getWxOpenService () {
83
97
return wxOpenService ;
84
98
}
@@ -238,14 +252,22 @@ public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException {
238
252
getWxOpenConfigStorage ().setComponentVerifyTicket (wxMessage .getComponentVerifyTicket ());
239
253
return "success" ;
240
254
}
241
- //新增、跟新授权
255
+ //新增、更新授权
242
256
if (StringUtils .equalsAnyIgnoreCase (wxMessage .getInfoType (), "authorized" , "updateauthorized" )) {
243
257
WxOpenQueryAuthResult queryAuth = wxOpenService .getWxOpenComponentService ().getQueryAuth (wxMessage .getAuthorizationCode ());
244
258
if (queryAuth == null || queryAuth .getAuthorizationInfo () == null || queryAuth .getAuthorizationInfo ().getAuthorizerAppid () == null ) {
245
259
throw new NullPointerException ("getQueryAuth" );
246
260
}
247
261
return "success" ;
248
262
}
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
+ }
249
271
return "" ;
250
272
}
251
273
@@ -398,4 +420,27 @@ public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorExceptio
398
420
399
421
return WxOpenCreateResult .fromJson (json );
400
422
}
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
+ }
401
446
}
0 commit comments