|
5 | 5 | import com.google.gson.reflect.TypeToken;
|
6 | 6 | import lombok.AllArgsConstructor;
|
7 | 7 | import lombok.extern.slf4j.Slf4j;
|
| 8 | +import me.chanjar.weixin.common.api.WxConsts; |
8 | 9 | import me.chanjar.weixin.common.error.WxError;
|
9 | 10 | import me.chanjar.weixin.common.error.WxErrorException;
|
10 | 11 | import me.chanjar.weixin.common.util.crypto.SHA1;
|
@@ -474,47 +475,71 @@ public void deleteTemplate(long templateId) throws WxErrorException {
|
474 | 475 | post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
|
475 | 476 | }
|
476 | 477 |
|
| 478 | + /** |
| 479 | + * 微信开放平台帐号管理统一请求入口 |
| 480 | + * |
| 481 | + * @param appId 操作appId 小程序/公众号 |
| 482 | + * @param appIdType 操作类型 小程序/公众号 |
| 483 | + * @param requestUrl 请求地址 |
| 484 | + * @param param 请求参数 |
| 485 | + * @return 请求结果 |
| 486 | + * @throws WxErrorException |
| 487 | + */ |
| 488 | + private String openAccountServicePost(String appId, String appIdType, String requestUrl, JsonObject param) throws WxErrorException { |
| 489 | + String result = ""; |
| 490 | + switch (appIdType) { |
| 491 | + case WxConsts.AppIdType.MP_TYPE: |
| 492 | + WxMpService wxMpService = this.getWxMpServiceByAppid(appId); |
| 493 | + result = wxMpService.post(requestUrl, param.toString()); |
| 494 | + return result; |
| 495 | + case WxConsts.AppIdType.MINI_TYPE: |
| 496 | + WxOpenMaService maService = this.getWxMaServiceByAppid(appId); |
| 497 | + result = maService.post(requestUrl, param.toString()); |
| 498 | + return result; |
| 499 | + default: |
| 500 | + throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("appIdType类型异常").build()); |
| 501 | + } |
| 502 | + } |
| 503 | + |
477 | 504 | @Override
|
478 |
| - public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException { |
| 505 | + public WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException { |
479 | 506 | JsonObject param = new JsonObject();
|
480 | 507 | param.addProperty("appid", appId);
|
481 | 508 |
|
482 |
| - String json = post(CREATE_OPEN_URL, param.toString(), "access_token"); |
| 509 | + String json = openAccountServicePost(appId, appIdType, CREATE_OPEN_URL, param); |
483 | 510 |
|
484 | 511 | return WxOpenCreateResult.fromJson(json);
|
485 | 512 | }
|
486 | 513 |
|
487 | 514 |
|
488 | 515 | @Override
|
489 |
| - public Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException { |
| 516 | + public Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException { |
490 | 517 | JsonObject param = new JsonObject();
|
491 | 518 | param.addProperty("appid", appId);
|
492 | 519 | param.addProperty("open_appid", openAppid);
|
493 | 520 |
|
494 |
| - String json = post(BIND_OPEN_URL, param.toString(), "access_token"); |
495 |
| - |
| 521 | + String json = openAccountServicePost(appId, appIdType, BIND_OPEN_URL, param); |
496 | 522 | return WxOpenResult.fromJson(json).isSuccess();
|
497 | 523 | }
|
498 | 524 |
|
499 | 525 |
|
500 | 526 | @Override
|
501 |
| - public Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException { |
| 527 | + public Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException { |
502 | 528 | JsonObject param = new JsonObject();
|
503 | 529 | param.addProperty("appid", appId);
|
504 | 530 | param.addProperty("open_appid", openAppid);
|
505 | 531 |
|
506 |
| - String json = post(UNBIND_OPEN_URL, param.toString(), "access_token"); |
507 |
| - |
| 532 | + String json = openAccountServicePost(appId, appIdType, UNBIND_OPEN_URL, param); |
508 | 533 | return WxOpenResult.fromJson(json).isSuccess();
|
509 | 534 | }
|
510 | 535 |
|
511 | 536 |
|
512 | 537 | @Override
|
513 |
| - public WxOpenGetResult getOpenAccount(String appId) throws WxErrorException { |
| 538 | + public WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException { |
514 | 539 | JsonObject param = new JsonObject();
|
515 | 540 | param.addProperty("appid", appId);
|
516 | 541 |
|
517 |
| - String json = post(GET_OPEN_URL, param.toString(), "access_token"); |
| 542 | + String json = openAccountServicePost(appId, appIdType, GET_OPEN_URL, param); |
518 | 543 | return WxOpenGetResult.fromJson(json);
|
519 | 544 | }
|
520 | 545 |
|
|
0 commit comments