Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

add unionid #252

Merged
merged 1 commit into from
Dec 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +16,8 @@ public class WxMpOAuth2AccessToken implements Serializable {

private String scope;

private String unionId;

public String getRefreshToken() {
return refreshToken;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -68,6 +78,7 @@ public String toString() {
", refreshToken='" + refreshToken + '\'' +
", openId='" + openId + '\'' +
", scope='" + scope + '\'' +
", unionId='" + unionId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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<WxMpOAuth2AccessToken> {

public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
Expand All @@ -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;
}

Expand Down