#520 企业微信网页授权增加使用user_ticket获取成员详情的接口

This commit is contained in:
Binary Wang
2018-04-22 22:35:47 +08:00
parent 61e3163f48
commit 5b69d91e65
9 changed files with 137 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
/**
* <pre>
@@ -64,4 +65,19 @@ public interface WxCpOAuth2Service {
*/
String[] getUserInfo(Integer agentId, String code) throws WxErrorException;
/**
* <pre>
* 使用user_ticket获取成员详情.
*
* 文档地址https://work.weixin.qq.com/api/doc#10028/%E4%BD%BF%E7%94%A8user_ticket%E8%8E%B7%E5%8F%96%E6%88%90%E5%91%98%E8%AF%A6%E6%83%85
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=ACCESS_TOKEN
*
* 权限说明:
* 需要有对应应用的使用权限,且成员必须在授权应用的可见范围内。
* </pre>
*
* @param userTicket 成员票据
*/
WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException;
}

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -8,6 +9,7 @@ import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
/**
* <pre>
@@ -52,9 +54,8 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
@Override
public String[] getUserInfo(Integer agentId, String code) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
+ "code=" + code
+ "&agentid=" + agentId;
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d",
code, agentId);
String responseText = this.mainService.get(url, null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
@@ -63,4 +64,12 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
GsonHelper.getString(jo, "OpenId")};
}
@Override
public WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail";
JsonObject param = new JsonObject();
param.addProperty("user_ticket", userTicket);
String responseText = this.mainService.post(url, param.toString());
return new GsonBuilder().create().fromJson(responseText, WxCpUserDetail.class);
}
}