|
@@ -32,7 +32,7 @@ function wxLogin(successcallback, failcallback) {
|
|
|
}
|
|
|
|
|
|
// 获取原来的 openid 和 session_key
|
|
|
-function getOpenidSessionKey(successcallback, failcallback) {
|
|
|
+function getOpenidSessionKey(successcallback, failcallback, loginType) {
|
|
|
if (wx.getStorageSync('user')) {
|
|
|
successcallback(
|
|
|
wx.getStorageSync('user'),
|
|
@@ -41,13 +41,39 @@ function getOpenidSessionKey(successcallback, failcallback) {
|
|
|
withShareTicket: true
|
|
|
})
|
|
|
);
|
|
|
+ //登陆成功后,统计用户登录时长,暂时使用定时器60秒后调用后台接口,比较耗性能,可以优化。。。。
|
|
|
+ let loginTime = wx.getStorageSync('loginTime') || 0;
|
|
|
+ let fn = () => {
|
|
|
+ let timeNum = setInterval( () => {
|
|
|
+ loginTime++;
|
|
|
+ wx.setStorage({
|
|
|
+ key:"loginTime",
|
|
|
+ data:loginTime
|
|
|
+ })
|
|
|
+ if(loginTime >= 60) {
|
|
|
+ clearInterval(timeNum);
|
|
|
+ //统计后台调用
|
|
|
+ let url = genAPIUrl('wx/statistics/onlineTime');
|
|
|
+ let uid = wx.getStorageSync('user').data.data.uid
|
|
|
+ request.getInstance().url(url).header({
|
|
|
+ uid,
|
|
|
+ }).method('POST').send().success(res => {
|
|
|
+ console.log('成功')
|
|
|
+ });
|
|
|
+ loginTime = 0;
|
|
|
+ fn();
|
|
|
+ }
|
|
|
+ //console.log(loginTime)
|
|
|
+ },1000)
|
|
|
+ }
|
|
|
+ fn();
|
|
|
return;
|
|
|
}
|
|
|
wxLogin(function(res) {
|
|
|
//console.log('获取sessionKey等内容'+JSON.stringify(res.data));
|
|
|
let sessionKey = JSON.parse(res.data).session_key;
|
|
|
let openId = JSON.parse(res.data).openid;
|
|
|
- getLoginSchedule(sessionKey, openId, successcallback, failcallback, false);
|
|
|
+ getLoginSchedule(sessionKey, openId, successcallback, failcallback, false, loginType);
|
|
|
},function(res) {
|
|
|
failcallback(res);
|
|
|
})
|
|
@@ -76,7 +102,7 @@ function getOpenidSessionKeyTwo(successcallback, failcallback) {
|
|
|
}
|
|
|
|
|
|
//登录
|
|
|
-function getLoginSchedule(sessionKey, openId, successcallback, failcallback, affirm) {
|
|
|
+function getLoginSchedule(sessionKey, openId, successcallback, failcallback, affirm, loginType) {
|
|
|
wx.getSetting({
|
|
|
success: function(res) {
|
|
|
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
|
|
@@ -113,7 +139,8 @@ function getLoginSchedule(sessionKey, openId, successcallback, failcallback, aff
|
|
|
sessionKey: sessionKey,
|
|
|
iv: res.iv,
|
|
|
dist: '1133',
|
|
|
- headimgurl: userInfo.avatarUrl
|
|
|
+ headimgurl: userInfo.avatarUrl,
|
|
|
+ loginType
|
|
|
}
|
|
|
request.getInstance().url(url).data(userData).method('GET').send().success(res => {
|
|
|
wx.hideToast()
|