TonyLuo 2018-08-20 12:03:44 +08:00 committed by Binary Wang
parent 93b27351a0
commit 9cdff1d010
2 changed files with 19 additions and 1 deletions

View File

@ -53,6 +53,12 @@ public interface WxOpenComponentService {
* 获取用户授权页URL来路URL和成功跳转URL 的域名都需要为三方平台设置的 登录授权的发起页域名
*/
String getPreAuthUrl(String redirectURI) throws WxErrorException;
/**
* authType 要授权的帐号类型1则商户点击链接后手机端仅展示公众号2表示仅展示小程序3表示公众号和小程序都展示如果为未指定则默认小程序和公众号都展示第三方平台开发者可以使用本字段来控制授权的帐号类型
* bizAppid 指定授权唯一的小程序或公众号
* auth_typebiz_appid两个字段互斥
*/
String getPreAuthUrl(String redirectURI,String authType, String bizAppid) throws WxErrorException;
String route(WxOpenXmlMessage wxMessage) throws WxErrorException;

View File

@ -177,14 +177,26 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public String getPreAuthUrl(String redirectURI) throws WxErrorException {
return getPreAuthUrl(redirectURI,null, null);
}
@Override
public String getPreAuthUrl(String redirectURI,String authType, String bizAppid) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
String responseContent = post(API_CREATE_PREAUTHCODE_URL, jsonObject.toString());
jsonObject = WxGsonBuilder.create().fromJson(responseContent, JsonObject.class);
return String.format(COMPONENT_LOGIN_PAGE_URL, getWxOpenConfigStorage().getComponentAppId(), jsonObject.get("pre_auth_code").getAsString(), URIUtil.encodeURIComponent(redirectURI));
String preAuthUrl = String.format(COMPONENT_LOGIN_PAGE_URL, getWxOpenConfigStorage().getComponentAppId(), jsonObject.get("pre_auth_code").getAsString(), URIUtil.encodeURIComponent(redirectURI));
if(StringUtils.isNotEmpty(authType)){
preAuthUrl = preAuthUrl + "&auth_type=" + authType;
}
if(StringUtils.isNotEmpty(bizAppid)){
preAuthUrl = preAuthUrl + "&biz_appid=" + bizAppid;
}
return preAuthUrl;
}
@Override
public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException {
if (wxMessage == null) {