UNPKG

typed-jd-union-cpsapi

Version:
34 lines 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JdCrypto = void 0; const crypto_1 = __importDefault(require("crypto")); class JdCrypto { //格式化日期成 yyyy-MM-dd HH:mm:ss 格式 static formatTimestamp(date) { //格式化成两位有效数字 const pad = (num) => (num < 10 ? '0' + num : '' + num); return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` + ` ${pad(date.getHours())}:${pad(date.getUTCMinutes())}:${pad(date.getSeconds())}`); } static timestamp() { return JdCrypto.formatTimestamp(new Date()); } static md5(s) { return crypto_1.default.createHash('md5').update(s).digest('hex'); } static sign(secretKey, params) { const sorted = Object.keys(params).sort(); let signStr = secretKey; for (let i = 0, l = sorted.length; i < l; i++) { let k = sorted[i]; signStr += k + params[k]; } signStr += secretKey; return JdCrypto.md5(signStr).toUpperCase(); } } exports.JdCrypto = JdCrypto; //# sourceMappingURL=cryptos.js.map