jiangping
2024-09-27 04b4bddaac0a222760113899568d20b45af701f4
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
67
68
69
70
71
72
73
74
75
76
package com.doumee.core.wx;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.system.model.SystemDictData;
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 programUrl = "packagesMine/meetingDetails/meetingDetails?id=";
 
 
    public  void  testMessage(String openid,String token){
        RestTemplate restTemplate = new RestTemplate();
        log.info("微信小程序 会议开始订阅消息发送日志 -> accessToken:{}",token);
        //这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取)
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+token;
        //拼接推送的模版
        WxMsgVO wxMsgVo = new WxMsgVO();
        //用户的openid(要发送给那个用户)
        wxMsgVo.setTouser(openid);
        //订阅消息模板id
        wxMsgVo.setTemplate_id("A_jEWoyl0Uu_l5J-zwlwx_FcbUirlsS6Peu4JW6a7Gc");
        Map<String, TemplateData> m = new HashMap<>(2);
        //会议主题
        m.put("thing1", new TemplateData("又来新客户啦!"));
 
        //会议地点
        m.put("character_string6", new TemplateData("zhangsan01"));
        wxMsgVo.setData(m);
        ResponseEntity<String> responseEntity =
                restTemplate.postForEntity(url, wxMsgVo, String.class);
        log.info("微信小程序-> 取消通知订阅消息发送日志:{}",JSONObject.toJSONString(responseEntity));
    }
 
 
 
 
//    /**
//     * 获取token
//     */
//    private static String getAccessToken() {
//        //发送请求获取token
//        JSONObject token = null;
//        try {
//            token = JSONObject.parseObject(HttpsUtil.get(APP_ACCESS_TOKEN_URL,false));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        JSONObject jsonObject = token;
//        String accessToken = (String) jsonObject.get("access_token");
//        Integer expiresIn = (Integer) jsonObject.get("expires_in");
//        //创建token对象,并存储
//        return new AccessToken(accessToken,String.valueOf(expiresIn)).getAccessToken();
//    }
 
}