jinpengyong
2023-11-03 ed05d0e27515d4fb054284e77af94c5d0ebed3c1
screen-api/src/main/java/com/moral/api/controller/AppUserController.java
@@ -5,7 +5,6 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@@ -19,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.moral.api.service.UserService;
import com.moral.api.utils.HttpClientUtil;
@@ -68,8 +68,8 @@
    @GetMapping("pushOneUser")
    @ApiOperation(value = "小程序推送消息")
    public  ResultMessage pushOneUser(String openid){
        String body = push("oOCWi6yfVapaK25Jnkk7jKSbMLyw");
    public  ResultMessage pushOneUser(){
        String body = push("oOCWi6-_hnzSvrMT8HX5D7Dz7tEA");
        return ResultMessage.ok(body);
    }
@@ -77,18 +77,39 @@
    public String push(String openid) {
        RestTemplate restTemplate = new RestTemplate();
        //这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取)
        //小程序订阅
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + HttpClientUtil.getAccessToken();
//        String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + HttpClientUtil.getAccessToken();
//        String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" + HttpClientUtil.getAccessToken();
//        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + HttpClientUtil.getAccessToken();
          //小程序客服
//        String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + HttpClientUtil.getAccessToken();
        //拼接推送的模版
        WxMssVo wxMssVo = new WxMssVo();
        wxMssVo.setTouser(openid);//用户的openid(要发送给那个用户,通常这里应该动态传进来的)
        wxMssVo.setTemplate_id("CFeSWarQLMPyPjwmiy6AV4eB-IZcipu48V8bFLkBzTU");//订阅消息模板id
        wxMssVo.setPage("pages/index/index");
        wxMssVo.setTemplate_id("YNqUZ1MgMvwY3G-NENVbcmIBR5dUotSdnwcz96CWrho");//订阅消息模板id
        wxMssVo.setLang("zh_CN");
        wxMssVo.setMiniprogramState("formal");
//        wxMssVo.setPage("pages/index/index");
        Map<String, String> m = new HashMap<>(3);
        m.put("thing1", "小程序入门课程");
        m.put("thing6", "杭州浙江大学");
        m.put("thing7", "第一章第一节");
        wxMssVo.setData(m);
        Map<String, Object> m = new HashMap<>();
        HashMap<String, Object> map1 = new HashMap<>();
        HashMap<String, Object> map2 = new HashMap<>();
        HashMap<String, Object> map3 = new HashMap<>();
        HashMap<String, Object> map4 = new HashMap<>();
        map1.put("value","欧阳仑2");
        map2.put("value","ouyanglun");
        map3.put("value","巧克力1");
        map4.put("value","2023-10-16");
        m.put("thing18", map1);
        m.put("character_string1", map2);
        m.put("thing2", map3);
        m.put("date4", map4);
        wxMssVo.setData(JSON.toJSON(m));
        ResponseEntity<String> responseEntity =
                restTemplate.postForEntity(url, wxMssVo, String.class);
        return responseEntity.getBody();