CUtil.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import MMD5 from "./MMD5";
  2. export default class CUtil{
  3. private static md5:MMD5 = new MMD5();
  4. /**
  5. * 给消息添加签名
  6. * @param msg
  7. * @param token
  8. */
  9. public static makeSign(msg,token):string {
  10. let date = new Date();
  11. msg.timestamp = date.getTime();
  12. let keys = Object.keys(msg).sort();
  13. var str = '';
  14. for(let id in keys){
  15. let key = keys[id];
  16. let value = msg[key];
  17. if(value == undefined || value instanceof Object){
  18. }else{
  19. str += key+"="+value + '&';
  20. }
  21. }
  22. str += token;
  23. // cc.log('content : '+str);
  24. msg.sign = this.md5.hex_md5(str);
  25. return msg;
  26. }
  27. public static getNowTime() {
  28. let d = new Date();
  29. return Math.floor(d.getTime()/1000);
  30. }
  31. public static getNowDateInt() {
  32. let d = new Date();
  33. let curr_date = '' + d.getDate();
  34. let curr_month = '' + (d.getMonth() + 1);
  35. let curr_year = '' + d.getFullYear();
  36. if (curr_month.length < 2) {
  37. curr_month = '0' + curr_month;
  38. }
  39. if (curr_date.length < 2) {
  40. curr_date = '0' + curr_date;
  41. }
  42. var yyyyMMdd = curr_year + curr_month + curr_date;
  43. return parseInt(yyyyMMdd);
  44. }
  45. }