赞
踩
1.获取token
2.组装报文
3.调用微信api
4.获取返回状态码成功,则为ok
- public void sendChargeMessage() {
- Token token = Token.getInstance();
- String accessToken = token.getAccessToken();
- System.out.println("我拿到token了++++++++" + accessToken);
-
- Map<String, WeChatTemplateData> data = new HashMap<>();
- WeChatTemplateData templateOrderIdData = new WeChatTemplateData();
- templateOrderIdData.setValue("");
- templateOrderIdData.setColor("#173177");
-
- WeChatTemplateData templateNameData = new WeChatTemplateData();
- templateNameData.setValue("");
- templateNameData.setColor("#173177");
-
-
- WeChatTemplateData templateTing5Data = new WeChatTemplateData();
- templateTing5Data.setValue("");
- templateTing5Data.setColor("#173177");
-
- WeChatTemplateData templateAmountData = new WeChatTemplateData();
- templateAmountData.setValue("");
- templateAmountData.setColor("#173177");
-
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年M月d日 HH:mm");
- LocalDateTime currentDateTime = LocalDateTime.now();
- String formattedDateTime = currentDateTime.format(formatter);
- WeChatTemplateData templateTimeData = new WeChatTemplateData();
- templateTimeData.setValue(formattedDateTime);
- templateTimeData.setColor("#173177");
-
-
- data.put("character_string4", templateOrderIdData);
- data.put("thing1", templateNameData);
- data.put("thing3", templateTing5Data);
- data.put("amount2", templateAmountData);
- data.put("time5", templateTimeData);
- log.info("消息发送数据:{}", data.toString());
-
- String result = this.chargeMessage(accessToken, open_id, data);
- log.info("消息发送结果:", result);
- }
-
-
- /**
- * 发送余额不足消息
- *
- * @param accessToken
- * @param touser
- * @param map
- * @return
- */
- public String chargeMessage(String accessToken, String touser, Map<String, WeChatTemplateData> map) {
- WechatTemplate message = new WechatTemplate();
- //拼接数据
- message.setPage(messPath);
- message.setData(map);
- message.setTouser(touser);
- message.setTemplate_id(chargeTemId);
- message.setAccess_token(accessToken);
- message.setMiniprogram_state(type);//跳转小程序类型 “体验版”
- String json = com.alibaba.fastjson.JSONObject.toJSONString(message);
- System.out.println("要发送的数据" + json);
- String ret = URLUtils.sendPost("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken, json);
- return ret;
- }
- public class WeChatTemplateData {
-
- private String value;
- private String color;
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- public String getColor() {
- return color;
- }
- public void setColor(String color) {
- this.color = color;
- }
- }
点赞加关注,持续更新中!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。