From 2aad5c6ca552423d1b8e6e8c869a698a15822759 Mon Sep 17 00:00:00 2001 From: fhx <308050795@qq.com> Date: 星期二, 25 四月 2023 15:32:39 +0800 Subject: [PATCH] 1.修改redis工具 --- src/main/java/com/hx/util/corp/CorpMpUtil.java | 68 +++++++++++++++++++++++++++++++-- 1 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hx/util/corp/CorpMpUtil.java b/src/main/java/com/hx/util/corp/CorpMpUtil.java index 98e460b..8ca404e 100644 --- a/src/main/java/com/hx/util/corp/CorpMpUtil.java +++ b/src/main/java/com/hx/util/corp/CorpMpUtil.java @@ -1,9 +1,10 @@ package com.hx.util.corp; import com.alibaba.fastjson.JSONObject; -import com.hx.exception.TipsException; import com.hx.util.HttpMethodUtil; import com.hx.util.StringUtils; +import com.hx.util.corp.entity.AppLetInfo; +import com.hx.util.corp.entity.OpenIdAUserId; import com.hx.util.corp.entity.WeiXinInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,7 +22,54 @@ private static Logger logger = LoggerFactory.getLogger(CorpMpUtil.class.getName()); /**閾炬帴-鑾峰彇搴旂敤accessToken*/ - public static final String URL_GET_USER_INFO= "https://qyapi.weixin.qq.com/cgi-bin/user/get"; + public static final String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/get"; + + /**openid杞瑄serid*/ + public static final String URL_OPENID_TO_USERID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid"; + + /**userid杞琽penid*/ + public static final String URL_USERID_TO_OPENID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid"; + + /**鑾峰彇灏忕▼搴忛摼鎺�*/ + public static final String URL_LINK = "https://api.weixin.qq.com/wxa/generate_urllink"; + + + /** + * openId鑾峰彇userId + * @param openId 鐢ㄦ埛openId + * @return 杩斿洖 + */ + public static OpenIdAUserId openIdToUserId(String openId, String token) { + Map<String,Object> map=new HashMap<>(); + map.put("access_token",token); + + JSONObject data = new JSONObject(); + data.put("openid",openId); + + String datas = HttpMethodUtil.HttpURLUtilJson(URL_OPENID_TO_USERID, data.toString(), map, null, "GET"); + OpenIdAUserId openIdAUserId = JSONObject.parseObject(datas, OpenIdAUserId.class); + return openIdAUserId; + } + + + /** + * userId鑾峰彇openId + * @param userid 浼佷笟鍛樺伐id + * @return 杩斿洖 + */ + public static OpenIdAUserId userIdToOpenId(String userid, String token) { + Map<String,Object> map=new HashMap<>(); + map.put("access_token",token); + + JSONObject data = new JSONObject(); + data.put("userid",userid); + + String datas = HttpMethodUtil.HttpURLUtilJson(URL_USERID_TO_OPENID, data.toString(), map, null, "GET"); + OpenIdAUserId openIdAUserId = JSONObject.parseObject(datas, OpenIdAUserId.class); + return openIdAUserId; + } + + /** * 鑾峰彇浼佷笟寰俊鍛樺伐淇℃伅 @@ -29,15 +77,25 @@ * @return 杩斿洖 */ public static WeiXinInfo userInfo(String userId, String token) { - logger.info("userId:"+userId); - logger.info("token:"+token); Map<String,Object> map=new HashMap<>(); map.put("access_token",token); map.put("userid",userId); String datas = HttpMethodUtil.HttpURLUtilJson(URL_GET_USER_INFO, null, map, null, "GET"); - logger.info("datas:"+datas); WeiXinInfo weiXinInfo = JSONObject.parseObject(datas, WeiXinInfo.class); return weiXinInfo; } + public static AppLetInfo getAppLetUrl(String path, String token, String env_version, String query) { + Map<String, Object> map = new HashMap(); + map.put("access_token", token); + com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); + data.put("path", path); + data.put("env_version", env_version); + if (!StringUtils.isEmpty(query)){ + data.put("query", query); + } + String datas = HttpMethodUtil.HttpURLUtilJson(URL_LINK, data.toString(), map, (Map)null, "POST"); + AppLetInfo appLetInfo = com.alibaba.fastjson.JSONObject.parseObject(datas, AppLetInfo.class); + return appLetInfo; + } } -- Gitblit v1.8.0