tools.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. const crypto = require('crypto');
  2. class tools {
  3. constructor(redis_help){
  4. this.redis_help = redis_help
  5. this.isDebug = false
  6. }
  7. init(){
  8. }
  9. distributorId = 1814786227164169;
  10. secretKey = 'CN6KQ8Bauo8JXg5fFPk86EHdRFIUVnyV';
  11. heiyan_config(){
  12. return { //黑岩配置
  13. chang_pian_user:{
  14. userName:"康帅",
  15. password:"Ks25666"
  16. },
  17. duan_pian_user:{
  18. userName:"王海泉",
  19. password:"My20240088"
  20. },
  21. default_user:{
  22. userName:"zhuoyue003",
  23. password:"Xuan2026@123"
  24. },
  25. }
  26. }
  27. unixTimestampToDate = function(timestamp) {
  28. const date = new Date(timestamp * 1000); // Unix时间戳是秒,JavaScript的Date对象需要毫秒
  29. return date.getTime();
  30. }
  31. dateToUnixTimestamp = function (date) {
  32. return Math.floor(date.getTime() / 1000); // 将毫秒转换为秒
  33. }
  34. calculateTimestampDifference = function(timestamp1, timestamp2) {
  35. return Math.abs(timestamp1 - timestamp2);
  36. }
  37. formatUnixTimestamp = function(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
  38. const date = new Date(timestamp * 1000);
  39. const year = date.getFullYear();
  40. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1
  41. const day = String(date.getDate()).padStart(2, '0');
  42. const hours = String(date.getHours()).padStart(2, '0');
  43. const minutes = String(date.getMinutes()).padStart(2, '0');
  44. const seconds = String(date.getSeconds()).padStart(2, '0');
  45. const formattedDate = format
  46. .replace('YYYY', year)
  47. .replace('MM', month)
  48. .replace('DD', day)
  49. .replace('HH', hours)
  50. .replace('mm', minutes)
  51. .replace('ss', seconds);
  52. return formattedDate;
  53. }
  54. getCurrentUnixTimestamp = function() {
  55. return Math.floor(Date.now() / 1000)
  56. }
  57. getCurrentUnixTimestamp = function() {
  58. return Math.floor(Date.now() / 1000)
  59. }
  60. getSign = function(distributorId,secretKey) {
  61. const params = [distributorId, secretKey, tools.getCurrentUnixTimestamp()];
  62. // 将参数数组中的每个元素转换为字符串并连接成一个单一的字符串
  63. const paramStr = params.map(String).join('');
  64. // 使用 MD5 算法生成哈希值
  65. const hash = crypto.createHash('md5');
  66. hash.update(paramStr);
  67. // 返回哈希值的十六进制表示
  68. return hash.digest('hex');
  69. }
  70. setHyToken(token){
  71. this.redis_help.setKeyValue("hei_yan_token",token)
  72. }
  73. async getHyToken (){
  74. return await this.redis_help.getKeyValue("hei_yan_token")
  75. }
  76. getSupdate(){ //插入素材域名
  77. if(this.isDebug){
  78. return 'https://clipvideoup.hainanmlwl.com'
  79. }else{
  80. return 'http://192.168.0.165:9606'
  81. }
  82. }
  83. getDataBaseConfig(){
  84. if(this.isDebug){
  85. return {
  86. host: '127.0.0.1', // 数据库主机名
  87. user: 'root', // 数据库用户名
  88. port: 3306,
  89. password: 'p0LTZh&CjMl2023', // 数据库密码
  90. database: 'ml_oceanengine' // 要连接的数据库名
  91. }
  92. }else{
  93. return {
  94. host: 'mr-dsq824ev2pqxbr6rhw.rwlb.rds.aliyuncs.com', // 数据库主机名
  95. user: 'zdroot', // 数据库用户名
  96. port: 3306,
  97. password: 'p0LTZh&CjMl2023', // 数据库密码
  98. database: 'ml_oceanengine' // 要连接的数据库名
  99. }
  100. }
  101. }
  102. getTaskDataBaseConfig(){
  103. if(this.isDebug){
  104. return {
  105. host: '127.0.0.1', // 数据库主机名
  106. user: 'root', // 数据库用户名
  107. port: 3306,
  108. password: 'p0LTZh&CjMl2023', // 数据库密码
  109. database: 'video_task' // 要连接的数据库名
  110. }
  111. }else{
  112. return {
  113. host: 'mr-dsq824ev2pqxbr6rhw.rwlb.rds.aliyuncs.com', // 数据库主机名
  114. user: 'zdroot', // 数据库用户名
  115. port: 3306,
  116. password: 'p0LTZh&CjMl2023', // 数据库密码
  117. database: 'video_task' // 要连接的数据库名
  118. }
  119. }
  120. }
  121. }
  122. module.exports = new tools(require('./src/use_redis'));