|
@@ -2,7 +2,7 @@ const request = require('./WXHttpRequest.js');
|
|
|
const url = require('./const.js');
|
|
|
const util = require('./util.js');
|
|
|
|
|
|
-const HOST = url.apiUrlOnLine;
|
|
|
+const HOST = url.baseApi;
|
|
|
|
|
|
|
|
|
function genAPIUrl(action) {
|
|
@@ -20,7 +20,8 @@ function wxLogin(successcallback, failcallback) {
|
|
|
success: function(res) {
|
|
|
if (res.code) {
|
|
|
// 获取openid
|
|
|
- let url = genAPIUrl('wx/openId')
|
|
|
+ console.log(res);
|
|
|
+ let url = genAPIUrl('wx/user/openId')
|
|
|
let data = { code: res.code }
|
|
|
return request.getInstance().url(url).data(data).send().success(successcallback).fail(failcallback);
|
|
|
} else {
|
|
@@ -29,23 +30,60 @@ function wxLogin(successcallback, failcallback) {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+//登录
|
|
|
+function getLoginSchedule(sessionKey, openId, successcallback, failcallback) {
|
|
|
+ wx.getSetting({
|
|
|
+ success: function(res) {
|
|
|
+ // 已经授权,可以直接调用 getUserInfo 获取头像昵称
|
|
|
+ wx.getUserInfo({
|
|
|
+ withCredentials: true,
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res);
|
|
|
+ let url = genAPIUrl('wx/user/loginRegist');
|
|
|
+ const userData = {
|
|
|
+ encryptedData: res.encryptedData,
|
|
|
+ sessionKey: sessionKey,
|
|
|
+ iv: res.iv,
|
|
|
+ dist: '1133',
|
|
|
+ headimgurl: res.userInfo.avatarUrl,
|
|
|
+ }
|
|
|
+ request.getInstance().url(url).data(userData).method('GET').send().success(res => {
|
|
|
+ wx.hideToast()
|
|
|
+ wx.showToast({
|
|
|
+ title: '登录成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ wx.setStorageSync('uid', res.data.data.data.uid)
|
|
|
+ wx.setStorageSync('user', res)
|
|
|
+ successcallback(res)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function(res) {
|
|
|
+ failcallback(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
// 获取原来的 openid 和 session_key
|
|
|
function getOpenidSessionKey(successcallback, failcallback) {
|
|
|
- if (wx.getStorageSync('user')) {
|
|
|
- successcallback(
|
|
|
- wx.getStorageSync('user'),
|
|
|
- //分享小程序按钮
|
|
|
- wx.showShareMenu({
|
|
|
- withShareTicket: true
|
|
|
- })
|
|
|
- );
|
|
|
- return;
|
|
|
- }
|
|
|
+ // if (wx.getStorageSync('user')) {
|
|
|
+ // successcallback(
|
|
|
+ // wx.getStorageSync('user'),
|
|
|
+ // //分享小程序按钮
|
|
|
+ // wx.showShareMenu({
|
|
|
+ // withShareTicket: true
|
|
|
+ // })
|
|
|
+ // );
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
wxLogin(function(res) {
|
|
|
if(res.data.code == 200){
|
|
|
let sessionKey = res.data.data.session_key;
|
|
|
let openId = res.data.data.openid;
|
|
|
+ console.log(sessionKey);
|
|
|
+ console.log(openId);
|
|
|
getLoginSchedule(sessionKey, openId, successcallback, failcallback);
|
|
|
}
|
|
|
|
|
@@ -54,7 +92,7 @@ function getOpenidSessionKey(successcallback, failcallback) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-//登录
|
|
|
+
|
|
|
|
|
|
module.exports = {
|
|
|
getOpenidSessionKey
|