123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- const crypto = require('crypto');
- class tools {
- constructor(redis_help){
- this.redis_help = redis_help
- this.isDebug = false
- }
- init(){
- }
- distributorId = 1814786227164169;
- secretKey = 'CN6KQ8Bauo8JXg5fFPk86EHdRFIUVnyV';
- heiyan_config(){
- return { //黑岩配置
- chang_pian_user:{
- userName:"康帅",
- password:"Ks25666"
- },
- duan_pian_user:{
- userName:"王海泉",
- password:"My20240088"
- },
- default_user:{
- userName:"zhuoyue003",
- password:"Xuan2026@123"
- },
- }
- }
- unixTimestampToDate = function(timestamp) {
- const date = new Date(timestamp * 1000); // Unix时间戳是秒,JavaScript的Date对象需要毫秒
- return date.getTime();
- }
- dateToUnixTimestamp = function (date) {
- return Math.floor(date.getTime() / 1000); // 将毫秒转换为秒
- }
-
- calculateTimestampDifference = function(timestamp1, timestamp2) {
- return Math.abs(timestamp1 - timestamp2);
- }
- formatUnixTimestamp = function(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
- const date = new Date(timestamp * 1000);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- const seconds = String(date.getSeconds()).padStart(2, '0');
-
- const formattedDate = format
- .replace('YYYY', year)
- .replace('MM', month)
- .replace('DD', day)
- .replace('HH', hours)
- .replace('mm', minutes)
- .replace('ss', seconds);
-
- return formattedDate;
- }
- getCurrentUnixTimestamp = function() {
- return Math.floor(Date.now() / 1000)
- }
- getCurrentUnixTimestamp = function() {
- return Math.floor(Date.now() / 1000)
- }
- getSign = function(distributorId,secretKey) {
- const params = [distributorId, secretKey, tools.getCurrentUnixTimestamp()];
- // 将参数数组中的每个元素转换为字符串并连接成一个单一的字符串
- const paramStr = params.map(String).join('');
-
- // 使用 MD5 算法生成哈希值
- const hash = crypto.createHash('md5');
- hash.update(paramStr);
-
- // 返回哈希值的十六进制表示
- return hash.digest('hex');
- }
-
- setHyToken(token){
- this.redis_help.setKeyValue("hei_yan_token",token)
- }
- async getHyToken (){
- return await this.redis_help.getKeyValue("hei_yan_token")
- }
- getSupdate(){ //插入素材域名
- if(this.isDebug){
- return 'https://clipvideoup.hainanmlwl.com'
- }else{
- return 'http://192.168.0.165:9606'
- }
- }
- getDataBaseConfig(){
- if(this.isDebug){
- return {
- host: '127.0.0.1', // 数据库主机名
- user: 'root', // 数据库用户名
- port: 3306,
- password: 'p0LTZh&CjMl2023', // 数据库密码
- database: 'ml_oceanengine' // 要连接的数据库名
- }
- }else{
- return {
- host: 'mr-dsq824ev2pqxbr6rhw.rwlb.rds.aliyuncs.com', // 数据库主机名
- user: 'zdroot', // 数据库用户名
- port: 3306,
- password: 'p0LTZh&CjMl2023', // 数据库密码
- database: 'ml_oceanengine' // 要连接的数据库名
- }
- }
- }
- getTaskDataBaseConfig(){
- if(this.isDebug){
- return {
- host: '127.0.0.1', // 数据库主机名
- user: 'root', // 数据库用户名
- port: 3306,
- password: 'p0LTZh&CjMl2023', // 数据库密码
- database: 'video_task' // 要连接的数据库名
- }
- }else{
- return {
- host: 'mr-dsq824ev2pqxbr6rhw.rwlb.rds.aliyuncs.com', // 数据库主机名
- user: 'zdroot', // 数据库用户名
- port: 3306,
- password: 'p0LTZh&CjMl2023', // 数据库密码
- database: 'video_task' // 要连接的数据库名
- }
- }
- }
- }
- module.exports = new tools(require('./src/use_redis'));
|