|
|
'use strict'
|
|
|
import { APP_REPORT_HOST, APP_VERSION, APP_BUILD} from '../libs/config';
|
|
|
import { APP_REPORT } from '../libs/request';
|
|
|
import md5 from '../vendors/md5';
|
|
|
import Promise from '../vendors/es6-promise';
|
|
|
import { APP_REPORT_HOST, APP_VERSION, APP_BUILD } from '../libs/config';
|
|
|
|
|
|
let getDeviceInfo = function (app) {
|
|
|
let ak = 'yoholuck_mp';//
|
|
|
let ak = 'yoholuck_mp'; // 小程序标识
|
|
|
|
|
|
let systemInfo = app.globalData.systemInfo
|
|
|
let device = {}
|
...
|
...
|
@@ -12,12 +11,12 @@ let getDeviceInfo = function (app) { |
|
|
let union_type = app.getUnion_type();
|
|
|
device.ak = ak
|
|
|
device.udid = app.globalData.udid ? app.globalData.udid : '';
|
|
|
device.ch = union_type ? union_type: app.globalData.ch;
|
|
|
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(' ', '_'):''
|
|
|
device.osv = systemInfo && systemInfo.version ? systemInfo.version : ''
|
|
|
device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_') : ''
|
|
|
|
|
|
if (systemInfo.platform == 'ios'){
|
|
|
if (systemInfo.platform == 'ios') {
|
|
|
//针对ios设备,特殊处理dm,转为iphone_7这种格式
|
|
|
var start_num = device.dm.indexOf('<')
|
|
|
var end_num = device.dm.indexOf('>')
|
...
|
...
|
@@ -34,57 +33,68 @@ let getDeviceInfo = function (app) { |
|
|
return device;
|
|
|
}
|
|
|
|
|
|
let appReport = function(reportType, pt, pn, param,appObject) {
|
|
|
let app = appObject;
|
|
|
let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this) {
|
|
|
let app = _this || getApp();
|
|
|
|
|
|
let deviceInfo = getDeviceInfo(app)
|
|
|
if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return;
|
|
|
if(!param)param = {};
|
|
|
if(!reportType)reportType='hb';
|
|
|
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){
|
|
|
if (!uid) {
|
|
|
uid = md5(app.getUid());
|
|
|
}
|
|
|
|
|
|
let event = {};
|
|
|
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
|
|
|
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)
|
|
|
parameters.type = reportType;
|
|
|
parameters.device = deviceInfo;
|
|
|
parameters.events = events;
|
|
|
|
|
|
let _appReport = function (url, params = {}) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
let app = getApp();
|
|
|
let data = JSON.stringify(params)
|
|
|
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
|
|
|
let header = {
|
|
|
'content-type': "application/json",
|
|
|
'x-yoho-sid': md5(sid),
|
|
|
}
|
|
|
wx.request({
|
|
|
url,
|
|
|
data,
|
|
|
header,
|
|
|
method: 'POST'
|
|
|
});
|
|
|
})
|
|
|
};
|
|
|
_appReport(APP_REPORT_HOST, parameters)
|
|
|
.then(function (data) {
|
|
|
// console.log(data)
|
|
|
})
|
|
|
.catch(function (error) {
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
appReport,
|
|
|
} |
|
|
\ No newline at end of file |
|
|
export default appReport; |
|
|
\ No newline at end of file |
...
|
...
|
|