使用crypto实现sha1
This commit is contained in:
parent
89498e443e
commit
1b53b4712a
|
|
@ -86,7 +86,7 @@ export declare class WechatPublicInstance {
|
||||||
signatureJsSDK(options: {
|
signatureJsSDK(options: {
|
||||||
url: string;
|
url: string;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
signature: any;
|
signature: string;
|
||||||
noncestr: string;
|
noncestr: string;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
appId: string;
|
appId: string;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ var tslib_1 = require("tslib");
|
||||||
require('../../fetch');
|
require('../../fetch');
|
||||||
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
||||||
var buffer_1 = require("buffer");
|
var buffer_1 = require("buffer");
|
||||||
var sha1 = require('sha1');
|
|
||||||
var WechatPublicInstance = /** @class */ (function () {
|
var WechatPublicInstance = /** @class */ (function () {
|
||||||
function WechatPublicInstance(appId, appSecret, accessToken, externalRefreshFn) {
|
function WechatPublicInstance(appId, appSecret, accessToken, externalRefreshFn) {
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
|
|
@ -523,7 +522,10 @@ var WechatPublicInstance = /** @class */ (function () {
|
||||||
zhimaString += contentArray[ele];
|
zhimaString += contentArray[ele];
|
||||||
});
|
});
|
||||||
return [2 /*return*/, {
|
return [2 /*return*/, {
|
||||||
signature: sha1(zhimaString),
|
signature: crypto_1.default
|
||||||
|
.createHash('sha1')
|
||||||
|
.update(zhimaString)
|
||||||
|
.digest('hex'),
|
||||||
noncestr: noncestr,
|
noncestr: noncestr,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
appId: this.appId,
|
appId: this.appId,
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,11 @@
|
||||||
"@types/node": "^17.0.31",
|
"@types/node": "^17.0.31",
|
||||||
"ts-node": "~10.9.1",
|
"ts-node": "~10.9.1",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "~4.7.4",
|
"typescript": "~4.7.4"
|
||||||
"@types/sha1": "^1.1.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alicloud/pop-core": "^1.7.12",
|
"@alicloud/pop-core": "^1.7.12",
|
||||||
"isomorphic-fetch": "^3.0.0",
|
"isomorphic-fetch": "^3.0.0",
|
||||||
"sha1": "^1.1.1",
|
|
||||||
"tencentcloud-sdk-nodejs": "^4.0.525",
|
"tencentcloud-sdk-nodejs": "^4.0.525",
|
||||||
"ts-md5": "^1.3.1"
|
"ts-md5": "^1.3.1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
require('../../fetch');
|
require('../../fetch');
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
const sha1 = require('sha1');
|
|
||||||
|
|
||||||
// 目前先支持text和news, 其他type文档:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html
|
// 目前先支持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';/
|
// 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];
|
zhimaString += contentArray[ele as keyof typeof contentArray];
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
signature: sha1(zhimaString),
|
signature: crypto
|
||||||
|
.createHash('sha1')
|
||||||
|
.update(zhimaString)
|
||||||
|
.digest('hex'),
|
||||||
noncestr,
|
noncestr,
|
||||||
timestamp,
|
timestamp,
|
||||||
appId: this.appId,
|
appId: this.appId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue