Compare commits
10 Commits
47da1be839
...
86f8654bbe
| Author | SHA1 | Date | |
|---|---|---|---|
| 86f8654bbe | |||
| 0cb2fce609 | |||
| 09d44fdb5c | |||
| cbd66f7bb0 | |||
|
|
572048be6c | ||
|
|
b63b533b58 | ||
|
|
7f5ee2f774 | ||
|
|
256c797be8 | ||
|
|
10a346ca67 | ||
|
|
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,14 @@ public class WeixinAppFacade {
|
||||
return secCheckApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信手机号相关的 API。
|
||||
*
|
||||
* @return 微信手机号相关的 API。
|
||||
* @since 1.10.0
|
||||
*/
|
||||
public PhoneNumberApi getPhoneNumberApi() {
|
||||
return phoneNumberApi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
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 extends WxaApiResult {
|
||||
|
||||
public static final TypeReference<PhoneInfoResult> TYPE_REFERENCE
|
||||
= new TypeReference<PhoneInfoResult>() {
|
||||
};
|
||||
|
||||
private PhoneInfo phoneInfo;
|
||||
|
||||
@JSONField(name = "phone_info")
|
||||
public PhoneInfo getPhoneInfo() {
|
||||
return phoneInfo;
|
||||
}
|
||||
|
||||
public void setPhoneInfo(PhoneInfo phoneInfo) {
|
||||
this.phoneInfo = phoneInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.wxa.WXBizDataCrypt;
|
||||
import com.foxinmy.weixin4j.wxa.model.phone.PhoneInfo;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 获取微信绑定号码。
|
||||
*
|
||||
* @since 1.10.0
|
||||
*/
|
||||
public class PhoneNumberApi extends TokenManagerApi {
|
||||
|
||||
public PhoneNumberApi(TokenManager tokenManager, Properties properties) {
|
||||
super(tokenManager, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信绑定手机号码
|
||||
* code换取用户手机号。 每个code只能使用一次,code的有效期为5min
|
||||
*
|
||||
* @param code 微信小程序 open-type="getPhoneNumber"
|
||||
* @throws WeixinException code无效或过期
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html"><a/>
|
||||
*/
|
||||
public PhoneInfo getPhoneNumber(String code) throws WeixinException {
|
||||
final PhoneNumberParameter phoneNumberParameter = new PhoneNumberParameter(code);
|
||||
PhoneInfoResult phoneInfoResult = this.post(
|
||||
"wxa_get_user_phone",
|
||||
phoneNumberParameter,
|
||||
PhoneInfoResult.TYPE_REFERENCE
|
||||
);
|
||||
phoneInfoResult.checkErrCode();
|
||||
return phoneInfoResult.getPhoneInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 encryptedData 中解析 PhoneInfo
|
||||
*
|
||||
* @param appId 小程序 appId
|
||||
* @param sessionKey wx.login 获取
|
||||
* @param encryptedData 密文
|
||||
* @param iv 加密方式
|
||||
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/deprecatedGetPhoneNumber.html"></a>
|
||||
*/
|
||||
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,21 @@
|
||||
package com.foxinmy.weixin4j.wxa.api;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PhoneNumberParameter implements Serializable {
|
||||
|
||||
private String code;
|
||||
|
||||
public PhoneNumberParameter(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
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,30 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user