From ed84f511c713901b201b18c1ef6ba1ae8d946f24 Mon Sep 17 00:00:00 2001 From: SimonDolph Date: Thu, 24 Dec 2015 17:44:48 +0800 Subject: [PATCH] add unionid --- .../mp/bean/result/WxMpOAuth2AccessToken.java | 15 +++++++++++++-- .../util/json/WxMpOAuth2AccessTokenAdapter.java | 14 +++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java index 2d6696d45..6ac77c83c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java @@ -1,9 +1,9 @@ package me.chanjar.weixin.mp.bean.result; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - import java.io.Serializable; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + public class WxMpOAuth2AccessToken implements Serializable { private String accessToken; @@ -16,6 +16,8 @@ public class WxMpOAuth2AccessToken implements Serializable { private String scope; + private String unionId; + public String getRefreshToken() { return refreshToken; } @@ -56,6 +58,14 @@ public void setExpiresIn(int expiresIn) { this.expiresIn = expiresIn; } + public String getUnionId() { + return unionId; + } + + public void setUnionId(String unionId) { + this.unionId = unionId; + } + public static WxMpOAuth2AccessToken fromJson(String json) { return WxMpGsonBuilder.create().fromJson(json, WxMpOAuth2AccessToken.class); } @@ -68,6 +78,7 @@ public String toString() { ", refreshToken='" + refreshToken + '\'' + ", openId='" + openId + '\'' + ", scope='" + scope + '\'' + + ", unionId='" + unionId + '\'' + '}'; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java index 6d73131a2..753e22d17 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpOAuth2AccessTokenAdapter.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.mp.util.json; -import com.google.gson.*; +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; -import java.lang.reflect.Type; - public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer { public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws @@ -28,6 +33,9 @@ public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDes if (accessTokenJsonObject.get("scope") != null && !accessTokenJsonObject.get("scope").isJsonNull()) { accessToken.setScope(GsonHelper.getAsString(accessTokenJsonObject.get("scope"))); } + if (accessTokenJsonObject.get("unionid") != null && !accessTokenJsonObject.get("unionid").isJsonNull()) { + accessToken.setUnionId(GsonHelper.getAsString(accessTokenJsonObject.get("unionid"))); + } return accessToken; }