🎨 修复合并错误的代码

This commit is contained in:
Binary Wang 2023-07-17 23:21:38 +08:00
parent f468653ac4
commit e5b0498401

View File

@ -1,6 +1,5 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -66,27 +65,13 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
@Override @Override
public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException { public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
Gson gson = new Gson();
jsonObject.addProperty("template_id_short", shortTemplateId);
jsonObject.addProperty("keyword_name_list", gson.toJson(keywordNameList));
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
final JsonObject result = GsonParser.parse(responseContent);
if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) {
return result.get("template_id").getAsString();
}
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}
@Override
public String addTemplate(String shortTemplateId, List<String> keywordNameList) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray(); JsonArray jsonArray = new JsonArray();
for(String val: keywordNameList) { keywordNameList.forEach(jsonArray::add);
jsonArray.add(val);
}
jsonObject.addProperty("template_id_short", shortTemplateId); jsonObject.addProperty("template_id_short", shortTemplateId);
jsonObject.add("keyword_name_list", jsonArray); jsonObject.add("keyword_name_list", jsonArray);
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString()); String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
final JsonObject result = GsonParser.parse(responseContent); final JsonObject result = GsonParser.parse(responseContent);
if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) { if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) {