problem description
the original Mini Program is bound under the first third-party platform of Wechat open platform, but now the number of Mini Program bindings of the first third-party platform has reached the upper limit, so a second third-party platform has been created under the same open platform. How to change the code so that Mini Program, who is bound to the first open platform, can still work properly, and then Mini Program, who is bound to the second open platform, can also authorize the operation?
the environmental background of the problems and what methods you have tried
Environment background: Mini Program bound to a third-party platform is
under different principals. Try method: change the appsecret and appid of the bound third-party platform in the code to the second third-party platform. As a result, Wechat returns the pre-authorization code is illegal, and Wechat authorizes the callback API to indicate that appid is illegal
related codes
/ / Please paste the code text below (do not replace the code with pictures)
/ / this is the API for obtaining preauthorization codes
public static void acquireComponentAccessToken () {
String appid = PROP.get("wx.open.appid");
String appsecret = PROP.get("wx.open.appsecret");
String componentVerifyTicket = DecryptedComponentVerifyTicket.getInstance().getComponentVerifyTicket();
Map<String, String> params = new HashMap<>();
params.put("component_appid", appid);
params.put("component_appsecret", appsecret);
params.put("component_verify_ticket", componentVerifyTicket);
String json = null;
try {
json = om.writeValueAsString(params);
} catch (JsonProcessingException e) {}
String resp = HttpKit.post(ACQUIRE_COMPONENT_ACCESS_TOKEN_URL, json);
// LOG.info("(WXOPEN) JSON: " + json);
LOG.info("(WXOPEN) ACQUIRE_COMPONENT_ACCESS_TOKEN: " + resp);
Map<String, Object> map = null;
try {
map = om.readValue(resp, Map.class);
} catch (IOException e) {}
ComponentAccessToken componentAccessToken = ComponentAccessToken.getInstance();
componentAccessToken.setComponentAccessToken((String) map.get("component_access_token"));
componentAccessToken.setExpiresIn((Integer) map.get("expires_in"));
componentAccessToken.setRefleshTime(new Date());
}
//
public void index() {
log.info("notify");
// component_verify_ticket
EncryptedComponentVerifyTicket ticket = new EncryptedComponentVerifyTicket();
wirePropertyFromRequest(ticket);
// log.info("(WXOPEN) ticket: " + ticket);
try {
AuthorizerAccessTokenUtil.decrypt(ticket);
} catch (AesException e) {
log.error(":" + e.getMessage());
}
// component_access_token
if (ComponentAccessToken.isExpired()) {
AuthorizerAccessTokenUtil.acquireComponentAccessToken();
}
log.info("");
// `wx_miniapp_auth`10min
List<WXMiniappAuth> miniappAuthList = WXMiniappAuth.dao.list();
AuthorizerAccessTokenUtil.refreshAuthorizerAccessToken(miniappAuthList);
renderText("success");
}
what result do you expect? What is the error message actually seen?
expected result: the second open platform can also authorize the successful new Mini Program
error message: Wechat returned illegal pre-authorization code, Wechat authorized callback API indicates that appid is illegal