收藏
回答

签名信息错误,验签失败

'request-id': '08D799FEFC0510DA071885CBEEA30620F26028FBBA04-270924360',

{

  data: { code: 'SIGN_ERROR', message: ' 签名信息错误,验签失败' },

  status: 401,

  headers: {

    server: 'nginx',

    date: 'Mon, 02 Nov 2020 04:36:39 GMT',

    'content-type': 'application/json; charset=utf-8',

    'content-length': '68',

    connection: 'keep-alive',

    'keep-alive': 'timeout=8',

    'cache-control': 'no-cache, must-revalidate',

    'x-content-type-options': 'nosniff',

    'request-id': '08D799FEFC0510DA071885CBEEA30620F26028FBBA04-270924360',

    'content-language': 'zh-CN'

  },

  res: {

    status: 401,

    statusCode: 401,

    statusMessage: 'Unauthorized',

    headers: {

      server: 'nginx',

      date: 'Mon, 02 Nov 2020 04:36:39 GMT',

      'content-type': 'application/json; charset=utf-8',

      'content-length': '68',

      connection: 'keep-alive',

      'keep-alive': 'timeout=8',

      'cache-control': 'no-cache, must-revalidate',

      'x-content-type-options': 'nosniff',

      'request-id': '08D799FEFC0510DA071885CBEEA30620F26028FBBA04-270924360',

      'content-language': 'zh-CN'

    },

    size: 68,

    aborted: false,

    rt: 120,

    keepAliveSocket: false,

    data: { code: 'SIGN_ERROR', message: ' 签名信息错误,验签失败' },

    requestUrls: [ 'https://api.mch.weixin.qq.com/v3/certificates' ],

    timing: null,

    remoteAddress: '123.126.122.46',

    remotePort: 443,

    socketHandledRequests: 1,

    socketHandledResponses: 1

  }

}

 async signature(option) {

        const { message, privateKey = apiPrivateKey } = option;

        const signature = crypto

        .createSign(sha256WithRSAEncryption)

        .update(message)

        .sign(privateKey, 'base64')

        return signature;

    }


async authorization(option) {

        const { ctx, logger } = this;

        const _ = ctx.helper.lodash;

        const getUUID = ctx.helper.getUUID;

        let { method, api, body, rondomStr = getUUID(32).toUpperCase(), timestamp = parseInt(( new Date().valueOf() + 60 * 1000)/ 1000), serialNo = certSerialNumber } = option;

        const message = `${method}\\n${api}\\n${timestamp}\\n${rondomStr}\\n${_.isEmpty(body) ? "" : JSON.stringify(body)}\\n`;

        const signature = await this.signature({ message });

        const authorization = `WECHATPAY2-SHA256-RSA2048 mchid="${mchId}",nonce_str="${rondomStr}",signature="${signature}",timestamp="${timestamp}",serial_no="${serialNo}"`;

        logger.info('authorization str',authorization);

        return authorization;

    }



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

1 个回答

登录 后发表内容
问题标签