微信小程序登录
parent
bc8782cdd9
commit
7bc0f07846
|
|
@ -96,6 +96,7 @@ class User extends Common
|
||||||
{
|
{
|
||||||
return DataReturn('获取授权信息失败', -10);
|
return DataReturn('获取授权信息失败', -10);
|
||||||
} else {
|
} else {
|
||||||
|
$result['gender'] = empty($result['gender']) ? 0 : ($result['gender'] == 'm') ? 2 : 1;
|
||||||
$result['openid'] = $result['user_id'];
|
$result['openid'] = $result['user_id'];
|
||||||
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
||||||
return UserService::AuthUserProgram($result, 'alipay_openid');
|
return UserService::AuthUserProgram($result, 'alipay_openid');
|
||||||
|
|
@ -134,6 +135,9 @@ class User extends Common
|
||||||
|
|
||||||
if(is_array($result))
|
if(is_array($result))
|
||||||
{
|
{
|
||||||
|
$result['nick_name'] = isset($result['nickName']) ? $result['nickName'] : '';
|
||||||
|
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
||||||
|
$result['gender'] = empty($result['gender']) ? 0 : ($result['gender'] == 2) ? 1 : 2;
|
||||||
$result['openid'] = $result['openId'];
|
$result['openid'] = $result['openId'];
|
||||||
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
||||||
return UserService::AuthUserProgram($result, 'weixin_openid');
|
return UserService::AuthUserProgram($result, 'weixin_openid');
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ App({
|
||||||
if (params != "" && params.substr(0, 1) != "&") {
|
if (params != "" && params.substr(0, 1) != "&") {
|
||||||
params = "&" + params;
|
params = "&" + params;
|
||||||
}
|
}
|
||||||
var user = this.GetUserCacheInfo();
|
var user = this.get_user_cache_info();
|
||||||
var app_client_user_id = user == false ? "" : user.wechat_openid;
|
var app_client_user_id = user == false ? "" : user.wechat_openid;
|
||||||
var user_id = user == false ? 0 : user.id;
|
var user_id = user == false ? 0 : user.id;
|
||||||
return (
|
return (
|
||||||
|
|
@ -184,22 +184,21 @@ App({
|
||||||
* method 回调操作对象的函数
|
* method 回调操作对象的函数
|
||||||
* return 有用户数据直接返回, 则回调调用者
|
* return 有用户数据直接返回, 则回调调用者
|
||||||
*/
|
*/
|
||||||
GetUserInfo(object, method) {
|
get_user_info(object, method) {
|
||||||
var user = this.GetUserCacheInfo();
|
var user = this.get_user_cache_info();
|
||||||
if (user == false) {
|
if (user == false) {
|
||||||
// 唤醒用户授权
|
// 唤醒用户授权
|
||||||
this.UserAuthCode(object, method);
|
this.user_auth_code(object, method);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
return user;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从缓存获取用户信息
|
* 从缓存获取用户信息
|
||||||
*/
|
*/
|
||||||
GetUserCacheInfo() {
|
get_user_cache_info() {
|
||||||
let user = wx.getStorageSync(this.data.cache_user_info_key);
|
let user = wx.getStorageSync(this.data.cache_user_info_key);
|
||||||
if ((user || null) == null) {
|
if ((user || null) == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -207,26 +206,12 @@ App({
|
||||||
return user;
|
return user;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* 从缓存获美啦取用户信息
|
|
||||||
*/
|
|
||||||
GetMeiLaUserCacheInfo() {
|
|
||||||
let user = wx.getStorageSync(this.data.cache_user_info_key);
|
|
||||||
if ((user || null) == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if ((user.my_user || null) == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return user.my_user;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户授权
|
* 用户授权
|
||||||
* object 回调操作对象
|
* object 回调操作对象
|
||||||
* method 回调操作对象的函数
|
* method 回调操作对象的函数
|
||||||
*/
|
*/
|
||||||
UserAuthCode(object, method) {
|
user_auth_code(object, method) {
|
||||||
// 加载loding
|
// 加载loding
|
||||||
wx.showLoading({ title: '授权中...' });
|
wx.showLoading({ title: '授权中...' });
|
||||||
var $this = this;
|
var $this = this;
|
||||||
|
|
@ -234,8 +219,6 @@ App({
|
||||||
// 请求授权接口
|
// 请求授权接口
|
||||||
wx.getSetting({
|
wx.getSetting({
|
||||||
success(res) {
|
success(res) {
|
||||||
console.log('app.js 授权部分');
|
|
||||||
|
|
||||||
if (!res.authSetting['scope.userInfo']) {
|
if (!res.authSetting['scope.userInfo']) {
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: "/pages/login/login"
|
url: "/pages/login/login"
|
||||||
|
|
@ -349,12 +332,16 @@ App({
|
||||||
if (res.data.code == 0) {
|
if (res.data.code == 0) {
|
||||||
wx.setStorage({
|
wx.setStorage({
|
||||||
key: $this.data.cache_user_info_key,
|
key: $this.data.cache_user_info_key,
|
||||||
data: res.data.data
|
data: res.data.data,
|
||||||
|
success: (res) => {
|
||||||
|
if (typeof object === 'object' && (method || null) != null) {
|
||||||
|
object[method]();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
$this.showToast('用户信息缓存失败');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof object === 'object' && (method || null) != null) {
|
|
||||||
object[method]();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this.showToast(res.data.text);
|
$this.showToast(res.data.text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ Page({
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init(e) {
|
init(e) {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: '温馨提示',
|
title: '温馨提示',
|
||||||
content: '绑定手机号码',
|
content: '绑定手机号码',
|
||||||
confirmButtonText: '确认',
|
confirmText: '确认',
|
||||||
cancelButtonText: '暂不',
|
cancelText: '暂不',
|
||||||
success: (result) => {
|
success: (result) => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
|
|
@ -194,11 +194,11 @@ Page({
|
||||||
if (type == 'edit') {
|
if (type == 'edit') {
|
||||||
this.goods_favor_event(id, goods_id, type);
|
this.goods_favor_event(id, goods_id, type);
|
||||||
} else {
|
} else {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: '温馨提示',
|
title: '温馨提示',
|
||||||
content: '删除后不可恢复,确定继续吗?',
|
content: '删除后不可恢复,确定继续吗?',
|
||||||
confirmButtonText: '确定',
|
confirmText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelText: '取消',
|
||||||
success: (result) => {
|
success: (result) => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
this.cart_delete(id, type);
|
this.cart_delete(id, type);
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ Page({
|
||||||
// 收藏事件
|
// 收藏事件
|
||||||
goods_favor_event(e)
|
goods_favor_event(e)
|
||||||
{
|
{
|
||||||
var user = app.GetUserInfo(this, 'goods_favor_event');
|
var user = app.get_user_info(this, 'goods_favor_event');
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -252,7 +252,7 @@ Page({
|
||||||
|
|
||||||
// 加入购物车事件
|
// 加入购物车事件
|
||||||
goods_cart_event(e, spec) {
|
goods_cart_event(e, spec) {
|
||||||
var user = app.GetUserInfo(this, 'goods_cart_event');
|
var user = app.get_user_info(this, 'goods_cart_event');
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -535,7 +535,7 @@ Page({
|
||||||
|
|
||||||
// 确认
|
// 确认
|
||||||
goods_buy_confirm_event(e) {
|
goods_buy_confirm_event(e) {
|
||||||
var user = app.GetUserInfo(this, 'goods_buy_confirm_event');
|
var user = app.get_user_info(this, 'goods_buy_confirm_event');
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Page({
|
||||||
// 设置用户信息
|
// 设置用户信息
|
||||||
this.setData({
|
this.setData({
|
||||||
params: option,
|
params: option,
|
||||||
user: app.GetUserCacheInfo() || null
|
user: app.get_user_cache_info() || null
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -30,8 +30,9 @@ Page({
|
||||||
* 登录授权事件
|
* 登录授权事件
|
||||||
*/
|
*/
|
||||||
get_user_info_event(e) {
|
get_user_info_event(e) {
|
||||||
console.log(e, e.detail.userInfo)
|
console.log(e, e.detail.userInfo);
|
||||||
app.user_auth_login();
|
//app.user_auth_login();
|
||||||
|
wx.navigateBack();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ Page({
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -120,11 +120,11 @@ Page({
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: "温馨提示",
|
title: "温馨提示",
|
||||||
content: "删除后不可恢复,确定继续吗?",
|
content: "删除后不可恢复,确定继续吗?",
|
||||||
confirmButtonText: "确认",
|
confirmText: "确认",
|
||||||
cancelButtonText: "不了",
|
cancelText: "不了",
|
||||||
success: result => {
|
success: result => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// 加载loding
|
// 加载loding
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -128,11 +128,11 @@ Page({
|
||||||
|
|
||||||
// 取消
|
// 取消
|
||||||
cancel_event(e) {
|
cancel_event(e) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: "温馨提示",
|
title: "温馨提示",
|
||||||
content: "取消后不可恢复,确定继续吗?",
|
content: "取消后不可恢复,确定继续吗?",
|
||||||
confirmButtonText: "确认",
|
confirmText: "确认",
|
||||||
cancelButtonText: "不了",
|
cancelText: "不了",
|
||||||
success: result => {
|
success: result => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// 参数
|
// 参数
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -127,11 +127,11 @@ Page({
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
delete_event(e) {
|
delete_event(e) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: "温馨提示",
|
title: "温馨提示",
|
||||||
content: "删除后不可恢复?,确定继续吗?",
|
content: "删除后不可恢复?,确定继续吗?",
|
||||||
confirmButtonText: "确认",
|
confirmText: "确认",
|
||||||
cancelButtonText: "不了",
|
cancelText: "不了",
|
||||||
success: result => {
|
success: result => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// 参数
|
// 参数
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var user = app.GetUserInfo(this, "init");
|
var user = app.get_user_info(this, "init");
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
|
|
@ -291,11 +291,11 @@ Page({
|
||||||
|
|
||||||
// 取消
|
// 取消
|
||||||
cancel_event(e) {
|
cancel_event(e) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: "温馨提示",
|
title: "温馨提示",
|
||||||
content: "取消后不可恢复,确定继续吗?",
|
content: "取消后不可恢复,确定继续吗?",
|
||||||
confirmButtonText: "确认",
|
confirmText: "确认",
|
||||||
cancelButtonText: "不了",
|
cancelText: "不了",
|
||||||
success: result => {
|
success: result => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// 参数
|
// 参数
|
||||||
|
|
@ -344,11 +344,11 @@ Page({
|
||||||
|
|
||||||
// 收货
|
// 收货
|
||||||
collect_event(e) {
|
collect_event(e) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: "温馨提示",
|
title: "温馨提示",
|
||||||
content: "请确认已收到货物或已完成,操作后不可恢复,确定继续吗?",
|
content: "请确认已收到货物或已完成,操作后不可恢复,确定继续吗?",
|
||||||
confirmButtonText: "确认",
|
confirmText: "确认",
|
||||||
cancelButtonText: "不了",
|
cancelText: "不了",
|
||||||
success: result => {
|
success: result => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// 参数
|
// 参数
|
||||||
|
|
|
||||||
|
|
@ -52,16 +52,16 @@ Page({
|
||||||
},
|
},
|
||||||
|
|
||||||
init(e) {
|
init(e) {
|
||||||
var user = app.GetUserInfo(this, "init"),
|
var user = app.get_user_info(this, "init"),
|
||||||
self = this;
|
self = this;
|
||||||
if (user != false) {
|
if (user != false) {
|
||||||
// 用户未绑定用户则转到登录页面
|
// 用户未绑定用户则转到登录页面
|
||||||
if ((user.mobile || null) == null) {
|
if ((user.mobile || null) == null) {
|
||||||
wx.confirm({
|
wx.showModal({
|
||||||
title: '温馨提示',
|
title: '温馨提示',
|
||||||
content: '绑定手机号码',
|
content: '绑定手机号码',
|
||||||
confirmButtonText: '确认',
|
confirmText: '确认',
|
||||||
cancelButtonText: '暂不',
|
cancelText: '暂不',
|
||||||
success: (result) => {
|
success: (result) => {
|
||||||
if(result.confirm) {
|
if(result.confirm) {
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue