appReport.js
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict'
import { APP_REPORT_HOST, APP_VERSION, APP_BUILD} from '../libs/config';
import { APP_REPORT } from '../libs/request';
import md5 from '../vendors/md5';
let getDeviceInfo = function (app) {
let ak = 'yohobuy_mp';//
let systemInfo = app.globalData.systemInfo
let device = {}
let union_type = app && app.globalData && app.globalData.union_type ? app.globalData.union_type : '';
device.ak = ak
device.udid = app.globalData.udid ? app.globalData.udid : '';
device.ch = union_type ? union_type: app.globalData.ch;
device.os = "weixinapp"
device.osv = systemInfo && systemInfo.version ? systemInfo.version:''
device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_'):''
return device;
}
let appReport = function(reportType, pt, pn, param,appObject) {
let app = appObject;
let deviceInfo = getDeviceInfo(app)
if (!pt || !pn || !deviceInfo) return;
if(!param)param = {};
if(!reportType)reportType='hb';
let ts = new Date().getTime() + '000000';
let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : '';
if(!uid){
uid = md5(app.getUid());
}
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0';
let event = {}
event.ps = '0',
event.av = APP_VERSION,
event.ab = APP_BUILD,
event.ca = '0',
event.net = networkType,
event.sid = sid,
event.uid = uid,
event.ts = ts,
event.pt = pt,
event.pn = pn,
event.param = param
let events = [];
events.push(event)
//组装最终要上报的数据
let parameters = {};
parameters.type = reportType,
parameters.device = deviceInfo,
parameters.events = events,
APP_REPORT(APP_REPORT_HOST, parameters)
.then(function (data) {
// console.log(data)
})
.catch(function (error) {
});
}
module.exports = {
appReport,
}