935090232@qq.com
2021-01-10 0b32374c7908814627648d2e8f0499be2535b2c7
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
77
78
package com.matrix.system.wechart.templateMsg.demo;
 
import com.alibaba.fastjson.JSONObject;
import com.matrix.component.tools.HttpClientUtil;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.system.hive.plugin.util.HttpUtils;
import com.matrix.system.shopXcx.api.WeChatGzhApiTools;
import com.matrix.system.shopXcx.bean.ShopAdvertisType;
import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.swing.text.html.HTML;
import java.io.IOException;
@Controller
@RequestMapping(value = "test")
public class MsgDemo {
 
    @Value("${gzh_appid}")
    String gzhAppId;
 
    @Value("${gzh_secret}")
    String gzhSecret;
 
 
    @RequestMapping("/template")
    @ResponseBody
    public AjaxResult template() {
        GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo();
        messagePojo.setTouser("o8EB656NQYwhUuKPMhVVwP_wtLJI");
        messagePojo.setTemplate_id("Mqu9xPYj_JFhXNj7nLJS7LESQUy6Z7FoCOmVO66Oxe8");
        //messagePojo.setUrl("www.baidu.com");
       // messagePojo.setMiniprogram(gzhAppId,"/123/234123412");
        messagePojo.setFirst("尊敬的谭娅:","#453454");
        messagePojo.setKeyWord("活细胞肩部护理","#453454");
        messagePojo.setKeyWord("2014年7月21日 18:36","#453454");
        messagePojo.setRemark("您的护理课程剩余3次。","#453454");
 
        String ACCESS_TOKEN=WeChatGzhApiTools.getAccessToken(gzhAppId,gzhSecret);
        String url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+ACCESS_TOKEN;
 
        System.out.println(JSONObject.toJSON(messagePojo).toString());
        JSONObject result= HttpClientUtil.sendPostWithJson(url,JSONObject.toJSON(messagePojo).toString());
        System.out.println(result.toString());
        return AjaxResult.buildSuccessInstance("1");
 
 
    }
 
 
    @RequestMapping("/getUserList")
    @ResponseBody
    public AjaxResult getUserList() {
 
        String ACCESS_TOKEN=WeChatGzhApiTools.getAccessToken(gzhAppId,gzhSecret);
 
        String url="https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID".replaceAll("ACCESS_TOKEN",ACCESS_TOKEN);
 
 
        String result= HttpUtils.sendGet(url,"");
        System.out.println(result.toString());
        return AjaxResult.buildSuccessInstance("1");
 
 
    }
 
}