mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-15 18:55:13 +08:00
#260 修复小程序发送模版消息接口的问题,并重新整理javadoc
This commit is contained in:
@@ -18,7 +18,7 @@ public interface WxMaMsgService {
|
|||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 发送客服消息
|
* 发送客服消息
|
||||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547&token=&lang=zh_CN">发送客服消息</a>
|
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/conversation.html">发送客服消息</a>
|
||||||
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
|
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
@@ -27,10 +27,9 @@ public interface WxMaMsgService {
|
|||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 发送模板消息
|
* 发送模板消息
|
||||||
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
|
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html#接口说明">发送模板消息</a>
|
||||||
|
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
|
||||||
* @return 消息Id
|
|
||||||
*/
|
*/
|
||||||
String sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
|
void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
|
||||||
}
|
}
|
||||||
|
@@ -27,14 +27,12 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
|
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
|
||||||
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
|
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
|
||||||
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||||
if (jsonObject.get("errcode").getAsInt() == 0) {
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||||
return jsonObject.get("msgid").getAsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -193,7 +193,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
T result = executor.execute(uriWithAccessToken, data);
|
T result = executor.execute(uriWithAccessToken, data);
|
||||||
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, result);
|
this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result);
|
||||||
return result;
|
return result;
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
WxError error = e.getError();
|
WxError error = e.getError();
|
||||||
@@ -212,12 +212,12 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, error);
|
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error);
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uriWithAccessToken, data, e.getMessage());
|
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user