'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;
}
验证签名工具:
链接:https://pan.baidu.com/s/1ixOAnYyZVW13dFr0jWVpvw 提取码:wujv
,麻烦使用V3签名验证工具参考V3签名文档https://wechatpay-api.gitbook.io/wechatpay-api-v3/
进行排查修改。V3签名需使用apiv3秘钥。麻烦参考https://kf.qq.com/faq/180830E36vyQ180830AZFZvu.html