Skip to content

Commit cc7a83e

Browse files
committed
binarywang#260 修复小程序发送模版消息接口的问题,并重新整理javadoc
1 parent 4e6c309 commit cc7a83e

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface WxMaMsgService {
1818
/**
1919
* <pre>
2020
* 发送客服消息
21-
* 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547&token=&lang=zh_CN">发送客服消息</a>
21+
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/conversation.html">发送客服消息</a>
2222
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
2323
* </pre>
2424
*/
@@ -27,10 +27,9 @@ public interface WxMaMsgService {
2727
/**
2828
* <pre>
2929
* 发送模板消息
30-
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
30+
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html#接口说明">发送模板消息</a>
31+
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
3132
* </pre>
32-
*
33-
* @return 消息Id
3433
*/
35-
String sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
34+
void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
3635
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException {
2727
}
2828

2929
@Override
30-
public String sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
30+
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
3131
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
3232
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
33-
if (jsonObject.get("errcode").getAsInt() == 0) {
34-
return jsonObject.get("msgid").getAsString();
33+
if (jsonObject.get("errcode").getAsInt() != 0) {
34+
throw new WxErrorException(WxError.fromJson(responseContent));
3535
}
36-
37-
throw new WxErrorException(WxError.fromJson(responseContent));
3836
}
3937

4038
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, Str
193193

194194
try {
195195
T result = executor.execute(uriWithAccessToken, data);
196-
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, result);
196+
this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result);
197197
return result;
198198
} catch (WxErrorException e) {
199199
WxError error = e.getError();
@@ -212,12 +212,12 @@ public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, Str
212212
}
213213

214214
if (error.getErrorCode() != 0) {
215-
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, error);
215+
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error);
216216
throw new WxErrorException(error);
217217
}
218218
return null;
219219
} catch (IOException e) {
220-
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uriWithAccessToken, data, e.getMessage());
220+
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage());
221221
throw new RuntimeException(e);
222222
}
223223
}

0 commit comments

Comments
 (0)