add phoneNumberApi
This commit is contained in:
parent
47da1be839
commit
8d96e3c46f
@ -1,7 +1,5 @@
|
||||
package com.foxinmy.weixin4j.wxa;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.cache.FileCacheStorager;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
@ -9,13 +7,9 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.wxa.api.CustomMessageApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.LoginApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.QrCodeApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.SecCheckApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.TemplateApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.TemplateMessageApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.SubscribeMessageApi;
|
||||
import com.foxinmy.weixin4j.wxa.api.*;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The facade of WeChat Mini Program APIs.
|
||||
@ -31,6 +25,7 @@ public class WeixinAppFacade {
|
||||
private final CustomMessageApi customMessageApi;
|
||||
private final SecCheckApi secCheckApi;
|
||||
private final SubscribeMessageApi subscribeMessageApi;
|
||||
private final PhoneNumberApi phoneNumberApi;
|
||||
|
||||
/**
|
||||
* Constructs {@link WeixinAppFacade} using {@link FileCacheStorager}.
|
||||
@ -69,7 +64,7 @@ public class WeixinAppFacade {
|
||||
*
|
||||
* @param weixinAccount the {@link WeixinAccount}.
|
||||
* @param cacheStorager the {@link CacheStorager}.
|
||||
* @param properties properties to overrides the properties defined in {@code weixin.properties}.
|
||||
* @param properties properties to overrides the properties defined in {@code weixin.properties}.
|
||||
*/
|
||||
public WeixinAppFacade(
|
||||
WeixinAccount weixinAccount,
|
||||
@ -114,6 +109,7 @@ public class WeixinAppFacade {
|
||||
this.customMessageApi = new CustomMessageApi(tokenManager, properties);
|
||||
this.secCheckApi = new SecCheckApi(tokenManager, properties);
|
||||
this.subscribeMessageApi = new SubscribeMessageApi(tokenManager, properties);
|
||||
this.phoneNumberApi = new PhoneNumberApi(tokenManager, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,4 +176,13 @@ public class WeixinAppFacade {
|
||||
return secCheckApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信手机号相关的 API。
|
||||
*
|
||||
* @return 微信手机号相关的 API。
|
||||
* @since 1.10
|
||||
*/
|
||||
public PhoneNumberApi getPhoneNumberApi() {
|
||||
return phoneNumberApi;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,106 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 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 static final TypeReference<PhoneInfoResult> TYPE_REFERENCE
|
||||
= new TypeReference<PhoneInfoResult>() {
|
||||
};
|
||||
|
||||
private PhoneInfo phoneInfo;
|
||||
|
||||
public PhoneInfo getPhoneInfo() {
|
||||
return phoneInfo;
|
||||
}
|
||||
|
||||
public void setPhoneInfo(PhoneInfo phoneInfo) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class PhoneNumberApi extends TokenManagerApi {
|
||||
|
||||
public PhoneNumberApi(TokenManager tokenManager) {
|
||||
super(tokenManager);
|
||||
}
|
||||
|
||||
public PhoneNumberApi(TokenManager tokenManager, Properties properties) {
|
||||
super(tokenManager, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信绑定手机号码
|
||||
*
|
||||
* @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 {
|
||||
String wxaGetUserPhone = getRequestUri(
|
||||
"wxa_get_user_phone",
|
||||
code,
|
||||
WxaApiResult.TYPE_REFERENCE
|
||||
);
|
||||
WeixinResponse post = this.weixinExecutor.post(wxaGetUserPhone);
|
||||
return post.getAsObject(PhoneInfoResult.TYPE_REFERENCE)
|
||||
.getPhoneInfo();
|
||||
}
|
||||
|
||||
}
|
||||
@ -55,3 +55,6 @@ wxa_media_check_async={api_wxa_url}/media_check_async?access_token=%s
|
||||
|
||||
# msgSecCheck
|
||||
wxa_msg_sec_check={api_wxa_url}/msg_sec_check?access_token=%s
|
||||
|
||||
# getuserphonenumber
|
||||
wxa_get_user_phone={api_wxa_url}/business/getuserphonenumber?access_token=%s&code=%s
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user