rk
6 天以前 08675d26d73c60e1c593e901e09588acf2c39233
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.doumee.config.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.core.utils.HttpsUtil;
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;
import org.springframework.stereotype.Service;
 
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 mineUrl = "/pages/mine/mine";
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    /**
     * 信息认证
     * @param openid
     * @param identityInfo
     * @throws WxErrorException
     */
    public  void  identityInfoMessage(String openid, IdentityInfo identityInfo){
        try{
 
            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="+accessToken;
            //拼接推送的模版
            WxMsgVO wxMsgVO = new WxMsgVO();
            //用户的openid(要发送给那个用户)
            wxMsgVO.setTouser(openid);
            //订阅消息模板id
            wxMsgVO.setTemplate_id("VJho7-lf-4_WZFfOzenDnX6sOhYBJWwkLExVjBB563U");
            Map<String, TemplateData> m = new HashMap<>(4);
            m.put("thing2", new TemplateData(Constants.equalsInteger(identityInfo.getType(),Constants.ZERO)?"用工认证":Constants.equalsInteger(identityInfo.getType(),Constants.ONE)?"运货认证":"供餐认证"));
            m.put("phrase6", new TemplateData(Constants.equalsInteger(identityInfo.getAuditStatus(),Constants.TWO)?"通过":"未通过"));
            m.put("time12", new TemplateData(DateUtil.formatDate(identityInfo.getAuditTime(),"yyyy-MM-dd HH:mm")));
            wxMsgVO.setPage(mineUrl);
            wxMsgVO.setData(m);
            log.error("微信小程序->微信消息通知 认证信息:{}", JSONObject.toJSONString(wxMsgVO));
            String responseEntity  = HttpsUtil.postJson(url,JSONObject.toJSONString(wxMsgVO));
            log.error("微信小程序->微信消息通知 认证信息:{}", JSONObject.toJSONString(responseEntity));
        }catch (WxErrorException wxErrorException){
 
        }
    }
 
}