|
1 | 1 | package me.chanjar.weixin.mp.api.impl; |
2 | 2 |
|
3 | | -import com.google.gson.Gson; |
4 | 3 | import com.google.gson.JsonArray; |
5 | 4 | import com.google.gson.JsonObject; |
6 | 5 | import lombok.RequiredArgsConstructor; |
@@ -66,27 +65,13 @@ public String addTemplate(String shortTemplateId) throws WxErrorException { |
66 | 65 | @Override |
67 | 66 | public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException { |
68 | 67 | 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 | | - } |
77 | 68 |
|
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(); |
84 | 69 | JsonArray jsonArray = new JsonArray(); |
85 | | - for(String val: keywordNameList) { |
86 | | - jsonArray.add(val); |
87 | | - } |
| 70 | + keywordNameList.forEach(jsonArray::add); |
| 71 | + |
88 | 72 | jsonObject.addProperty("template_id_short", shortTemplateId); |
89 | | - jsonObject.add("keyword_name_list",jsonArray); |
| 73 | + jsonObject.add("keyword_name_list", jsonArray); |
| 74 | + |
90 | 75 | String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString()); |
91 | 76 | final JsonObject result = GsonParser.parse(responseContent); |
92 | 77 | if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) { |
|
0 commit comments