Authored by 李奇

修改接口508

... ... @@ -2,28 +2,13 @@
import wx from './utils/wx';
import udid from './common/udid';
import event from './common/event';
import promisify from './common/promisify';
import objectAssign from './vendors/object-assign';
import {WeToast} from './vendors/toast/wetoast';
import config from './common/config';
import {GET, POST} from './common/request';
import {Encrypt,Decrypt} from './common/aes.js';
let crypto = require('./common/cryptojs/cryptojs.js').Crypto
import md5 from './vendors/md5';
var mta = require('./vendors/mta_analysis.js')
import { wechatLoginAction } from './utils/login';
import { isStringEmpty } from './utils/util';
import { logEvent,
YB_LAUNCH_APP,
YB_EXIT_APP,
YB_ENTER_FOREGROUND,
YB_ENTER_BACKGROUND,
YB_PAGE_OPEN_L,
YB_AWAKE_MP
} from './common/analytics.js';
import { appReport } from './common/appReport.js';
import {wechatLoginAction} from './utils/login';
import {isStringEmpty} from './utils/util';
App({
onLaunch: function (options) {
... ... @@ -39,14 +24,14 @@ App({
this.globalData.systemInfo = res;
this.checkUDID();
that.getSimplePise()
this.checkNetworkType()
that.getSimplePise();
this.checkNetworkType();
if (options && options.scene){
if (options && options.scene) {
this.globalData.ch = options.scene
}
if (options && options.query && options.query.union_type){
if (options && options.query && options.query.union_type) {
this.globalData.union_type = options.query.union_type
}
... ... @@ -73,60 +58,27 @@ App({
data: ""
});
}
})
});
this.getSessionkey();
let timestamp = new Date().getTime() + ''
let timestamp = new Date().getTime() + '';
this.globalData.sid = md5(timestamp);
if (options){
if (options) {
let channel = options.query.channel;
let channelType = options.query.type;
let params = { 'CHANNEL': channel, 'TYPE': channelType };
logEvent(YB_LAUNCH_APP, params, this);
let params = {'CHANNEL': channel, 'TYPE': channelType};
}
setTimeout(function () {
wechatLoginAction(function (response) {});}, 1000);
wechatLoginAction(() => '');
}, 1000);
this.mtainit(options);
},
//当应用程序进入前台显示状态时触发
onShow(options) {
let that = this
let params = {};
logEvent(YB_ENTER_FOREGROUND, params, this)
if (that.globalData.hasReportAwakeAction==='false'){
let pathParam = ""
if(options && options.query) {
for (var Key in options.query) {
if (pathParam.length == 0) {
pathParam = Key + '=' + options.query[Key] + '';
} else {
pathParam = pathParam + '&' + '' + Key + '=' + options.query[Key] + '';
}
}
}
let path
if(pathParam!==""){
path = options.path + "?" + pathParam
}else{
path = options.path
}
params = {
PAGE_PATH: path
};
logEvent(YB_AWAKE_MP, params, this);
that.globalData.hasReportAwakeAction = 'true'
}
appReport('start', "LIFECYCLE", "RESUME", {},this)
},
onShow() {},
//当应用程序进入后台状态时触发
onHide () {
let params = {};
logEvent(YB_ENTER_BACKGROUND,params)
appReport('start', "LIFECYCLE", "STOP", {},this)
},
onHide () {},
getUserInfo: function () {
try {
... ... @@ -156,7 +108,7 @@ App({
var value = this.globalData.WXThird_session
if (!isStringEmpty(value)) {
that.globalData.WXThird_session = value;
}else{
} else {
value = wx.getStorageSync('WXThird_session')
}
return value
... ... @@ -197,9 +149,9 @@ App({
})
},
setOpenID:function(openID){
setOpenID: function (openID) {
if(openID=='') return
if (openID == '') return
this.globalData.openID = openID;
wx.setStorage({
key: "openID",
... ... @@ -209,9 +161,9 @@ App({
getOpenID: function () {
let openid = ''
if (!isStringEmpty(this.globalData.openID)){
if (!isStringEmpty(this.globalData.openID)) {
openid = this.globalData.openID
}else{
} else {
openid = wx.getStorageSync('openID')
this.globalData.openID = openid
}
... ... @@ -233,27 +185,24 @@ App({
systemInfo: null,
WXThird_session: '',
WXUnion_ID: '',
openID:'',
openID: '',
p2SecretKey: '',
sessionkey: '',
sid: '',
udid:'',
cid:'1',
mobileRegisterState:'',
udid: '',
cid: '1',
mobileRegisterState: '',
hasReportAwakeAction: 'false',
defraudurl:'https://activity.yoho.cn/feature/45.html?title=防诈骗提醒',
defraudurl: 'https://activity.yoho.cn/feature/45.html?title=防诈骗提醒',
miniapp_type: config.constants.MINI_APP_TYPE,
union_type:'',
ch:'',
networkType:'0',
deviceInfo:{},
union_type: '',
ch: '',
networkType: '0',
deviceInfo: {}
},
isLogin: function () {
return this.globalData.userInfo != null &&
// this.globalData.userInfo.uid != undefined &&
// this.globalData.userInfo.uid != null &&
// this.globalData.userInfo.uid != '' &&
this.globalData.WXThird_session != '' &&
this.globalData.WXThird_session != null &&
this.globalData.WXThird_session != undefined;
... ... @@ -261,14 +210,14 @@ App({
getUid: function () {
let uid = this.globalData.userInfo.uid
if(!uid||uid===0){
if (!uid || uid === 0) {
this.getUserInfo();
uid = this.globalData.userInfo.uid
}
return uid;
},
getMiniappType:function(){
getMiniappType: function () {
return config.constants.MINI_APP_TYPE
},
... ... @@ -277,20 +226,20 @@ App({
let that = this
let data = {
"udid": that.globalData.udid,
"method": 'resources.simple.pice'}
"method": 'resources.simple.pice'
}
let method = "GET"
let header = {
'Content-Type': 'application/x-www-form-urlencoded'
}
wx.request({
url:config.constants.API_HOST,
url: config.constants.API_HOST,
data,
method,
header: header,
success: function (res) {
// console.log("res:", res)
if (res && res.data && res.data.data && res.data.data.sk){
if (res && res.data && res.data.data && res.data.data.sk) {
that.globalData.p2SecretKey = res.data.data.sk;
wx.setStorage({
key: "p2SecretKey",
... ... @@ -299,7 +248,6 @@ App({
}
},
fail: function (err) {
// console.log("err:",err)
}
});
},
... ... @@ -307,34 +255,23 @@ App({
fastloginSwitch: function () {
let that = this
let param = {
method: 'app.passport.fastloginSwitch',
method: 'app.passport.fastloginSwitch'
};
GET(config.constants.API_HOST, param)
.then(json => {
// if (!json || !json.code || json.code != 200 || !json.data) return;
// if (!json.data || !json.data.sk) return;
// let p2SecretKey = json.data.sk;
// if (!p2SecretKey) return;
// that.globalData.p2SecretKey = p2SecretKey;
// wx.setStorage({
// key: "p2SecretKey",
// data: p2SecretKey
// });
})
.catch(error => {
});
},
checkUDID:function(){
checkUDID: function () {
let that = this
try {
var value = wx.getStorageSync('udid')
if (value) {
that.globalData.udid = value;
}else{
} else {
let udidValue = md5(that.getUUID());
that.globalData.udid = udidValue;
try {
... ... @@ -344,12 +281,10 @@ App({
}
//获取签名秘钥
} catch (e) {
// Do something when catch error
// console.log("checkUDID error: " + e)
}
},
checkNetworkType:function(){
checkNetworkType: function () {
let that = this;
let net = '';
... ... @@ -371,8 +306,7 @@ App({
}
// console.log("network:",net)
},
complete:function(res){
appReport('start', "LIFECYCLE", "START", {}, that)
complete: function (res) {
}
})
that.globalData.networkType = net;
... ... @@ -384,10 +318,6 @@ App({
},
loginCallBack: function (response) {
// console.log(response)
// if (response.code === 10001) {
// this.showRelaunchModal();
// }
},
showRelaunchModal: function () {
... ... @@ -411,23 +341,15 @@ App({
try {
var value = wx.getStorageSync('sessionkey')
if (value) {
// console.log(value)
this.globalData.sessionkey = value;
}
} catch (e) {
// console.log(e)
}
}
return undefined;
},
mtainit(e) {
mta.App.init({
"appID": "500570715",
"eventID": "500570797",
});
// console.log("init mta");
},
mtainit(e) {},
WeToast
})
... ...
... ... @@ -11,12 +11,14 @@ const config = {
constants: {
LOG_EVENT_HOST: 'https://analysis.yohobuy.com/yas_mobile',
APP_REPORT_HOST: 'https://app.yoho.cn/collect/v3',
API_HOST: 'http://api-test1.yohops.com:9999',
// API_HOST: 'https://api.yoho.cn',
// SERVICE_HOST: 'https://api.yoho.cn',
API_HOST: 'http://api-test1.yohops.com:9999/',
SERVICE_HOST: 'http://api-test1.yohops.com:9999/',
MINI_APP_TYPE: '0',
PAYMENT_CODE: '45',
OS_VERSION: 'yohobuy:h5',
APP_VERSION: '2.2.1',
APP_VERSION: '6.4.0',
APP_BUILD: '1003',
PRIVATE_KEY: 'b43890b0a296ff3c7b8c260ca763980b',
CLIENT_TYPE: 'miniapp',
... ...
... ... @@ -9,8 +9,58 @@ let p1SecretKey = "yoho9646yoho9646"
let ClientInitConfigMehtod = "resources.simple.pice"
let ClientConfigHasRequested = 0
function getPrivateKey(){
return new Promise(function(resolve,reject){
let app = getApp()
let p2SecretKey = app && app.globalData && app.globalData.p2SecretKey;
if (!p2SecretKey){
p2SecretKey = wx.getStorageSync("p2SecretKey")
}
if (p2SecretKey){
resolve(p2SecretKey)
}else{
let data = {
"udid": app.globalData.udid,
"method": 'resources.simple.pice'
}
let method = "GET"
let header = {
'Content-Type': 'application/x-www-form-urlencoded'
}
wx.request({
url: config.constants.API_HOST,
data,
method,
header: header,
success: function (res) {
// console.log("res:", res)
if (res && res.data && res.data.data && res.data.data.sk) {
app.globalData.p2SecretKey = res.data.data.sk;
wx.setStorage({
key: "p2SecretKey",
data: res.data.data.sk
});
resolve(app.globalData.p2SecretKey)
}
},
fail: function (err) {
reject(err)
// console.log("err:",err)
}
});
}
})
}
function request(method = 'GET') {
return function(url, params = {}) {
return getPrivateKey()
.then(key => {
return new Promise(function(resolve, reject) {
let app = getApp();
if (params && !params.hasOwnProperty('uid')) {
... ... @@ -90,6 +140,7 @@ function request(method = 'GET') {
}
});
})
});
}
}
... ... @@ -149,23 +200,12 @@ function _publicParams() {
// Do something when catch error
}
// app_version = '5.6.0';
// os_version = '10.3';
// screen_size = '320x568';
// let uid = '0';
// let udid = 'acea1c6170ecca417c67979a406156950bcf4fe5';
// let physical_channel = 1;
return {
app_version,
os_version,
client_type,
screen_size,
// physical_channel,
// udid,
v,
// uid,
v
};
}
... ...
import api from '../../common/api';
export default {
/**
* 解析用户信息
* @param thirdSession
* @param encryptedData
* @param iv
* @returns {*}
*/
decodeUserInfo(thirdSession, encryptedData, iv) {
return api.post({
url: '/wechat/',
data: {
iv,
encryptedData,
srdSession: thirdSession,
method: 'wechat.smallProgram.decodeUserInfo'
}
});
},
/**
* 判断有货微信账户是否绑定手机号
* @param unionID
* @param nickName
* @returns {*}
*/
wechatUserIsBind(unionID, nickName) {
return api.get({
url: '',
data: {
method: 'app.passport.signinByOpenID',
openId: unionID,
source_type: 'wechat',
nickname: nickName,
}
});
},
/**
* 微信登录小程序
* @param code
* @returns {*}
*/
wechatMiniAppLogin(code) {
return api.get({
url: '/wechat/',
data: {
method: 'wechat.smallProgram.onLogin',
jsCode: code,
miniapp_type: '2'
}
});
},
/**
* 绑定小程序
* @param unionId
* @param mobile
* @param code
* @param area
* @returns {*}
*/
bindMiniapp(unionId, mobile, code, area = 86) {
return api.get({
url: '',
data: {
code,
mobile,
area,
open_id: unionId,
source_type: 'wechat',
method: 'app.passport.bindMiniapp'
}
});
},
/**
* 自动绑定小程序
* @param unionId
* @param mobile
* @param area
* @returns {*}
*/
bindMiniAppByAuto(unionId, mobile, area = 86) {
return api.get({
url: '',
data: {
mobile,
area,
open_id: unionId,
source_type: 'wechat',
method: 'app.passport.miniAppBindByAuto'
}
});
},
/**
* 自动登录
* @param mobile
* @param code
* @param area
* @returns {*}
*/
autoSignIn(mobile, code, area = 86) {
return api.get({
url: '',
data: {
code,
area,
profile: mobile,
source_type: 'wechat',
method: 'app.passport.autoSignin'
}
});
},
/**
* sessionKey是否失效验证
* @returns {*}
*/
verify() {
return api.get({
url: '',
data: {
method: 'app.passport.verify'
}
});
},
/**
* 获取用户信息
* @param uid 用户UID
* @returns {*}
*/
getProfile() {
return api.get({
url: '',
data: {
method: 'app.passport.profile'
}
});
},
/**
* 获取优惠券总数
* @returns {*}
*/
getCouponTotal() {
return api.get({
url: '/coupon/total.do',
data: {},
api: 'store'
});
},
/**
* 获取有货币总数
* @returns {*}
*/
getCoinTotal() {
return api.get({
url: '',
data: {
method: 'app.yohocoin.total'
}
});
},
/**
* 获取国家和地区
* @returns {*}
*/
getArea() {
return api.get({
url: '',
data: {
source_type: 'wechat',
method: 'app.passport.getArea'
}
});
},
/**
* 用户未授权-发送验证码
* @param area 国家码
* @param mobile 手机号
* @returns {*}
*/
sendSms(area, mobile) {
return api.get({
url: '',
data: {
area,
mobile,
source_type: 'wechat',
method: 'app.message.sendSms'
}
});
},
/**
* 用户已授权-发送验证码
* @param mobile 手机号
* @param area 国家码
* @returns {*}
*/
sendCodeByMiniApp(area, mobile, openId) {
return api.get({
url: '',
data: {
area,
mobile,
open_id: openId,
source_type: 'wechat',
method: 'app.bind.sendCodeByMiniApp'
}
});
}
};
... ...

1.11 KB | W: | H:

259 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin

1.09 KB | W: | H:

214 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -129,12 +129,13 @@ function getUnionID(srd_session, callbackFunc) {
判断该微信用户是否已经绑定了有货账号,如果已绑定则返回uid等用户信息
*/
function wechatUserIsBind(unionID, nickName, callbackFunc) {
let app = getApp()
let app = getApp();
let param = {
method: 'app.passport.signinByOpenID',
openId: unionID,
nickname: nickName,
}
};
POST(config.constants.API_HOST, param)
.then(data => {
let responseData = data.data
... ... @@ -146,7 +147,6 @@ function wechatUserIsBind(unionID, nickName, callbackFunc) {
userInfo.ssouid = responseData.ssouid;
userInfo.uid = responseData.uid;
app.setUserInfo(userInfo);
app.setSessionkey(responseData.session_key);
trigger(true)
... ...