设为首页 加入收藏

TOP

微信小程序订阅消息开发指南(java)(四)
2023-07-25 21:33:53 】 浏览:55
Tags:程序订 java
.EntityUtils; import org.jeecg.modules.video.utitls.Constants; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; /** * @description: * @author: Mr.Fang * @create: 2023-04-03 17:06 **/ public class HttpUtils { /** * description: 获取token,返回结果为 JSON 自行转 map * create by: Mr.Fang * * @return: java.lang.String * @date: 2023/4/3 17:46 */ public String getToken() throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); Map<String, Object> params = new HashMap<>(); params.put("appid", Constants.APPLET_APP_ID); params.put("secret", Constants.APPLET_SECRET); params.put("grant_type", "client_credential"); String url = handleParams("https://api.weixin.qq.com/cgi-bin/token", params); HttpGet httpGet = new HttpGet(url); CloseableHttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); // 响应结果 return EntityUtils.toString(entity, CharSetType.UTF8.getType()); } /** * description: 获取 open id,返回结果为 JSON 自行转 map * create by: Mr.Fang * * @param: [code] * @return: java.lang.String * @date: 2023/4/3 17:46 */ public String getOpenId(String code) throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); Map<String, Object> params = new HashMap<>(); params.put("appid", Constants.APPLET_APP_ID); params.put("secret", Constants.APPLET_SECRET); params.put("js_code", code); params.put("grant_type", "authorization_code"); String url = handleParams("https://api.weixin.qq.com/sns/jscode2session", params); HttpGet httpGet = new HttpGet(url); CloseableHttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); // 响应结果 return EntityUtils.toString(entity, CharSetType.UTF8.getType()); } /** * description: 消息推送 返回结果为 JSON 自行转 map;token 调用 getToken获取 * create by: Mr.Fang * * @param: [token] * @return: java.lang.String * @date: 2023/4/3 17:46 */ public String pushMsg(String token) throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); Map<String, Object> params = new HashMap<>(); // 处理微信推送数据结构 JSONObject mapData = new JSONObject(); Map<String, Object> map1 = new HashMap<>(); map1.put("value", "任务名称"); mapData.put("thing2", map1); Map<String, Object> map2 = new HashMap<>(); map2.put("value", "2023-04-03 12:00:00"); mapData.put("time3", map2); Map<String, Object> map3 = new HashMap<>(); map3.put("value", "描述信息"); mapData.put("thing4", map3); Map<String, Object> map4 = new HashMap<>(); map4.put("value", "备注系信息"); mapData.put("thing10", map4); Map<String, Object> map5 = new HashMap<>(); map5.put("value", "抖音"); mapData.put("thing11", map5); params.put("templa
首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java 处理重复提交问题 下一篇面试官:谈谈 Spring Cloud 与 Du..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目