huanghongfa
2021-07-02 ffcd3e31c9938eb256d616c80edbe1821e9fb2bf
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
package com.panzhihua.common.utlis;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.http.entity.ContentType;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
 
public class WxUtil {
 
    //客服消息推送地址
    public final static String kf_url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
 
    public static String sendKfLinkMessage(String openid,String url,String thumbUrl,String access_token)throws Exception{
        Map<String,Object> map_content = new HashMap<>();
        map_content.put("title","社区福利一分购");
        map_content.put("description","点击参与社区一分钱抢购活动");
        map_content.put("url",url);//跳转地址
        map_content.put("thumb_url",thumbUrl);//图片地址
        Map<String,Object> map = new HashMap<>();
        map.put("touser",openid);
        map.put("msgtype","link");
        map.put("link",map_content);
        String content = JSON.toJSONString(map);
        return HttpClientUtil.httpPost(kf_url+"?access_token="+access_token,content);
    }
 
    public static String sendKfConetntMessage(String openid,String access_token)throws Exception{
        Map<String,Object> map_content = new HashMap<>();
        map_content.put("content","社区福利一分购");
        Map<String,Object> map = new HashMap<>();
        map.put("touser",openid);
        map.put("msgtype","text");
        map.put("text",map_content);
        String content = JSON.toJSONString(map);
        return HttpClientUtil.httpPost(kf_url+"?access_token="+access_token,content);
    }
 
    public static String sendKfImagesMessage(String openid,String access_token,String mediaId)throws Exception{
        Map<String,Object> map_content = new HashMap<>();
        map_content.put("media_id",mediaId);
        Map<String,Object> map = new HashMap<>();
        map.put("touser",openid);
        map.put("msgtype","image");
        map.put("image",map_content);
        String content = JSON.toJSONString(map);
        return HttpClientUtil.httpPost(kf_url+"?access_token="+access_token,content);
    }
 
}