| package com.doumee.core.wx; | 
|   | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.doumee.biz.system.SystemDictDataBiz; | 
| import com.doumee.core.constants.Constants; | 
| import com.doumee.core.utils.DateUtil; | 
| import com.doumee.dao.system.model.SystemUser; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.http.ResponseEntity; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.web.client.RestTemplate; | 
|   | 
| import java.util.Date; | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * Created by IntelliJ IDEA. | 
|  * | 
|  * @Author : Rk | 
|  * @create 2022/12/7 17:27 | 
|  */ | 
| @Service | 
| @Slf4j | 
| public class SendWxMessage { | 
|   | 
|     private static String goodsOrderUrl = "pages/settlementDetails/settlementDetails?goodsOrderId="; | 
|   | 
|     @Autowired | 
|     private SystemDictDataBiz systemDictDataBiz; | 
|   | 
|     public  void  bookingsCancel(String openid, String goodsOrderId, String accessToken, String bikeCode, Date startTime, Date endTime){ | 
|         RestTemplate restTemplate = new RestTemplate(); | 
|         log.info("微信小程序->微信消息通知 临时锁车超时 -> accessToken:{}",accessToken); | 
|         //这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取) | 
|         String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken; | 
|         //拼接推送的模版 | 
|         WxMsgVO wxMsgVo = new WxMsgVO(); | 
|         //用户的openid(要发送给那个用户) | 
|         wxMsgVo.setTouser(openid); | 
|         //订阅消息模板id | 
|         wxMsgVo.setTemplate_id(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.TIME_OUT_TEMPID).getCode()); | 
|         Map<String, TemplateData> m = new HashMap<>(4); | 
|         m.put("character_string1", new TemplateData(bikeCode)); | 
|         //解锁时间 | 
|         m.put("date3", new TemplateData(DateUtil.getDate(startTime,"yyyy-MM-dd HH:mm"))); | 
|         //上锁时间 | 
|         m.put("date4", new TemplateData(DateUtil.getDate(endTime,"yyyy-MM-dd HH:mm"))); | 
|         //温馨提醒 | 
|         m.put("thing5", new TemplateData("临时锁车已超过最大时长,已自动还车")); | 
|         wxMsgVo.setPage(goodsOrderUrl + goodsOrderId); | 
|         wxMsgVo.setData(m); | 
|         ResponseEntity<String> responseEntity = | 
|                 restTemplate.postForEntity(url, wxMsgVo, String.class); | 
|         log.info("微信小程序->微信消息通知 临时锁车超时:{}", JSONObject.toJSONString(responseEntity)); | 
|     } | 
|   | 
|   | 
| } |