From 013835fc313c3c70210d4ff4a4b007787e0d0b91 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 4 Aug 2018 19:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEcode=E8=8E=B7=E5=8F=96=E6=88=90=E5=91=98=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0user=5Fticket=E5=92=8Cexpires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java | 7 ++++--- .../chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java index a9fa5f94..6e4fce82 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java @@ -51,16 +51,17 @@ public interface WxCpOAuth2Service { /** *
-   * 用oauth2获取用户信息
+   * 根据code获取成员信息
    * http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
+   * https://work.weixin.qq.com/api/doc#10028/根据code获取成员信息
    * 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
    *
    * 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
    * 
* * @param agentId 企业号应用的id - * @param code 微信oauth授权返回的代码 - * @return [userid, deviceid] + * @param code 通过成员授权获取到的code,最大为512字节。每次成员授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 + * @return [UserId, DeviceId, OpenId, user_ticket, expires_in] * @see #getUserInfo(String) */ String[] getUserInfo(Integer agentId, String code) throws WxErrorException; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java index f5950f5b..cbdc66b5 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java @@ -16,6 +16,8 @@ import me.chanjar.weixin.cp.bean.WxCpUserDetail; * * Created by Binary Wang on 2017-6-25. * @author Binary Wang + * + * @author Binary Wang * */ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service { @@ -61,7 +63,10 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service { JsonObject jo = je.getAsJsonObject(); return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId"), - GsonHelper.getString(jo, "OpenId")}; + GsonHelper.getString(jo, "OpenId"), + GsonHelper.getString(jo, "user_ticket"), + GsonHelper.getString(jo, "expires_in") + }; } @Override