Skip to content

Commit 23c96d9

Browse files
committed
Improve 'templateSend' method to check the response code to see if it's successful or not.
1 parent 9363a67 commit 23c96d9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorEx
507507
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
508508
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
509509
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
510-
return tmpJsonElement.getAsJsonObject().get("msgid").getAsString();
510+
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
511+
if (jsonObject.get("errcode").getAsInt() == 0)
512+
return jsonObject.get("msgid").getAsString();
513+
throw new WxErrorException(WxError.fromJson(responseContent));
511514
}
512515

513516
public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException {

0 commit comments

Comments
 (0)