tools.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const crypto = require('crypto');
  2. const config = require('./etc/config.json')
  3. class tools {
  4. constructor(redis_help){
  5. this.redis_help = redis_help
  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. return config.isDebug?config.debug_supdate_config:config.release_supdate_config
  78. }
  79. getDataBaseConfig(){
  80. return config.isDebug?config.debug_mysql:config.release_mysql
  81. }
  82. getTaskDataBaseConfig(){
  83. return config.isDebug?config.debug_task_mysql:config.release_task_mysql
  84. }
  85. async getFqSidtt() {
  86. let sidtt = 'b0390e26648a71801795b3b13c9d7d20'
  87. let list = await this.redis_help.getKeyValue("all_fq_key")
  88. if(list == null){
  89. return sidtt
  90. }
  91. list = JSON.parse(list)
  92. if(list.length<=0){
  93. return sidtt
  94. }
  95. sidtt = list[0]
  96. return sidtt.sid_tt
  97. }
  98. }
  99. module.exports = new tools(require('./src/use_redis'));