How does Mini Program, who is bound to different third-party platforms under the same Wechat open platform, authorize the operation at the same time?

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


you may want the database to record which open platform the authorized Mini Program belongs to, and determine which third-party open platform appsecret and appid are used according to the binding information recorded in the database.

Authorization callback configuration: first third party: / callback/xxx/1. The second third party: / callback/xxx/2, matches the corresponding third-party platform information in the database according to the following numbers, and then obtains it.

for example, there is a third_party_platform table that records information about third-party platforms

I don't know if you are caused by two third-party platforms using the same callback address.

Menu