Skip to content

Commit e93b4b3

Browse files
Copilotbinarywang
andcommitted
重构:添加辅助方法提高代码可维护性
Co-authored-by: binarywang <[email protected]>
1 parent 1ec2bc5 commit e93b4b3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpCustomizedServiceImpl.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.chanjar.weixin.common.error.WxErrorException;
66
import me.chanjar.weixin.cp.bean.WxCpTpCustomizedAppDetail;
77
import me.chanjar.weixin.cp.bean.WxCpTpTemplateList;
8+
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
89
import me.chanjar.weixin.cp.tp.service.WxCpTpCustomizedService;
910
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
1011

@@ -24,23 +25,40 @@ public class WxCpTpCustomizedServiceImpl implements WxCpTpCustomizedService {
2425

2526
@Override
2627
public WxCpTpTemplateList getTemplateList() throws WxErrorException {
27-
String url = this.mainService.getWxCpTpConfigStorage().getApiUrl(GET_TEMPLATE_LIST);
28-
String responseText = this.mainService.get(url + "?provider_access_token="
29-
+ this.mainService.getWxCpProviderToken(), null, true);
28+
String responseText = this.mainService.get(getWxCpTpConfigStorage().getApiUrl(GET_TEMPLATE_LIST)
29+
+ getProviderAccessToken(), null, true);
3030
return WxCpTpTemplateList.fromJson(responseText);
3131
}
3232

3333
@Override
3434
public WxCpTpCustomizedAppDetail getCustomizedAppDetail(String authCorpId, Integer agentId) throws WxErrorException {
35-
String url = this.mainService.getWxCpTpConfigStorage().getApiUrl(GET_CUSTOMIZED_APP_DETAIL);
3635
JsonObject jsonObject = new JsonObject();
3736
jsonObject.addProperty("auth_corpid", authCorpId);
3837
if (agentId != null) {
3938
jsonObject.addProperty("agentid", agentId);
4039
}
41-
String responseText = this.mainService.post(url + "?provider_access_token="
42-
+ this.mainService.getWxCpProviderToken(), jsonObject.toString(), true);
40+
String responseText = this.mainService.post(getWxCpTpConfigStorage().getApiUrl(GET_CUSTOMIZED_APP_DETAIL)
41+
+ getProviderAccessToken(), jsonObject.toString(), true);
4342
return WxCpTpCustomizedAppDetail.fromJson(responseText);
4443
}
4544

45+
/**
46+
* 获取provider_access_token参数
47+
*
48+
* @return provider_access_token参数
49+
* @throws WxErrorException 微信错误异常
50+
*/
51+
private String getProviderAccessToken() throws WxErrorException {
52+
return "?provider_access_token=" + mainService.getWxCpProviderToken();
53+
}
54+
55+
/**
56+
* 获取tp参数配置
57+
*
58+
* @return config
59+
*/
60+
private WxCpTpConfigStorage getWxCpTpConfigStorage() {
61+
return mainService.getWxCpTpConfigStorage();
62+
}
63+
4664
}

0 commit comments

Comments
 (0)