使用crypto实现sha1

This commit is contained in:
Wang Kejun 2023-04-28 14:36:54 +08:00
parent 89498e443e
commit 1b53b4712a
4 changed files with 11 additions and 9 deletions

View File

@ -86,7 +86,7 @@ export declare class WechatPublicInstance {
signatureJsSDK(options: {
url: string;
}): Promise<{
signature: any;
signature: string;
noncestr: string;
timestamp: number;
appId: string;

View File

@ -5,7 +5,6 @@ var tslib_1 = require("tslib");
require('../../fetch');
var crypto_1 = tslib_1.__importDefault(require("crypto"));
var buffer_1 = require("buffer");
var sha1 = require('sha1');
var WechatPublicInstance = /** @class */ (function () {
function WechatPublicInstance(appId, appSecret, accessToken, externalRefreshFn) {
this.appId = appId;
@ -523,7 +522,10 @@ var WechatPublicInstance = /** @class */ (function () {
zhimaString += contentArray[ele];
});
return [2 /*return*/, {
signature: sha1(zhimaString),
signature: crypto_1.default
.createHash('sha1')
.update(zhimaString)
.digest('hex'),
noncestr: noncestr,
timestamp: timestamp,
appId: this.appId,

View File

@ -18,13 +18,11 @@
"@types/node": "^17.0.31",
"ts-node": "~10.9.1",
"tslib": "^2.4.0",
"typescript": "~4.7.4",
"@types/sha1": "^1.1.3"
"typescript": "~4.7.4"
},
"dependencies": {
"@alicloud/pop-core": "^1.7.12",
"isomorphic-fetch": "^3.0.0",
"sha1": "^1.1.1",
"tencentcloud-sdk-nodejs": "^4.0.525",
"ts-md5": "^1.3.1"
}

View File

@ -1,7 +1,6 @@
require('../../fetch');
import crypto from 'crypto';
import { Buffer } from 'buffer';
const sha1 = require('sha1');
// 目前先支持text和news, 其他type文档https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html
// type ServeMessageType = 'text' | 'news' | 'mpnews' | 'mpnewsarticle' | 'image' | 'voice' | 'video' | 'music' | 'msgmenu';/
@ -529,10 +528,13 @@ export class WechatPublicInstance {
zhimaString += contentArray[ele as keyof typeof contentArray];
});
return {
signature: sha1(zhimaString),
signature: crypto
.createHash('sha1')
.update(zhimaString)
.digest('hex'),
noncestr,
timestamp,
appId: this.appId,
};
}
}
}