1 Star 0 Fork 3

唐唐/大转盘抽奖

forked from yongchao71/大转盘抽奖 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.63 KB
一键复制 编辑 原始数据 按行查看 历史
yongchao71 提交于 2018-09-19 18:01 . add project code
var aldstat = require("./utils/ald-stat.js");
const wxaapi = require('./public/wxaapi.js');
const wxRequest = require('./utils/js/wxRequest.js');
const wxPromise = require('./utils/js/wxPromise.js');
const wxCRequest = require('./public/js/crequest.js');
App({
globalData: {
userInfo: null,
flag: false,
sessionKey: ""
// corType:"yy",
// corBrg: "#1ED7BB"
},
onLaunch: function (options) {
},
/**
* 获取用户登录信息
*/
getUserData:function(callback){
let _This=this;
let oUserInfo = _This.globalData.userInfo||{};
let unionId = oUserInfo.unionId;
if (unionId){
wxCRequest.fGetUserToken(unionId,function(tresult){
}).then(function(tresult){
oUserInfo.permission = tresult;
callback(oUserInfo);
});
return false;
};
_This.fGetSessionKey(true,function (sessionKey){
_This.fAuthUserData(sessionKey).then(resAll => {
oUserInfo = getApp().globalData.userInfo;
unionId = oUserInfo.unionId;
//console.log("app.js---resAll--------------", resAll, unionId);
if (!resAll){
wxCRequest.fGetUserToken(unionId,function (tresult) {
}).then(function (tresult) {
oUserInfo.permission = tresult;
callback(oUserInfo);
});
return false;
}
wxCRequest.fGetUserToken(resAll.data.userinfo.unionId,function (tresult) {
//callback(resAll.data.userinfo);
}).then(function (tresult) {
let oUserinfo=resAll.data.userinfo;
oUserinfo.permission = tresult;
getApp().globalData.userInfo = oUserinfo;
callback(oUserinfo);
});;
});
});
},
/**
* 用户授权用户信息
*/
fAuthUserData(sessionKey){
let _This=this;
return wxPromise(wx.getUserInfo)().then(resUserInfo => {
//console.log("----app.js------resUserInfo-----------", resUserInfo);
if (resUserInfo.errMsg.indexOf("ok") < 0) {
}else{
var encryptedData = resUserInfo.encryptedData;
var iv = resUserInfo.iv;
var postData = {
encryptedData: encryptedData,
sessionKey: sessionKey, iv: iv
};
//return wxRequest(wxaapi.unionid.userinfo.url, postData);//解析用户信息----------------
return wxRequest(wxaapi.sellunion.selltooluserinfo.url, postData);
}
})
},
/**
* 获取sessionKey
*/
fGetSessionKey: function (firstType,callback){
let _This =this;
let sessionKey=_This.globalData.sessionKey;
wxPromise(wx.checkSession)().then(result => {
if (!firstType&&result.errMsg.indexOf("ok") > 0) {
callback(sessionKey);
} else {
wxPromise(wx.login)().then(result => {
//console.log("user code------------------",result);
let ucode = result.code;
// return wxRequest(wxaapi.unionid.code.url, { code: ucode });//-------------------------解析用户code
return wxRequest(wxaapi.sellunion.selltoolcode.url, { code: ucode });
}).then(sResult => {
// console.log("sResult session------------------", sResult);
let resSession = sResult.data||{};
getApp().globalData.sessionKey = resSession.session_key;
let userInfo={
unionId: resSession.unionid,
openId: resSession.openid
};
let appUserInfo = getApp().globalData.userInfo||{};
if (!appUserInfo.unionId){
// appUserInfo.unionId=userInfo.unionId;
// appUserInfo.openId = userInfo.openId;
getApp().globalData.userInfo = userInfo;
}
sessionKey = resSession.session_key;
callback(sessionKey);
});
}
});
},
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/a513681467/lcy_wxa_selltool.git
[email protected]:a513681467/lcy_wxa_selltool.git
a513681467
lcy_wxa_selltool
大转盘抽奖
master

搜索帮助