use of com.github.liuweijw.commons.pay.enums.WxTemplateEnum in project fw-cloud-framework by liuweijw.
the class WxMessageController method sendWeixinTemplateMessage.
@ResponseBody
@Deprecated
@RequestMapping(value = "/send/{wechatId}")
public HttpResult sendWeixinTemplateMessage(@PathVariable("wechatId") String wechatId, @RequestParam("message") String message) {
if (StringHelper.isBlank(message))
return new HttpResult().failure("发送消息内容不能为空");
WechatInfo wechatInfo = wechatInfoService.findByWechatId(wechatId);
if (null == wechatInfo)
return new HttpResult().failure("公众号wechatId[" + wechatId + "]不存在");
log.info("公众号消息发送:|wechatId[{}]|reqKey[{}]|message[{}]", wechatId, wechatInfo.getReqKey(), message);
String decryptMessage = Crypt.getInstance().decrypt(message, wechatInfo.getReqKey());
if (StringHelper.isBlank(decryptMessage))
return new HttpResult().failure("发送消息内容签名不正确");
MsgBean msgBean = JSONObject.parseObject(decryptMessage, MsgBean.class);
if (null == msgBean)
return new HttpResult().failure("发送消息内容转换失败");
WxTemplateEnum wxTemplateEnum = WxTemplateEnum.of(msgBean.getTemplateId());
try {
boolean isOk = messageService.sendWeixinTemplateMessage(wxTemplateEnum, msgBean);
if (isOk)
return new HttpResult().success("SUCCESS");
} catch (WxErrorException e) {
e.printStackTrace();
return new HttpResult().failure("发送消息失败[" + e.getMessage() + "]");
}
return new HttpResult().failure("消息发送失败!");
}
Aggregations