Blame view

src/utils/utils.js 5.8 KB
5e52ed7c   刘淇   个人中心
1
2
3
4
5
6
7
8
9
10
11
12
  import md5 from "./md5.min.js";
  var myCommonSalt = function(val) { // 获取盐值
    let len = parseInt(val);
    let $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
    let maxPos = $chars.length;
    var pwd = "";
    for (var i = 0; i < len; i++) {
      pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    console.log(pwd);
    return pwd;
  };
0c49c87e   liuqimichale   微信公众号 初始化
13
  export default {
5e52ed7c   刘淇   个人中心
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    myCommonSalt,
    formatDate: function(secs, type = 0) {         //type是可选参数,因为json中时间的格式是year-month-date,不能识别XX年XX月XX日
      var t = new Date(secs);
      var year = t.getFullYear();
      var month = t.getMonth() + 1;
      if (month < 10) {
        month = "0" + month;
      }
      var date = t.getDate();
      if (date < 10) {
        date = "0" + date;
      }
      var hour = t.getHours();
      if (hour < 10) {
        hour = "0" + hour;
      }
      var minute = t.getMinutes();
      if (minute < 10) {
        minute = "0" + minute;
      }
      var second = t.getSeconds();
      if (second < 10) {
        second = "0" + second;
      }
      if (type == 0) {
        return year + "年" + month + "月" + date + "日";
      } else {
        return year + "-" + month + "-" + date;
0c49c87e   liuqimichale   微信公众号 初始化
42
      }
0c49c87e   liuqimichale   微信公众号 初始化
43
    },
5e52ed7c   刘淇   个人中心
44
    timestampToTime: function(timestamp) {
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
45
      var d = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
5e52ed7c   刘淇   个人中心
46
47
      var youWant = d.getFullYear() + "-" + this.completedString(d.getMonth() + 1) + "-" + this.completedString(d.getDate());
      return youWant;
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
48
    },
5e52ed7c   刘淇   个人中心
49
50
    completedString: function(s) {
      return s < 10 ? "0" + s : s;
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
51
    },
5e52ed7c   刘淇   个人中心
52
53
    dateFormat: function(msd) {  // 时间转换
      var time = msd;
0c49c87e   liuqimichale   微信公众号 初始化
54
      if (null != time && "" != time) {
0c49c87e   liuqimichale   微信公众号 初始化
55
        if (time > 60 && time < 60 * 60) {
0c49c87e   liuqimichale   微信公众号 初始化
56
          time = parseInt(time / 60.0) + "分钟" + parseInt((parseFloat(time / 60.0) -
0c49c87e   liuqimichale   微信公众号 初始化
57
            parseInt(time / 60.0)) * 60) + "秒";
0c49c87e   liuqimichale   微信公众号 初始化
58
        }
0c49c87e   liuqimichale   微信公众号 初始化
59
        else if (time >= 60 * 60 && time < 60 * 60 * 24) {
0c49c87e   liuqimichale   微信公众号 初始化
60
          time = parseInt(time / 3600.0) + "小时" + parseInt((parseFloat(time / 3600.0) -
0c49c87e   liuqimichale   微信公众号 初始化
61
            parseInt(time / 3600.0)) * 60) + "分钟" +
0c49c87e   liuqimichale   微信公众号 初始化
62
            parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
0c49c87e   liuqimichale   微信公众号 初始化
63
              parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";
0c49c87e   liuqimichale   微信公众号 初始化
64
        } else if (time >= 60 * 60 * 24) {
0c49c87e   liuqimichale   微信公众号 初始化
65
          time = parseInt(time / 3600.0 / 24) + "天" + parseInt((parseFloat(time / 3600.0 / 24) -
0c49c87e   liuqimichale   微信公众号 初始化
66
            parseInt(time / 3600.0 / 24)) * 24) + "小时" + parseInt((parseFloat(time / 3600.0) -
0c49c87e   liuqimichale   微信公众号 初始化
67
            parseInt(time / 3600.0)) * 60) + "分钟" +
0c49c87e   liuqimichale   微信公众号 初始化
68
            parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
0c49c87e   liuqimichale   微信公众号 初始化
69
              parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";
0c49c87e   liuqimichale   微信公众号 初始化
70
        }
0c49c87e   liuqimichale   微信公众号 初始化
71
        else {
0c49c87e   liuqimichale   微信公众号 初始化
72
          time = parseInt(time) + "秒";
0c49c87e   liuqimichale   微信公众号 初始化
73
        }
0c49c87e   liuqimichale   微信公众号 初始化
74
      }
0c49c87e   liuqimichale   微信公众号 初始化
75
76
      return time;
    },
6ea1f7ef   刘淇   个人中心
77
  
5e52ed7c   刘淇   个人中心
78
    clientBrowser: function() { // 判断客户端
0c49c87e   liuqimichale   微信公众号 初始化
79
80
      if (/MicroMessenger/.test(window.navigator.userAgent)) {
        console.log("微信客户端");
5e52ed7c   刘淇   个人中心
81
        return "微信";
0c49c87e   liuqimichale   微信公众号 初始化
82
83
      } else if (/AlipayClient/.test(window.navigator.userAgent)) {
        console.log("支付宝客户端");
5e52ed7c   刘淇   个人中心
84
        return "支付宝";
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
85
86
      } else if (/BankabciPhone/.test(window.navigator.userAgent)) {
        console.log("农行客户端");
5e52ed7c   刘淇   个人中心
87
88
        return "立即";
      } else if (/BankabcAndroid/.test(window.navigator.userAgent)) {
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
89
        console.log("农行客户端");
5e52ed7c   刘淇   个人中心
90
91
        return "立即";
      } else {
0c49c87e   liuqimichale   微信公众号 初始化
92
        console.log("其他浏览器");
5e52ed7c   刘淇   个人中心
93
        return "支付宝";
0c49c87e   liuqimichale   微信公众号 初始化
94
95
      }
    },
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
96
    // 1:支付宝 2:微信 3:银联 10:H5   4微信公众号   34 农行
5e52ed7c   刘淇   个人中心
97
    clientBrowsePayType: function() { // 判断客户端
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
98
99
      if (/MicroMessenger/.test(window.navigator.userAgent)) {
        console.log("微信客户端");
5e52ed7c   刘淇   个人中心
100
        return "4";
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
101
102
      } else if (/AlipayClient/.test(window.navigator.userAgent)) {
        console.log("支付宝客户端");
5e52ed7c   刘淇   个人中心
103
        return "1";
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
104
105
      } else if (/BankabciPhone/.test(window.navigator.userAgent)) {
        console.log("农行客户端");
5e52ed7c   刘淇   个人中心
106
107
        return "34";
      } else if (/BankabcAndroid/.test(window.navigator.userAgent)) {
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
108
        console.log("农行客户端");
5e52ed7c   刘淇   个人中心
109
110
        return "34";
      } else {
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
111
        console.log("其他浏览器");
5e52ed7c   刘淇   个人中心
112
        return "1";
bb951693   liuqimichale   赤峰微信公众号 -- 临停支付
113
114
      }
    },
5e52ed7c   刘淇   个人中心
115
116
117
    myVarAppid: "ud8yq5tv0inxupc05xfeau39jywlqoj2",// 公共请求Appid
    myDeviceInfo: "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E", // 公共请求设备信息
    myVxAppId: "wx1489e48e6a547023",
6ea1f7ef   刘淇   个人中心
118
119
    userToken:localStorage.getItem('userToken'),
    userPhoneNum:localStorage.getItem('userPhoneNum'),
94a4ee91   刘淇   宣化 聚合支付
120
121
122
    // openId: "oWw3o5rY_bFsiT_nFd2CEQWGZfhs",
  
    openId:localStorage.getItem('openId'),
5e52ed7c   刘淇   个人中心
123
    myOrgId: "10120", // 归属地 赤峰id  10003    黄石 10079
6ea1f7ef   刘淇   个人中心
124
  
834a2f37   刘淇   宣化 临停补缴 聚合支付
125
126
127
  
    xuanhuaAppid:'00276515',
    commonTerminalSource:'7',
6ea1f7ef   刘淇   个人中心
128
129
130
    // myVxAppId: 'wx1489e48e6a547023',
    signObject: function(jsonObj) { //签名字段
      jsonObj.sign_type = "md5";
834a2f37   刘淇   宣化 临停补缴 聚合支付
131
      jsonObj.app_id = "lrpo55tmveqe07w3gpovzgx34pdez7eh";
6ea1f7ef   刘淇   个人中心
132
133
      jsonObj.deviceInfo = "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E";
      jsonObj.salt = myCommonSalt(32);
94a4ee91   刘淇   宣化 聚合支付
134
135
      jsonObj.token = localStorage.getItem('userToken');
      // jsonObj.token = 'e3b5417a987641219efb8dc1f8b5fbce'  // 为了测试
6d13a003   刘淇   会员卡聚合支付
136
  
6ea1f7ef   刘淇   个人中心
137
138
139
140
141
142
143
144
145
      let sort = [];
      for (let k in jsonObj) {
        sort.push({
          keyname: k,
          value: jsonObj[k]
        });
      }
      return this.myGetSign(sort);
    },
5e52ed7c   刘淇   个人中心
146
147
    myGetSign: function(objb) { // 获取签名
      var compare = function(obj1, obj2) {
0c49c87e   liuqimichale   微信公众号 初始化
148
149
150
151
152
153
154
155
156
        var val1 = obj1.keyname;
        var val2 = obj2.keyname;
        if (val1 < val2) {
          return -1;
        } else if (val1 > val2) {
          return 1;
        } else {
          return 0;
        }
5e52ed7c   刘淇   个人中心
157
      };
0c49c87e   liuqimichale   微信公众号 初始化
158
      objb.sort(compare);
834a2f37   刘淇   宣化 临停补缴 聚合支付
159
      var strmd5 = "gz8wfwd0gn1etamjjhzey1ggcz78pfvd";
5e52ed7c   刘淇   个人中心
160
161
162
      for (var i = 0; i < objb.length; i++) {
        if (objb[i].value != null && objb[i].value != "") {
          strmd5 += objb[i].keyname + objb[i].value;
0c49c87e   liuqimichale   微信公众号 初始化
163
164
        }
      }
834a2f37   刘淇   宣化 临停补缴 聚合支付
165
      strmd5 += "gz8wfwd0gn1etamjjhzey1ggcz78pfvd";
0c49c87e   liuqimichale   微信公众号 初始化
166
167
      // console.log('strmd5-------->'+strmd5);
      strmd5 = md5(strmd5);
5e52ed7c   刘淇   个人中心
168
      strmd5 = strmd5.toUpperCase();
0c49c87e   liuqimichale   微信公众号 初始化
169
      return strmd5;
9ca46819   刘淇   购买会员卡
170
171
    },
  
5e52ed7c   刘淇   个人中心
172
  };