New file |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |