WxOpenServiceImpl.java
24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
package org.theyeasy.weixin.service.impl;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.theyeasy.weixin.handler.AbstractHandler;
import org.theyeasy.weixin.handler.KfSessionHandler;
import org.theyeasy.weixin.handler.LocationHandler;
import org.theyeasy.weixin.handler.LogHandler;
import org.theyeasy.weixin.handler.MenuHandler;
import org.theyeasy.weixin.handler.MsgHandler;
import org.theyeasy.weixin.handler.NullHandler;
import org.theyeasy.weixin.handler.ScanHandler;
import org.theyeasy.weixin.handler.StoreCheckNotifyHandler;
import org.theyeasy.weixin.handler.SubscribeHandler;
import org.theyeasy.weixin.handler.UnsubscribeHandler;
import org.theyeasy.weixin.model.BusinessInfo;
import org.theyeasy.weixin.model.TypeInfo;
import org.theyeasy.weixin.model.WxOpenApiGetAuthorizerInfoResult;
import org.theyeasy.weixin.model.WxOpenAuthorizationFuncResult;
import org.theyeasy.weixin.model.WxOpenConfig;
import org.theyeasy.weixin.model.WxOpenConfigStorage;
import org.theyeasy.weixin.model.WxOpenInMemoryConfigStorage;
import org.theyeasy.weixin.model.WxOpenQueryAuthResult;
import org.theyeasy.weixin.service.WxOpenService;
import org.theyeasy.weixin.util.WxTokenServiceConstant;
import redis.clients.jedis.Jedis;
import com.google.common.base.Strings;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.w1hd.zzhnc.model.SysWxauthorize;
import com.w1hd.zzhnc.service.SysWxauthorizeService;
import com.w1hd.zzhnc.util.CommonUtil;
import com.w1hd.zzhnc.util.PropertiesFileUtil;
import com.w1hd.zzhnc.util.RedisUtil;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
/**
* 微信第三方平台服务类
* @author Administrator
*
*/
@Service
public class WxOpenServiceImpl implements WxOpenService {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
private static final JsonParser JSON_PARSER = new JsonParser();
private ConcurrentMap<String, WxMpService> concurrentMapWordCounts = new ConcurrentHashMap<String, WxMpService>();
private WxOpenConfigStorage wxOpenConfigStorage;
@Autowired
private WxOpenConfig openConfig;
private CloseableHttpClient httpClient;
private HttpHost httpProxy;
@Autowired
protected LogHandler logHandler;
@Autowired
protected NullHandler nullHandler;
@Autowired
protected KfSessionHandler kfSessionHandler;
@Autowired
protected StoreCheckNotifyHandler storeCheckNotifyHandler;
@Autowired
ScanHandler scanHandler;
@Autowired
private LocationHandler locationHandler;
@Autowired
private MenuHandler menuHandler;
@Autowired
private MsgHandler msgHandler;
@Autowired
private UnsubscribeHandler unsubscribeHandler;
@Autowired
private SubscribeHandler subscribeHandler;
@Autowired
private SysWxauthorizeService sysWxauthorizeService;
private ConcurrentMap<String, WxMpMessageRouter> router = new ConcurrentHashMap<String, WxMpMessageRouter>();
@PostConstruct
public void init() {
final WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
config.setAppId(this.openConfig.getAppId());// 设置微信公众号的appid
config.setSecret(this.openConfig.getAppSecret());// 设置微信公众号的app corpSecret
config.setToken(this.openConfig.getToken());// 设置微信公众号的token
config.setAesKey(this.openConfig.getAesKey());// 设置消息加解密密钥
config.updateComponentVerifyTicket("");
config.setRedirectUri(this.openConfig.getRedirectUri());
setWxOpenConfigStorage(config);
initHttpClient();
// 中间件注册
CommonUtil.commonInsert(this.openConfig.getAppId(), "微易小程序平台_新", this.openConfig.getAppSecret(),
this.openConfig.getToken(), openConfig.getAesKey());
try {
getAccessToken(false);// 获取第三方token
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public synchronized WxMpService initWxMpService(String appId, String authorizerRefreshToken)
throws WxErrorException {
log.info("进入initWxMpService,appid=" + appId + "&refreshToken=" + authorizerRefreshToken);
if (Strings.isNullOrEmpty(appId))
throw new RuntimeException("appId不能为空");
WxMpService mpService = null;
if (concurrentMapWordCounts.containsKey(appId)) {
log.info("mpService=concurrentMapWordCounts.get(appId);");
mpService = concurrentMapWordCounts.get(appId);
} else {
mpService = new WxOpenMpServiceImpl(this.openConfig.getAppId(), appId);
concurrentMapWordCounts.put(appId, mpService);
log.info("mpService=new WxOpenMpServiceImpl");
refreshRouter(appId);
}
try {
// 执行中间件注册
CommonUtil.authorizerInsert(this.getWxOpenConfigStorage().getAppId(), appId, authorizerRefreshToken);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return mpService;
}
public synchronized WxMpService getWxMpService(String appId) throws WxErrorException {
if (Strings.isNullOrEmpty(appId))
throw new RuntimeException("appId不能为空");
WxMpService mpService = null;
if (concurrentMapWordCounts.containsKey(appId)) {
mpService = concurrentMapWordCounts.get(appId);
} else {
System.out.print("getWxMpService为空,自动调用initWxMpService");
//自动注册(Add by lcc 171028 注意:本项目只有一个公众号授权,所以可以这样。)
mpService = initWxMpService(appId,"");
if(mpService==null)
{
WxError error = new WxError();
error.setErrorCode(-100);
error.setErrorMsg("该公众号未注册");
throw new WxErrorException(error);
}
}
return mpService;
}
@Override
public String getPreAuthCode() throws WxErrorException {
return getPreAuthCode(false);
}
@Override
public String getPreAuthCode(boolean forceRefresh) throws WxErrorException {
// TODO Auto-generated method stub
try {
if (true) {
this.getWxOpenConfigStorage().expirePreAuthCode();
}
if (this.getWxOpenConfigStorage().isPreAuthCodeExpired()) {
String uri = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode";
JsonObject o = new JsonObject();
o.addProperty("component_appid", getWxOpenConfigStorage().getAppId());
String resultContent = post(uri, o.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(resultContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String preAuthCode = tmpJsonObject.get("pre_auth_code").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxOpenConfigStorage.updatePreAuthCode(preAuthCode, expiresInSeconds);
System.out.println("获取预授权码成功:" + preAuthCode);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally {
}
return this.wxOpenConfigStorage.getPreAuthCode();
}
@Override
public WxOpenQueryAuthResult getApiQueryAuth(String authorizationCode) throws WxErrorException {
// TODO Auto-generated method stub
log.info("进入getApiQueryAuth,authorizationCode=:" + authorizationCode );
String url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth";
JsonObject o = new JsonObject();
o.addProperty("component_appid", this.getWxOpenConfigStorage().getAppId());
o.addProperty("authorization_code", authorizationCode);
log.info("getWxOpenConfigStorage().getAppId()=" + this.getWxOpenConfigStorage().getAppId());
String resultContent = post(url, o.toString());
log.info("resultContent=" + resultContent);
WxOpenQueryAuthResult authResult = WxOpenQueryAuthResult.fromJson(resultContent);
// 设置授权公众号token及刷新token操作
initWxMpService(authResult.getAuthorizationInfo().getAuthorizerAppid(),
authResult.getAuthorizationInfo().getAuthorizerRefreshToken()).getWxMpConfigStorage().updateAccessToken(
authResult.getAuthorizationInfo().getAuthorizerAccessToken(),
authResult.getAuthorizationInfo().getExpiresIn());
return authResult;
}
@Override
public void setWxOpenConfigStorage(WxOpenConfigStorage openConfigStorage) {
// TODO Auto-generated method stub
this.wxOpenConfigStorage = openConfigStorage;
this.initHttpClient();
}
@Override
public WxOpenConfigStorage getWxOpenConfigStorage() {
// TODO Auto-generated method stub
return this.wxOpenConfigStorage;
}
@Override
public String getAccessToken() throws WxErrorException {
// TODO Auto-generated method stub
return getAccessToken(false);
}
@Override //这是获取的第三方平台的token,不是公众号的token(mark by lcc 171028)
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
// TODO Auto-generated method stub
String open_token_key = WxTokenServiceConstant.WX_OPEN_TOKEN_SERVICE.concat("_")
.concat(this.openConfig.getAppId());
open_token_key = RedisUtil.get3rdToken(open_token_key);
log.info("【从正式环境获取第三方平台的token】open_component_token={}", open_token_key);
return open_token_key;
}
private void initHttpClient() {
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage();
ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
.httpProxyPort(configStorage.getHttpProxyPort()).httpProxyUsername(configStorage.getHttpProxyUsername())
.httpProxyPassword(configStorage.getHttpProxyPassword());
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
}
this.httpClient = apacheHttpClientBuilder.build();
}
@Override
public String getOauth2buildAuthorizationUrl() throws WxErrorException {
String redirectUri = this.getWxOpenConfigStorage().getRedirectUri();
return getOauth2buildAuthorizationUrl(redirectUri);
}
@Override
public String getOauth2buildAuthorizationUrl(String redirectUri) throws WxErrorException {
String appid = this.getWxOpenConfigStorage().getAppId();
String code = getPreAuthCode();
if (Strings.isNullOrEmpty(redirectUri)) {// 判断是否为空
new RuntimeException("未设置回调地址");
}
StringBuffer url = new StringBuffer();
url.append("https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=");
url.append(appid);
url.append("&pre_auth_code=");
url.append(code);
url.append("&redirect_uri=");
url.append(URIUtil.encodeURIComponent(redirectUri));
return url.toString();
}
protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data)
throws WxErrorException {
if (uri.indexOf("component_access_token=") != -1) {
throw new IllegalArgumentException("uri参数中不允许有component_access_token: " + uri);
}
String accessToken = getAccessToken(false);
String uriWithAccessToken = uri;
uriWithAccessToken += uri.indexOf('?') == -1 ? "?component_access_token=" + accessToken
: "&component_access_token=" + accessToken;
try {
return executor.execute(getHttpclient(), this.httpProxy, uriWithAccessToken, data);
} catch (WxErrorException e) {
WxError error = e.getError();
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
// TODO Auto-generated method stub
try {
T result = executeInternal(executor, uri, data);
return result;
} catch (WxErrorException e) {
e.printStackTrace();
return null;
}
}
public HttpHost getHttpProxy() {
return this.httpProxy;
}
public CloseableHttpClient getHttpclient() {
return this.httpClient;
}
@Override
public String get(String url, String queryParam) throws WxErrorException {
// TODO Auto-generated method stub
return execute(new SimpleGetRequestExecutor(), url, queryParam);
}
public WxMpXmlOutMessage route(WxMpXmlMessage message, String appId) {
try {
return this.router.get(appId).route(message);
} catch (Exception e) {
this.log.error(e.getMessage(), e);
}
return null;
}
public boolean hasKefuOnline(String appId) {
try {
WxMpService mpService = concurrentMapWordCounts.get(appId);
WxMpKfOnlineList kfOnlineList = mpService.getKefuService().kfOnlineList();
return kfOnlineList != null && kfOnlineList.getKfOnlineList().size() > 0;
} catch (Exception e) {
}
return false;
}
protected MenuHandler getMenuHandler() {
return this.menuHandler;
}
protected SubscribeHandler getSubscribeHandler() {
return this.subscribeHandler;
}
protected UnsubscribeHandler getUnsubscribeHandler() {
return this.unsubscribeHandler;
}
protected AbstractHandler getLocationHandler() {
return this.locationHandler;
}
protected MsgHandler getMsgHandler() {
return this.msgHandler;
}
protected AbstractHandler getScanHandler() {
return this.scanHandler;
}
private void refreshRouter(String appId) {
log.info("进入refreshRouter");
WxMpService mpService = concurrentMapWordCounts.get(appId);
final WxMpMessageRouter newRouter = new WxMpMessageRouter(mpService);
// 记录所有事件的日志
newRouter.rule().handler(this.logHandler).next();
// 接收客服会话管理事件
/*
* newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_POI_CHECK_NOTIFY)
* .handler(this.kfSessionHandler).end();
* newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_KF_CLOSE_SESSION)
* .handler(this.kfSessionHandler).end();
* newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_KF_SWITCH_SESSION)
* .handler(this.kfSessionHandler).end();
*/
/*
* // 门店审核事件 newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT) .event(WxConsts.EVT_POI_CHECK_NOTIFY)
* .handler(this.storeCheckNotifyHandler) .end();
*/
// 自定义菜单事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.BUTTON_CLICK)
.handler(this.getMenuHandler()).end();
// 点击菜单连接事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.BUTTON_VIEW)
.handler(this.nullHandler).end();
// 关注事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SUBSCRIBE)
.handler(this.getSubscribeHandler()).end();
// 取消关注事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_UNSUBSCRIBE)
.handler(this.getUnsubscribeHandler()).end();
// 上报地理位置事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_LOCATION)
.handler(this.getLocationHandler()).end();
// 接收地理位置消息
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_LOCATION).handler(this.getLocationHandler()).end();
// 扫码事件
newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SCAN)
.handler(this.getScanHandler()).end();
// 默认
newRouter.rule().async(false).handler(this.getMsgHandler()).end();
this.router.put(appId, newRouter);
log.info("router 结束");
}
@Override
public String getApiGetAuthorizerInfo(String authorizationCode, int merchantid) throws WxErrorException {
log.info("authorizationCode=" + authorizationCode);
// TODO Auto-generated method stub
WxOpenQueryAuthResult authResult = getApiQueryAuth(authorizationCode);
log.info("getApiQueryAuth.authResult.refreshToken=" + authResult.getAuthorizationInfo().getAuthorizerRefreshToken());
String url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info";
JsonObject o = new JsonObject();
o.addProperty("component_appid", this.getWxOpenConfigStorage().getAppId());
o.addProperty("authorizer_appid", authResult.getAuthorizationInfo().getAuthorizerAppid());
log.info("api_get_authorizer_info:post之前,参数为:" + o.toString());
String resultContent = post(url, o.toString());
WxOpenApiGetAuthorizerInfoResult apiGetAuthorizerInfoResult = WxOpenApiGetAuthorizerInfoResult
.fromJson(resultContent);
String appId = authResult.getAuthorizationInfo().getAuthorizerAppid();
//因本系统只用一个公众号,并有可能被替换。所以APPID每次授权更新到redis服务器。
RedisUtil.setMpAppid(appId);
RedisUtil.setRefreshToken(authResult.getAuthorizationInfo().getAuthorizerRefreshToken());
log.info("api_get_authorizer_info:post之后,refreshToken=" + authResult.getAuthorizationInfo().getAuthorizerRefreshToken());
//Edit By lcc(171027):本项目只需要一个公众号授权,所以每次授权均覆盖已有授权。
SysWxauthorize authorizerMp = sysWxauthorizeService.getAuthorizerOnlyOne();
if (authorizerMp == null) {
authorizerMp = new SysWxauthorize();
log.info("new SysWxauthorize()");
}
authorizerMp.setWxcode(authResult.getAuthorizationInfo().getAuthorizerAppid());
authorizerMp.setWxappid(appId);
authorizerMp.setDeleted(false);
authorizerMp.setStatus(1);
authorizerMp.setRefreshtoken(authResult.getAuthorizationInfo().getAuthorizerRefreshToken());
authorizerMp.setCreatedtime(new Date());
List<WxOpenAuthorizationFuncResult> funcInfos = authResult.getAuthorizationInfo().getFuncInfo();
// 获取公众号授权给开发者的权限集列表,ID为1到15时分别代表
String ids = "";
for (int i = 0, size = funcInfos.size(); i < size; i++) {
ids += funcInfos.get(i).getFuncscopeCategory().getId() + ",";
}
authorizerMp.setFuncinfo(ids);
// 设置功能开通状态
BusinessInfo businessInfo = apiGetAuthorizerInfoResult.getAuthorizerInfo().getBusinessInfo();
String businessInfoIds = "";
if (businessInfo != null) {
if (businessInfo.getOpenCard() == null || businessInfo.getOpenCard().equals(0)) {
businessInfoIds += "open_card=0,";
} else {
businessInfoIds += "open_card=1,";
}
if (businessInfo.getOpenPay() == null || businessInfo.getOpenPay().equals(0)) {
businessInfoIds += "open_pay=0,";
} else {
businessInfoIds += "open_pay=1,";
}
if (businessInfo.getOpenScan() == null || businessInfo.getOpenScan().equals(0)) {
businessInfoIds += "open_scan=0,";
} else {
businessInfoIds += "open_scan=1,";
}
if (businessInfo.getOpenShake() == null || businessInfo.getOpenShake().equals(0)) {
businessInfoIds += "open_shake=0,";
} else {
businessInfoIds += "open_shake=1,";
}
if (businessInfo.getOpenStore() == null || businessInfo.getOpenStore().equals(0)) {
businessInfoIds += "open_store=0";
} else {
businessInfoIds += "open_store=1";
}
}
authorizerMp.setBusinessinfo(businessInfoIds);
// 设置功能开通状态
// 授权方公众号类型,0代表订阅号,1代表由历史老帐号升级后的订阅号,2代表服务号
TypeInfo serviceTypeInfo = apiGetAuthorizerInfoResult.getAuthorizerInfo().getServiceTypeInfo();
if (serviceTypeInfo != null) {
authorizerMp.setServicetypeinfo(serviceTypeInfo.getId());
}
// 授权方公众号类型,0代表订阅号,1代表由历史老帐号升级后的订阅号,2代表服务号
// 授权方认证类型
TypeInfo verifyTypeInfo = apiGetAuthorizerInfoResult.getAuthorizerInfo().getVerifyTypeInfo();
if (verifyTypeInfo != null) {
authorizerMp.setVerifytypeinfo(verifyTypeInfo.getId());
}
// 授权方认证类型
authorizerMp.setAlias(apiGetAuthorizerInfoResult.getAuthorizerInfo().getAlias());
authorizerMp.setWxname(apiGetAuthorizerInfoResult.getAuthorizerInfo().getNickName());
authorizerMp.setHeadimg(apiGetAuthorizerInfoResult.getAuthorizerInfo().getHeadImg());
authorizerMp.setQrcodeurl(apiGetAuthorizerInfoResult.getAuthorizerInfo().getQrcodeUrl());
authorizerMp.setUsername(apiGetAuthorizerInfoResult.getAuthorizerInfo().getUserName());
authorizerMp.setMerchantid(merchantid);
if (authorizerMp.getId() == null || authorizerMp.getId().equals(0)) {
log.info("insertAuthorizerMp");
sysWxauthorizeService.insertAuthorizerMp(authorizerMp);
} else {
log.info("updateAuthorizerMp");
sysWxauthorizeService.updateAuthorizerMp(authorizerMp);
}
// 执行中间件注册
CommonUtil.authorizerInsert(this.getWxOpenConfigStorage().getAppId(), appId,
authResult.getAuthorizationInfo().getAuthorizerRefreshToken());
return authResult.getAuthorizationInfo().getAuthorizerAccessToken();
}
@Override
public void setRetrySleepMillis(int retrySleepMillis) {
}
@Override
public void setMaxRetryTimes(int maxRetryTimes) {
}
@Override
public String post(String url, String postData) throws WxErrorException {
return execute(new SimplePostRequestExecutor(), url, postData);
}
}