提交 7bc0f078 编写于 作者: D devil_gong

微信小程序登录

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