new package wxa.model.phone
This commit is contained in:
parent
8d96e3c46f
commit
10a346ca67
@ -1,15 +1,14 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
|
||||
import java.io.Serializable;
|
||||
import com.foxinmy.weixin4j.wxa.model.phone.PhoneInfo;
|
||||
|
||||
/**
|
||||
* get phone number result
|
||||
*
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html"><a/>
|
||||
*/
|
||||
public class PhoneInfoResult implements Serializable {
|
||||
public class PhoneInfoResult extends WxaApiResult {
|
||||
|
||||
public static final TypeReference<PhoneInfoResult> TYPE_REFERENCE
|
||||
= new TypeReference<PhoneInfoResult>() {
|
||||
@ -25,82 +24,4 @@ public class PhoneInfoResult implements Serializable {
|
||||
this.phoneInfo = phoneInfo;
|
||||
}
|
||||
|
||||
public static class PhoneInfo implements Serializable {
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String purePhoneNumber;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
private Watermark watermark;
|
||||
|
||||
/**
|
||||
* @return 用户绑定的手机号(国外手机号会有区号)
|
||||
*/
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 没有区号的手机号
|
||||
*/
|
||||
public String getPurePhoneNumber() {
|
||||
return purePhoneNumber;
|
||||
}
|
||||
|
||||
public void setPurePhoneNumber(String purePhoneNumber) {
|
||||
this.purePhoneNumber = purePhoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 区号
|
||||
*/
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 数据水印
|
||||
*/
|
||||
public Watermark getWatermark() {
|
||||
return watermark;
|
||||
}
|
||||
|
||||
public void setWatermark(Watermark watermark) {
|
||||
this.watermark = watermark;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Watermark implements Serializable {
|
||||
|
||||
private String appId;
|
||||
|
||||
private Long timestamp;
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.wxa.WXBizDataCrypt;
|
||||
import com.foxinmy.weixin4j.wxa.model.phone.PhoneInfo;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class PhoneNumberApi extends TokenManagerApi {
|
||||
|
||||
public PhoneNumberApi(TokenManager tokenManager) {
|
||||
super(tokenManager);
|
||||
}
|
||||
|
||||
public PhoneNumberApi(TokenManager tokenManager, Properties properties) {
|
||||
super(tokenManager, properties);
|
||||
}
|
||||
@ -21,15 +20,30 @@ public class PhoneNumberApi extends TokenManagerApi {
|
||||
*
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html"><a/>
|
||||
*/
|
||||
public PhoneInfoResult.PhoneInfo getPhoneNumber(String code) throws WeixinException {
|
||||
public PhoneInfo getPhoneNumber(String code) throws WeixinException {
|
||||
String wxaGetUserPhone = getRequestUri(
|
||||
"wxa_get_user_phone",
|
||||
code,
|
||||
WxaApiResult.TYPE_REFERENCE
|
||||
);
|
||||
WeixinResponse post = this.weixinExecutor.post(wxaGetUserPhone);
|
||||
return post.getAsObject(PhoneInfoResult.TYPE_REFERENCE)
|
||||
.getPhoneInfo();
|
||||
PhoneInfoResult phoneInfoResult = post.getAsObject(PhoneInfoResult.TYPE_REFERENCE);
|
||||
phoneInfoResult.checkErrCode();
|
||||
return phoneInfoResult.getPhoneInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 encryptedData 中解析 PhoneInfo
|
||||
*/
|
||||
public PhoneInfo parsePhoneNumber(
|
||||
String appId,
|
||||
String sessionKey,
|
||||
String encryptedData,
|
||||
String iv
|
||||
) {
|
||||
WXBizDataCrypt wxBizDataCrypt = new WXBizDataCrypt(appId, sessionKey);
|
||||
JSONObject jsonObject = wxBizDataCrypt.decryptData(encryptedData, iv);
|
||||
return JSONObject.toJavaObject(jsonObject, PhoneInfo.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package com.foxinmy.weixin4j.wxa.model.phone;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PhoneInfo implements Serializable {
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String purePhoneNumber;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
private Watermark watermark;
|
||||
|
||||
/**
|
||||
* @return 用户绑定的手机号(国外手机号会有区号)
|
||||
*/
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 没有区号的手机号
|
||||
*/
|
||||
public String getPurePhoneNumber() {
|
||||
return purePhoneNumber;
|
||||
}
|
||||
|
||||
public void setPurePhoneNumber(String purePhoneNumber) {
|
||||
this.purePhoneNumber = purePhoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 区号
|
||||
*/
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 数据水印
|
||||
*/
|
||||
public Watermark getWatermark() {
|
||||
return watermark;
|
||||
}
|
||||
|
||||
public void setWatermark(Watermark watermark) {
|
||||
this.watermark = watermark;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.foxinmy.weixin4j.wxa.model.phone;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Watermark implements Serializable {
|
||||
|
||||
private String appId;
|
||||
|
||||
private Long timestamp;
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user