Blame view

libs/switch.js 1.04 KB
李奇 authored
1 2 3 4 5 6
import Promise from '../vendors/es6-promise';
import {APP_VERSION, ICONFIG_HOST} from '../libs/config';
import {encrypt, decrypt} from '../utils/icfg-aes';
import {stringify} from '../vendors/query-string';

let iconfSwitch = function (app) {
李奇 authored
7
    app = app || getApp();
李奇 authored
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
    let data = {};
    let device = app.globalData.systemInfo;
    
    data.app_ver = APP_VERSION;
    data.uid = app.getUid() || '';
    data.os = device.platform.indexOf('ios') > -1 ? 0 : 1;
    data.osv = device.osv || device.version;
    data.model = device.model;
    data.udid = app.globalData.udid ? app.globalData.udid : '';
    data.patchv = '';
    data.ci = (app.getUnion_type() ? app.getUnion_type() : app.globalData.ch) || '';

    return new Promise(function (resolve, reject) {
        wx.request({
            url: `${ICONFIG_HOST}?${encrypt(stringify(data))}`,
            success({data} = {}) {
                resolve(JSON.parse(decrypt(data)));
            },
            fail(err) {
                reject(err);
            }
        });
    })

};

export default iconfSwitch;