Skip to content

Commit e5b0498

Browse files
committed
🎨 修复合并错误的代码
1 parent f468653 commit e5b0498

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import com.google.gson.Gson;
43
import com.google.gson.JsonArray;
54
import com.google.gson.JsonObject;
65
import lombok.RequiredArgsConstructor;
@@ -66,27 +65,13 @@ public String addTemplate(String shortTemplateId) throws WxErrorException {
6665
@Override
6766
public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException {
6867
JsonObject jsonObject = new JsonObject();
69-
Gson gson = new Gson();
70-
jsonObject.addProperty("template_id_short", shortTemplateId);
71-
jsonObject.addProperty("keyword_name_list", gson.toJson(keywordNameList));
72-
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
73-
final JsonObject result = GsonParser.parse(responseContent);
74-
if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) {
75-
return result.get("template_id").getAsString();
76-
}
7768

78-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
79-
}
80-
81-
@Override
82-
public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException {
83-
JsonObject jsonObject = new JsonObject();
8469
JsonArray jsonArray = new JsonArray();
85-
for(String val: keywordNameList) {
86-
jsonArray.add(val);
87-
}
70+
keywordNameList.forEach(jsonArray::add);
71+
8872
jsonObject.addProperty("template_id_short", shortTemplateId);
89-
jsonObject.add("keyword_name_list",jsonArray);
73+
jsonObject.add("keyword_name_list", jsonArray);
74+
9075
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
9176
final JsonObject result = GsonParser.parse(responseContent);
9277
if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) {

0 commit comments

Comments
 (0)