1
|
-'use strict'
|
|
|
2
|
-import { APP_REPORT_HOST, APP_VERSION, APP_BUILD} from '../libs/config';
|
|
|
3
|
-import { APP_REPORT } from '../libs/request';
|
|
|
4
|
import md5 from '../vendors/md5';
|
1
|
import md5 from '../vendors/md5';
|
|
|
2
|
+import Promise from '../vendors/es6-promise';
|
|
|
3
|
+import { APP_REPORT_HOST, APP_VERSION, APP_BUILD } from '../libs/config';
|
5
|
|
4
|
|
6
|
let getDeviceInfo = function (app) {
|
5
|
let getDeviceInfo = function (app) {
|
7
|
- let ak = 'yoholuck_mp';//
|
6
|
+ let ak = 'yoholuck_mp'; // 小程序标识
|
8
|
|
7
|
|
9
|
let systemInfo = app.globalData.systemInfo
|
8
|
let systemInfo = app.globalData.systemInfo
|
10
|
let device = {}
|
9
|
let device = {}
|
|
@@ -12,12 +11,12 @@ let getDeviceInfo = function (app) { |
|
@@ -12,12 +11,12 @@ let getDeviceInfo = function (app) { |
12
|
let union_type = app.getUnion_type();
|
11
|
let union_type = app.getUnion_type();
|
13
|
device.ak = ak
|
12
|
device.ak = ak
|
14
|
device.udid = app.globalData.udid ? app.globalData.udid : '';
|
13
|
device.udid = app.globalData.udid ? app.globalData.udid : '';
|
15
|
- device.ch = union_type ? union_type: app.globalData.ch;
|
14
|
+ device.ch = union_type ? union_type : app.globalData.ch;
|
16
|
device.os = "weixinapp"
|
15
|
device.os = "weixinapp"
|
17
|
- device.osv = systemInfo && systemInfo.version ? systemInfo.version:''
|
|
|
18
|
- device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_'):''
|
16
|
+ device.osv = systemInfo && systemInfo.version ? systemInfo.version : ''
|
|
|
17
|
+ device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_') : ''
|
19
|
|
18
|
|
20
|
- if (systemInfo.platform == 'ios'){
|
19
|
+ if (systemInfo.platform == 'ios') {
|
21
|
//针对ios设备,特殊处理dm,转为iphone_7这种格式
|
20
|
//针对ios设备,特殊处理dm,转为iphone_7这种格式
|
22
|
var start_num = device.dm.indexOf('<')
|
21
|
var start_num = device.dm.indexOf('<')
|
23
|
var end_num = device.dm.indexOf('>')
|
22
|
var end_num = device.dm.indexOf('>')
|
|
@@ -34,57 +33,68 @@ let getDeviceInfo = function (app) { |
|
@@ -34,57 +33,68 @@ let getDeviceInfo = function (app) { |
34
|
return device;
|
33
|
return device;
|
35
|
}
|
34
|
}
|
36
|
|
35
|
|
37
|
-let appReport = function(reportType, pt, pn, param,appObject) {
|
|
|
38
|
- let app = appObject;
|
36
|
+let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this) {
|
|
|
37
|
+ let app = _this || getApp();
|
39
|
|
38
|
|
40
|
let deviceInfo = getDeviceInfo(app)
|
39
|
let deviceInfo = getDeviceInfo(app)
|
41
|
if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return;
|
40
|
if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return;
|
42
|
- if(!param)param = {};
|
|
|
43
|
- if(!reportType)reportType='hb';
|
41
|
+ if (!reportType) reportType = 'hb';
|
44
|
|
42
|
|
45
|
let ts = new Date().getTime() + '000000';
|
43
|
let ts = new Date().getTime() + '000000';
|
46
|
let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : '';
|
44
|
let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : '';
|
47
|
|
45
|
|
48
|
- if(!uid){
|
46
|
+ if (!uid) {
|
49
|
uid = md5(app.getUid());
|
47
|
uid = md5(app.getUid());
|
50
|
}
|
48
|
}
|
51
|
|
49
|
|
|
|
50
|
+ let event = {};
|
52
|
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
|
51
|
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
|
53
|
-
|
|
|
54
|
let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0';
|
52
|
let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0';
|
55
|
|
53
|
|
56
|
- let event = {}
|
|
|
57
|
- event.ps = '0',
|
|
|
58
|
- event.av = APP_VERSION,
|
|
|
59
|
- event.ab = APP_BUILD,
|
|
|
60
|
- event.ca = '0',
|
|
|
61
|
- event.net = networkType,
|
|
|
62
|
- event.sid = sid,
|
|
|
63
|
- event.uid = uid,
|
|
|
64
|
- event.ts = ts,
|
|
|
65
|
- event.pt = pt,
|
|
|
66
|
- event.pn = pn,
|
|
|
67
|
- event.param = param
|
54
|
+ event.ps = '0';
|
|
|
55
|
+ event.av = APP_VERSION;
|
|
|
56
|
+ event.ab = APP_BUILD;
|
|
|
57
|
+ event.ca = '0';
|
|
|
58
|
+ event.net = networkType;
|
|
|
59
|
+ event.sid = sid;
|
|
|
60
|
+ event.uid = uid;
|
|
|
61
|
+ event.ts = ts;
|
|
|
62
|
+ event.pt = pt;
|
|
|
63
|
+ event.pn = pn;
|
|
|
64
|
+ event.param = param;
|
68
|
|
65
|
|
69
|
let events = [];
|
66
|
let events = [];
|
70
|
events.push(event)
|
67
|
events.push(event)
|
71
|
|
68
|
|
72
|
//组装最终要上报的数据
|
69
|
//组装最终要上报的数据
|
73
|
let parameters = {};
|
70
|
let parameters = {};
|
74
|
- parameters.type = reportType,
|
|
|
75
|
- parameters.device = deviceInfo,
|
|
|
76
|
- parameters.events = events,
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
- APP_REPORT(APP_REPORT_HOST, parameters)
|
71
|
+ parameters.type = reportType;
|
|
|
72
|
+ parameters.device = deviceInfo;
|
|
|
73
|
+ parameters.events = events;
|
|
|
74
|
+
|
|
|
75
|
+ let _appReport = function (url, params = {}) {
|
|
|
76
|
+ return new Promise(function (resolve, reject) {
|
|
|
77
|
+ let app = getApp();
|
|
|
78
|
+ let data = JSON.stringify(params)
|
|
|
79
|
+ let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
|
|
|
80
|
+ let header = {
|
|
|
81
|
+ 'content-type': "application/json",
|
|
|
82
|
+ 'x-yoho-sid': md5(sid),
|
|
|
83
|
+ }
|
|
|
84
|
+ wx.request({
|
|
|
85
|
+ url,
|
|
|
86
|
+ data,
|
|
|
87
|
+ header,
|
|
|
88
|
+ method: 'POST'
|
|
|
89
|
+ });
|
|
|
90
|
+ })
|
|
|
91
|
+ };
|
|
|
92
|
+ _appReport(APP_REPORT_HOST, parameters)
|
80
|
.then(function (data) {
|
93
|
.then(function (data) {
|
81
|
- // console.log(data)
|
|
|
82
|
})
|
94
|
})
|
83
|
.catch(function (error) {
|
95
|
.catch(function (error) {
|
84
|
});
|
96
|
});
|
85
|
|
97
|
|
86
|
}
|
98
|
}
|
87
|
|
99
|
|
88
|
-module.exports = {
|
|
|
89
|
- appReport,
|
|
|
90
|
-} |
|
|
|
|
100
|
+export default appReport; |