提交 | 用户 | age
|
826b66
|
1 |
package com.hx.util.corp; |
C |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONObject; |
|
4 |
import com.hx.util.HttpMethodUtil; |
|
5 |
import com.hx.util.StringUtils; |
|
6 |
import com.hx.util.corp.entity.AppLetInfo; |
|
7 |
import com.hx.util.corp.entity.OpenIdAUserId; |
|
8 |
import com.hx.util.corp.entity.WeiXinInfo; |
|
9 |
import org.slf4j.Logger; |
|
10 |
import org.slf4j.LoggerFactory; |
|
11 |
|
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
/** 企业微信工具类 |
|
16 |
* @author wangrenhuang |
|
17 |
* @Date 2021-10-19 |
|
18 |
*/ |
|
19 |
public class CorpMpUtil { |
|
20 |
|
|
21 |
//log4j日志 |
|
22 |
private static Logger logger = LoggerFactory.getLogger(CorpMpUtil.class.getName()); |
|
23 |
|
|
24 |
/**链接-获取应用accessToken*/ |
|
25 |
public static final String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/get"; |
|
26 |
|
|
27 |
/**openid转userid*/ |
|
28 |
public static final String URL_OPENID_TO_USERID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid"; |
|
29 |
|
|
30 |
/**userid转openid*/ |
|
31 |
public static final String URL_USERID_TO_OPENID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid"; |
|
32 |
|
|
33 |
/**获取小程序链接*/ |
|
34 |
public static final String URL_LINK = "https://api.weixin.qq.com/wxa/generate_urllink"; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* openId获取userId |
|
39 |
* @param openId 用户openId |
|
40 |
* @return 返回 |
|
41 |
*/ |
|
42 |
public static OpenIdAUserId openIdToUserId(String openId, String token) { |
|
43 |
Map<String,Object> map=new HashMap<>(); |
|
44 |
map.put("access_token",token); |
|
45 |
|
|
46 |
JSONObject data = new JSONObject(); |
|
47 |
data.put("openid",openId); |
|
48 |
|
|
49 |
String datas = HttpMethodUtil.HttpURLUtilJson(URL_OPENID_TO_USERID, data.toString(), map, null, "GET"); |
|
50 |
OpenIdAUserId openIdAUserId = JSONObject.parseObject(datas, OpenIdAUserId.class); |
|
51 |
return openIdAUserId; |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* userId获取openId |
|
57 |
* @param userid 企业员工id |
|
58 |
* @return 返回 |
|
59 |
*/ |
|
60 |
public static OpenIdAUserId userIdToOpenId(String userid, String token) { |
|
61 |
Map<String,Object> map=new HashMap<>(); |
|
62 |
map.put("access_token",token); |
|
63 |
|
|
64 |
JSONObject data = new JSONObject(); |
|
65 |
data.put("userid",userid); |
|
66 |
|
|
67 |
String datas = HttpMethodUtil.HttpURLUtilJson(URL_USERID_TO_OPENID, data.toString(), map, null, "GET"); |
|
68 |
OpenIdAUserId openIdAUserId = JSONObject.parseObject(datas, OpenIdAUserId.class); |
|
69 |
return openIdAUserId; |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
/** |
|
75 |
* 获取企业微信员工信息 |
|
76 |
* @param userId 用户id |
|
77 |
* @return 返回 |
|
78 |
*/ |
|
79 |
public static WeiXinInfo userInfo(String userId, String token) { |
|
80 |
Map<String,Object> map=new HashMap<>(); |
|
81 |
map.put("access_token",token); |
|
82 |
map.put("userid",userId); |
|
83 |
String datas = HttpMethodUtil.HttpURLUtilJson(URL_GET_USER_INFO, null, map, null, "GET"); |
|
84 |
WeiXinInfo weiXinInfo = JSONObject.parseObject(datas, WeiXinInfo.class); |
|
85 |
return weiXinInfo; |
|
86 |
} |
|
87 |
|
|
88 |
public static AppLetInfo getAppLetUrl(String path, String token, String env_version, String query) { |
|
89 |
Map<String, Object> map = new HashMap(); |
|
90 |
map.put("access_token", token); |
|
91 |
com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); |
|
92 |
data.put("path", path); |
|
93 |
data.put("env_version", env_version); |
|
94 |
if (!StringUtils.isEmpty(query)){ |
|
95 |
data.put("query", query); |
|
96 |
} |
|
97 |
String datas = HttpMethodUtil.HttpURLUtilJson(URL_LINK, data.toString(), map, (Map)null, "POST"); |
|
98 |
AppLetInfo appLetInfo = com.alibaba.fastjson.JSONObject.parseObject(datas, AppLetInfo.class); |
|
99 |
return appLetInfo; |
|
100 |
} |
|
101 |
} |