收藏
回答

小程序获取手机号出现加签加密后回调信息解密后出现40235错误?

String respData = httpResponse.body(); 在这行代码中获取到了错误信息,我的系统中引入了2个小程序配置,其中加签加密解签解密的逻辑是通用的,另一个小程序的全部是正常的我想知道是不是因为我这个小程序的备案是出于管局审核中,因为是今天上午才通过审核,是不是因为没同步状态导致的。

  "errcode" : 40235,

  "errmsg" : "invalid encrypt rid: 699fdec1-1c547f6d-004689c6"

}


public Object getUserPhoneNumber(String code) {
    // 访问地址
    String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";

    // 进行 加密\加签\发送请求
    HttpResponse httpResponse = sendGetUserPhoneNumber(code, url);

    // 提取响应体中的信息
    if (httpResponse == null) {
        throw new ServiceException(HttpStatusConstants.ERROR, "请求发送失败,请稍后重试");
    }

    // 平台证书签名数据,使用base64编码
    String wechatmpSignature = httpResponse.header("Wechatmp-Signature");
    // 小程序id
    String wechatmpAppid = httpResponse.header("Wechatmp-Appid");
    // 签名时时间戳
    String wechatmpTimeStamp = httpResponse.header("Wechatmp-TimeStamp");
    // 平台证书编号
    String wechatmpSerial = httpResponse.header("Wechatmp-Serial");

    // 即将失效的平台证书编号,非证书内序列号,仅在证书更换周期内出现
    String wechatmpSerialDeprecated = httpResponse.header("Wechatmp-Serial-Deprecated");
    // 即将失效的平台证书签名数据,仅在证书更换周期内出现,使用base64编码
    String wechatmpSignatureDeprecated = httpResponse.header("Wechatmp-Signature-Deprecated");

    // 响应数据
    String respData = httpResponse.body();

    // 加密\加签\发送完成 -> 进行解密\解签\提取信息
    JsonObject resp = new JsonObject();

    // 开放平台证书编号
    resp.addProperty("resp_sn", wechatmpSerial);
    resp.addProperty("resp_sig", wechatmpSignature);
    resp.addProperty("resp_appid", wxSP2Config.getAppId());
    resp.addProperty("resp_ts", wechatmpTimeStamp);
    resp.addProperty("resp_data", respData);

    if (wechatmpSerialDeprecated == null) {
        wechatmpSerialDeprecated = "";
    }
    if (wechatmpSignatureDeprecated == null) {
        wechatmpSignatureDeprecated = "";
    }

    // 如果证书快过期了才会出现这两个
    resp.addProperty("resp_deprecated_sn", wechatmpSerialDeprecated);
    resp.addProperty("resp_deprecated_sig", wechatmpSignatureDeprecated);

    // 校验签名
    boolean check = wxSP2ApiDecryptUtils.check(resp, url);
    if (!check) {
        log.error("微信小程序-验证签名失败!验签失败!");
        throw new ServiceException("请求失败,请稍后再试");
    }

    // 解密
    Object apiResp = wxSP2ApiDecryptUtils.getApiResp(url, Long.parseLong(wechatmpTimeStamp), respData);

    return apiResp;
}


回答关注问题邀请回答
收藏

2 个回答

  • 等待
    等待
    02-26

    已解决!重新生成了api相关秘钥就好了

    02-26
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    02-26
    有用
    回复 2
    • 等待
      等待
      02-26
      02-26
      回复
    • 等待
      等待
      02-26
      getuserphonenumber接口 可以不加密直接调用吗,需要关闭api加密功能吗
      02-26
      回复
登录 后发表内容