mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🐛 #1604 修复微信开放平台帐号管理相关接口,使用指定appId的access_token
* fix:修改微信开放平台帐号管理相关接口,使用指定appId的access_token,非开放平台自身的component_access_token
This commit is contained in:
parent
4d1440912d
commit
04fb35d1ba
@ -394,5 +394,17 @@ public class WxConsts {
|
|||||||
public static final String OPERATORDEFAULT = "DEFAULT";
|
public static final String OPERATORDEFAULT = "DEFAULT";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* appId 类型
|
||||||
|
*/
|
||||||
|
public static class AppIdType {
|
||||||
|
/**
|
||||||
|
* 公众号appId类型
|
||||||
|
*/
|
||||||
|
public static final String MP_TYPE = "mp";
|
||||||
|
/**
|
||||||
|
* 小程序appId类型
|
||||||
|
*/
|
||||||
|
public static final String MINI_TYPE = "mini";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,43 +415,47 @@ public interface WxOpenComponentService {
|
|||||||
* 创建 开放平台帐号并绑定公众号/小程序.
|
* 创建 开放平台帐号并绑定公众号/小程序.
|
||||||
* https://api.weixin.qq.com/cgi-bin/open/create
|
* https://api.weixin.qq.com/cgi-bin/open/create
|
||||||
*
|
*
|
||||||
* @param appId 公众号/小程序的appId
|
* @param appId 公众号/小程序的appId
|
||||||
|
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
|
||||||
* @return . wx open create result
|
* @return . wx open create result
|
||||||
* @throws WxErrorException .
|
* @throws WxErrorException .
|
||||||
*/
|
*/
|
||||||
WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException;
|
WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/bind.html
|
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/bind.html
|
||||||
* 将公众号/小程序绑定到开放平台帐号下
|
* 将公众号/小程序绑定到开放平台帐号下
|
||||||
*
|
*
|
||||||
* @param appId 公众号/小程序的appId
|
* @param appId 公众号/小程序的appId
|
||||||
|
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
|
||||||
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
|
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
* @throws WxErrorException the wx error exception
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException;
|
Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/unbind.html
|
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/unbind.html
|
||||||
* 将公众号/小程序从开放平台帐号下解绑
|
* 将公众号/小程序从开放平台帐号下解绑
|
||||||
*
|
*
|
||||||
* @param appId 公众号/小程序的appId
|
* @param appId 公众号/小程序的appId
|
||||||
|
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
|
||||||
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
|
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
* @throws WxErrorException the wx error exception
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException;
|
Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html
|
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html
|
||||||
* 获取公众号/小程序所绑定的开放平台帐号
|
* 获取公众号/小程序所绑定的开放平台帐号
|
||||||
*
|
*
|
||||||
* @param appId 公众号/小程序的appId
|
* @param appId 公众号/小程序的appId
|
||||||
|
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
|
||||||
* @return 开放平台帐号 appid,由创建开发平台帐号接口返回
|
* @return 开放平台帐号 appid,由创建开发平台帐号接口返回
|
||||||
* @throws WxErrorException the wx error exception
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
WxOpenGetResult getOpenAccount(String appId) throws WxErrorException;
|
WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
|
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
|
||||||
|
@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
import me.chanjar.weixin.common.error.WxError;
|
import me.chanjar.weixin.common.error.WxError;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||||
@ -474,47 +475,71 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
|||||||
post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
|
post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信开放平台帐号管理统一请求入口
|
||||||
|
*
|
||||||
|
* @param appId 操作appId 小程序/公众号
|
||||||
|
* @param appIdType 操作类型 小程序/公众号
|
||||||
|
* @param requestUrl 请求地址
|
||||||
|
* @param param 请求参数
|
||||||
|
* @return 请求结果
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
private String openAccountServicePost(String appId, String appIdType, String requestUrl, JsonObject param) throws WxErrorException {
|
||||||
|
String result = "";
|
||||||
|
switch (appIdType) {
|
||||||
|
case WxConsts.AppIdType.MP_TYPE:
|
||||||
|
WxMpService wxMpService = this.getWxMpServiceByAppid(appId);
|
||||||
|
result = wxMpService.post(requestUrl, param.toString());
|
||||||
|
return result;
|
||||||
|
case WxConsts.AppIdType.MINI_TYPE:
|
||||||
|
WxOpenMaService maService = this.getWxMaServiceByAppid(appId);
|
||||||
|
result = maService.post(requestUrl, param.toString());
|
||||||
|
return result;
|
||||||
|
default:
|
||||||
|
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("appIdType类型异常").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException {
|
public WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("appid", appId);
|
param.addProperty("appid", appId);
|
||||||
|
|
||||||
String json = post(CREATE_OPEN_URL, param.toString(), "access_token");
|
String json = openAccountServicePost(appId, appIdType, CREATE_OPEN_URL, param);
|
||||||
|
|
||||||
return WxOpenCreateResult.fromJson(json);
|
return WxOpenCreateResult.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException {
|
public Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("appid", appId);
|
param.addProperty("appid", appId);
|
||||||
param.addProperty("open_appid", openAppid);
|
param.addProperty("open_appid", openAppid);
|
||||||
|
|
||||||
String json = post(BIND_OPEN_URL, param.toString(), "access_token");
|
String json = openAccountServicePost(appId, appIdType, BIND_OPEN_URL, param);
|
||||||
|
|
||||||
return WxOpenResult.fromJson(json).isSuccess();
|
return WxOpenResult.fromJson(json).isSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException {
|
public Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("appid", appId);
|
param.addProperty("appid", appId);
|
||||||
param.addProperty("open_appid", openAppid);
|
param.addProperty("open_appid", openAppid);
|
||||||
|
|
||||||
String json = post(UNBIND_OPEN_URL, param.toString(), "access_token");
|
String json = openAccountServicePost(appId, appIdType, UNBIND_OPEN_URL, param);
|
||||||
|
|
||||||
return WxOpenResult.fromJson(json).isSuccess();
|
return WxOpenResult.fromJson(json).isSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxOpenGetResult getOpenAccount(String appId) throws WxErrorException {
|
public WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("appid", appId);
|
param.addProperty("appid", appId);
|
||||||
|
|
||||||
String json = post(GET_OPEN_URL, param.toString(), "access_token");
|
String json = openAccountServicePost(appId, appIdType, GET_OPEN_URL, param);
|
||||||
return WxOpenGetResult.fromJson(json);
|
return WxOpenGetResult.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user