mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-29 09:38:19 +08:00
🎨 优化部分代码,重构OAuth2网页授权、网页登录等相关接口,方便接入open模块
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
package me.chanjar.weixin.common.bean;
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* oauth2用户个人信息.
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @date 2020-10-11
|
||||
*/
|
||||
@Data
|
||||
public class WxOAuth2UserInfo implements Serializable {
|
||||
private static final long serialVersionUID = 3181943506448954725L;
|
||||
|
||||
/**
|
||||
* openid 普通用户的标识,对当前开发者帐号唯一
|
||||
*/
|
||||
private String openid;
|
||||
/**
|
||||
* nickname 普通用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* sex 普通用户性别,1为男性,2为女性
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* city 普通用户个人资料填写的城市
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* province 普通用户个人资料填写的省份
|
||||
*/
|
||||
private String province;
|
||||
/**
|
||||
* country 国家,如中国为CN
|
||||
*/
|
||||
private String country;
|
||||
/**
|
||||
* headimgurl 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),
|
||||
* 用户没有头像时该项为空
|
||||
*/
|
||||
@SerializedName("headimgurl")
|
||||
private String headImgUrl;
|
||||
/**
|
||||
* unionid 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。
|
||||
*/
|
||||
@SerializedName("unionid")
|
||||
private String unionId;
|
||||
|
||||
/**
|
||||
* privilege 用户特权信息,json数组,如微信沃卡用户为(chinaunicom)
|
||||
*/
|
||||
@SerializedName("privilege")
|
||||
private String[] privileges;
|
||||
|
||||
public static WxOAuth2UserInfo fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxOAuth2UserInfo.class);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package me.chanjar.weixin.common.bean.oauth2;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
@Data
|
||||
public class WxOAuth2AccessToken implements Serializable {
|
||||
private static final long serialVersionUID = -1345910558078620805L;
|
||||
|
||||
@SerializedName("access_token")
|
||||
private String accessToken;
|
||||
|
||||
@SerializedName("expires_in")
|
||||
private int expiresIn = -1;
|
||||
|
||||
@SerializedName("refresh_token")
|
||||
private String refreshToken;
|
||||
|
||||
@SerializedName("openid")
|
||||
private String openId;
|
||||
|
||||
@SerializedName("scope")
|
||||
private String scope;
|
||||
|
||||
/**
|
||||
* https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11513156443eZYea&version=&lang=zh_CN.
|
||||
* 本接口在scope参数为snsapi_base时不再提供unionID字段。
|
||||
*/
|
||||
@SerializedName("unionid")
|
||||
private String unionId;
|
||||
|
||||
public static WxOAuth2AccessToken fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxOAuth2AccessToken.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,5 @@
|
||||
package me.chanjar.weixin.common.util.http;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@ -9,6 +7,8 @@ import me.chanjar.weixin.common.util.http.apache.ApacheSimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.jodd.JoddHttpSimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpSimpleGetRequestExecutor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 简单的GET请求执行器.
|
||||
* 请求的参数是String, 返回的结果也是String
|
||||
@ -27,7 +27,7 @@ public abstract class SimpleGetRequestExecutor<H, P> implements RequestExecutor<
|
||||
handler.handle(this.execute(uri, data, wxType));
|
||||
}
|
||||
|
||||
public static RequestExecutor<String, String> create(RequestHttp requestHttp) {
|
||||
public static RequestExecutor<String, String> create(RequestHttp<?, ?> requestHttp) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new ApacheSimpleGetRequestExecutor(requestHttp);
|
||||
|
||||
Reference in New Issue
Block a user