//DOWX app.js
|
|
|
var aldstat = require("utils/ald-stat.js");
|
const com = require("utils/common.js");
|
const dowx = require("./utils/DOWX.js");
|
|
|
var th = null;
|
|
App({
|
|
// 相当于全局信息
|
data:
|
{
|
info: null //用户信息, 如头像、openid
|
},
|
|
// 小程序初始化完成时
|
onLaunch: function ()
|
{
|
th = this;
|
},
|
|
onShow: function ()
|
{
|
// 获取个人信息权限
|
dowx.Authorize_userInfo(function ()
|
{
|
if (th.data.loginhad == true) { return false; }
|
// 获取用户信息
|
th.Get_info(function (res) {
|
// 注册用户
|
th.Login_user();
|
});
|
});
|
},
|
|
// 用户在服务器端数据注册
|
working_Login_user: false,
|
Login_user: function()
|
{
|
// '注册'发送数据准备
|
var mydata = {
|
openid: th.data.info.info2.openid, //openId
|
encryptedData: th.data.info.info1.encryptedData, //加密信息
|
iv: th.data.info.info1.iv //向量
|
};
|
var myurl = com.getWholeUrl("bainian/api/client/user/login", mydata);
|
// 发起注册
|
th.working_Login_user = true;
|
dowx.AjaxPost(myurl, {}, function (res)
|
{
|
th.working_Login_user = false;
|
dowx.AjaxStop([th.working_Login_user, th.working_Get_info]);
|
if (res.code != 0)
|
{
|
wx.showLoading({ title: '注册返回错误', });
|
console.log(res);
|
}
|
else
|
{
|
th.data.loginhad = true;
|
}
|
});
|
},
|
|
// 获取用户基本信息,参数 回调函数
|
working_Get_info: false,
|
Get_info:function(callback)
|
{
|
if (th.data.info==null)
|
{
|
// 获取用户信息,openid
|
th.working_Get_info = true;
|
dowx.Get_userInfo('bainian/api/client/user/getopenid',function (res)
|
{
|
th.working_Get_info = false;
|
dowx.AjaxStop([th.working_Login_user, th.working_Get_info]);
|
// 保存数据到globalData
|
th.data.info=res;
|
callback(th.data.info);
|
});
|
}
|
//信息已经存在时,直接返回
|
else { callback(th.data.info); }
|
}
|
})
|