mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🆕 #1873 【企业微信】第三方应用增加网页授权登陆获取访问用户身份和获取访问用户敏感信息的接口
This commit is contained in:
parent
64d67bb42f
commit
c80e77c047
@ -0,0 +1,58 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangxiaoming
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WxCpTpUserDetail extends WxCpBaseResp {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5028321625140879571L;
|
||||||
|
/**
|
||||||
|
* 用户所属企业的corpid
|
||||||
|
*/
|
||||||
|
@SerializedName("corpid")
|
||||||
|
private String corpId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员UserID
|
||||||
|
*/
|
||||||
|
@SerializedName("userid")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员姓名
|
||||||
|
*/
|
||||||
|
@SerializedName("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别。0表示未定义,1表示男性,2表示女性
|
||||||
|
*/
|
||||||
|
@SerializedName("gender")
|
||||||
|
private String gender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像url。仅在用户同意snsapi_privateinfo授权时返回
|
||||||
|
*/
|
||||||
|
@SerializedName("avatar")
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工个人二维码(扫描可添加为外部联系人),仅在用户同意snsapi_privateinfo授权时返回
|
||||||
|
*/
|
||||||
|
@SerializedName("qr_code")
|
||||||
|
private String qrCode;
|
||||||
|
|
||||||
|
public static WxCpTpUserDetail fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpTpUserDetail.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return WxCpGsonBuilder.create().toJson(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huangxiaoming
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WxCpTpUserInfo extends WxCpBaseResp {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5028321625140879571L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户所属企业的corpid
|
||||||
|
*/
|
||||||
|
@SerializedName("CorpId")
|
||||||
|
private String corpId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户在企业内的UserID,如果该企业与第三方应用有授权关系时,返回明文UserId,否则返回密文UserId
|
||||||
|
*/
|
||||||
|
@SerializedName("UserId")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机设备号(由企业微信在安装时随机生成,删除重装会改变,升级不受影响)
|
||||||
|
*/
|
||||||
|
@SerializedName("DeviceId")
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员票据,最大为512字节。
|
||||||
|
* scope为snsapi_userinfo或snsapi_privateinfo,且用户在应用可见范围之内时返回此参数。
|
||||||
|
* 后续利用该参数可以获取用户信息或敏感信息,参见:https://work.weixin.qq.com/api/doc/90001/90143/91122
|
||||||
|
*/
|
||||||
|
@SerializedName("user_ticket")
|
||||||
|
private String userTicket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user_ticket的有效时间(秒),随user_ticket一起返回
|
||||||
|
*/
|
||||||
|
@SerializedName("expires_in")
|
||||||
|
private String expiresIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取
|
||||||
|
*/
|
||||||
|
@SerializedName("open_userid")
|
||||||
|
private String openUserId;
|
||||||
|
|
||||||
|
public static WxCpTpUserInfo fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpTpUserInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return WxCpGsonBuilder.create().toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -142,6 +142,8 @@ public final class WxCpApiPathConsts {
|
|||||||
public static final String GET_AUTH_INFO = "/cgi-bin/service/get_auth_info";
|
public static final String GET_AUTH_INFO = "/cgi-bin/service/get_auth_info";
|
||||||
public static final String GET_AUTH_CORP_JSAPI_TICKET = "/cgi-bin/get_jsapi_ticket";
|
public static final String GET_AUTH_CORP_JSAPI_TICKET = "/cgi-bin/get_jsapi_ticket";
|
||||||
public static final String GET_SUITE_JSAPI_TICKET = "/cgi-bin/ticket/get";
|
public static final String GET_SUITE_JSAPI_TICKET = "/cgi-bin/ticket/get";
|
||||||
|
public static final String GET_USERINFO3RD = "/cgi-bin/service/getuserinfo3rd";
|
||||||
|
public static final String GET_USERDETAIL3RD = "/cgi-bin/service/getuserdetail3rd";
|
||||||
}
|
}
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
|
@ -6,10 +6,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
|||||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
import me.chanjar.weixin.cp.bean.*;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTpAuthInfo;
|
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTpCorp;
|
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTpPermanentCodeInfo;
|
|
||||||
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,4 +263,24 @@ public interface WxCpTpService {
|
|||||||
* @return WxSessionManager session manager
|
* @return WxSessionManager session manager
|
||||||
*/
|
*/
|
||||||
WxSessionManager getSessionManager();
|
WxSessionManager getSessionManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 获取访问用户身份
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
WxCpTpUserInfo getUserInfo3rd(String code) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 获取访问用户敏感信息
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param userTicket
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
WxCpTpUserDetail getUserDetail3rd(String userTicket) throws WxErrorException;
|
||||||
}
|
}
|
||||||
|
@ -342,4 +342,19 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
|
|||||||
return this.sessionManager;
|
return this.sessionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpTpUserInfo getUserInfo3rd(String code) throws WxErrorException{
|
||||||
|
String url = configStorage.getApiUrl(GET_USERINFO3RD);
|
||||||
|
String result = get(url+"?code="+code,null);
|
||||||
|
return WxCpTpUserInfo.fromJson(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpTpUserDetail getUserDetail3rd(String userTicket) throws WxErrorException{
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("user_ticket", userTicket);
|
||||||
|
String result = post(configStorage.getApiUrl(GET_USERDETAIL3RD), jsonObject.toString());
|
||||||
|
return WxCpTpUserDetail.fromJson(result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user