Skip to content

Commit f4dc810

Browse files
committed
issue binarywang#51 发送模板消息需要返回 获得的messageid
1 parent 24b1e9b commit f4dc810

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ public interface WxMpService {
315315
* </pre>
316316
* @param templateMessage
317317
* @throws WxErrorException
318+
* @return msgid
318319
*/
319-
public void templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
320+
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
320321

321322
/**
322323
* <pre>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ public String shortUrl(String long_url) throws WxErrorException {
286286
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
287287
}
288288

289-
public void templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
289+
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
290290
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
291-
execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
291+
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
292+
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
293+
return tmpJsonElement.getAsJsonObject().get("msgid").getAsString();
292294
}
293295

294296
public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException {

0 commit comments

Comments
 (0)