jiangping
2025-07-19 0cfbaf9a439dc75824c52a6e58b6849064afbc80
server/services/src/main/java/com/doumee/config/wx/SendWxMessage.java
@@ -4,6 +4,7 @@
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.business.model.IdentityInfo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,33 +28,32 @@
    private static String goodsOrderUrl = "pages/settlementDetails/settlementDetails?goodsOrderId=";
    private static String identityInfoUrl = "pages/mine/mine";
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    public  void  bookingsCancel(String openid, String goodsOrderId, String accessToken, String bikeCode, Date startTime, Date endTime) throws WxErrorException {
    public  void  identityInfoMessage(String openid, IdentityInfo identityInfo) throws WxErrorException {
        RestTemplate restTemplate = new RestTemplate();
        log.info("微信小程序->微信消息通知  -> accessToken:{}",accessToken);
        String accessToken = WxMiniConfig.wxMaService.getAccessToken();
        log.info("微信小程序->微信消息通知 - 认证信息  -> accessToken:{}",accessToken);
        //这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取)
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+WxMiniConfig.wxMaService.getAccessToken();
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken;
        //拼接推送的模版
        WxMsgVO wxMsgVo = new WxMsgVO();
        WxMsgVO wxMsgVO = new WxMsgVO();
        //用户的openid(要发送给那个用户)
        wxMsgVo.setTouser(openid);
        wxMsgVO.setTouser(openid);
        //订阅消息模板id
//        wxMsgVo.setTemplate_id(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.TIME_OUT_TEMPID).getCode());
        wxMsgVO.setTemplate_id("4H9ztG4E9BxJLwMuYSZ6oiM7yb4KX7u7bYhkhYJP0-Y");
        Map<String, TemplateData> m = new HashMap<>(4);
        m.put("character_string1", new TemplateData(bikeCode));
        //解锁时间
        m.put("date3", new TemplateData(DateUtil.getFomartDate(startTime,"yyyy/MM/dd HH:mm")));
        //上锁时间
        m.put("date4", new TemplateData(DateUtil.getFomartDate(endTime,"yyyy/MM/dd HH:mm")));
        //温馨提醒
        m.put("thing5", new TemplateData("临时锁车已超过最大时长,已自动还车"));
        wxMsgVo.setPage(goodsOrderUrl + goodsOrderId);
        wxMsgVo.setData(m);
        m.put("thing11", new TemplateData(Constants.equalsInteger(identityInfo.getType(),Constants.ZERO)?"用工认证":Constants.equalsInteger(identityInfo.getType(),Constants.ONE)?"运货认证":"供餐认证"));
        m.put("phrase4", new TemplateData(Constants.equalsInteger(identityInfo.getAuditStatus(),Constants.TWO)?"认证通过":"认证未通过"));
        m.put("date3", new TemplateData(DateUtil.getFomartDate(identityInfo.getAuditTime(),"yyyy-MM-dd HH:mm:ss")));
        m.put("thing5", new TemplateData(identityInfo.getAuditRemark()));
        wxMsgVO.setPage(identityInfoUrl);
        wxMsgVO.setData(m);
        ResponseEntity<String> responseEntity =
                restTemplate.postForEntity(url, wxMsgVo, String.class);
        log.info("微信小程序->微信消息通知 临时锁车超时:{}", JSONObject.toJSONString(responseEntity));
                restTemplate.postForEntity(url, wxMsgVO, String.class);
        log.info("微信小程序->微信消息通知 认证信息:{}", JSONObject.toJSONString(responseEntity));
    }