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