12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import MMD5 from "./MMD5";
- export default class CUtil{
- private static md5:MMD5 = new MMD5();
- /**
- * 给消息添加签名
- * @param msg
- * @param token
- */
- public static makeSign(msg,token):string {
- let date = new Date();
- msg.timestamp = date.getTime();
- let keys = Object.keys(msg).sort();
- var str = '';
- for(let id in keys){
- let key = keys[id];
- let value = msg[key];
- if(value == undefined || value instanceof Object){
- }else{
- str += key+"="+value + '&';
- }
- }
- str += token;
- // cc.log('content : '+str);
- msg.sign = this.md5.hex_md5(str);
- return msg;
- }
- public static getNowTime() {
- let d = new Date();
- return Math.floor(d.getTime()/1000);
- }
- public static getNowDateInt() {
- let d = new Date();
- let curr_date = '' + d.getDate();
- let curr_month = '' + (d.getMonth() + 1);
- let curr_year = '' + d.getFullYear();
- if (curr_month.length < 2) {
- curr_month = '0' + curr_month;
- }
- if (curr_date.length < 2) {
- curr_date = '0' + curr_date;
- }
- var yyyyMMdd = curr_year + curr_month + curr_date;
- return parseInt(yyyyMMdd);
- }
- }
|