| | |
| | | import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; |
| | | import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; |
| | | import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Map; |
| | | |
| | |
| | | return false; |
| | | } |
| | | try { |
| | | WxMpKefuMessage message = WxMpKefuMessage.TEXT() |
| | | .toUser(openid) |
| | | .content(content) |
| | | .build(); |
| | | WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(openid).content(content).build(); |
| | | boolean result = wxMpService.getKefuService().sendKefuMessage(message); |
| | | log.info("【WxMpUtils】文本客服消息发送{},openid:{}", result ? "成功" : "失败", openid); |
| | | return result; |
| | |
| | | * 示例:{"first": new WxMpTemplateData("first", "你好", "#173177"), ...} |
| | | * @return 发送成功返回微信返回的 msgid,失败返回 null |
| | | */ |
| | | public String sendTemplateMessage(String openid, String templateId, String url, |
| | | Map<String, WxMpTemplateData> dataMap) { |
| | | public String sendTemplateMessage(String openid, String templateId, String url, Map<String, WxMpTemplateData> dataMap) { |
| | | if (StringUtils.isEmpty(openid)) { |
| | | log.warn("【WxMpUtils】sendTemplateMessage 失败:openid 为空"); |
| | | return null; |
| | |
| | | log.info("【WxMpUtils】模板消息发送成功,openid:{},msgId:{}", openid, msgId); |
| | | return msgId; |
| | | } catch (WxErrorException e) { |
| | | log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", |
| | | openid, templateId, e.getError(), e); |
| | | log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", openid, templateId, e.getError(), e); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | * 示例:{"first": "你好", "keyword1": "2024-01-01", "remark": "感谢使用"} |
| | | * @return 发送成功返回微信返回的 msgid,失败返回 null |
| | | */ |
| | | public String sendTemplateMessage(String openid, String templateId, String url, |
| | | Map<String, String> dataMap, String defaultColor) { |
| | | public String sendTemplateMessage(String openid, String templateId, String url, Map<String, String> dataMap, String defaultColor) { |
| | | if (StringUtils.isEmpty(openid)) { |
| | | log.warn("【WxMpUtils】sendTemplateMessage 失败:openid 为空"); |
| | | return null; |
| | |
| | | log.info("【WxMpUtils】模板消息发送成功,openid:{},msgId:{}", openid, msgId); |
| | | return msgId; |
| | | } catch (WxErrorException e) { |
| | | log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", |
| | | openid, templateId, e.getError(), e); |
| | | log.error("【WxMpUtils】模板消息发送异常,openid:{},templateId:{},错误:{}", openid, templateId, e.getError(), e); |
| | | return null; |
| | | } |
| | | } |