diff --git a/application/api/controller/User.php b/application/api/controller/User.php
index 74cbcd6b3..b9e57ddc8 100755
--- a/application/api/controller/User.php
+++ b/application/api/controller/User.php
@@ -224,7 +224,7 @@ class User extends Common
{
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
- if(is_array($result))
+ if(!empty($result) && is_array($result))
{
$result['nick_name'] = isset($result['nickName']) ? $result['nickName'] : '';
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
@@ -591,37 +591,85 @@ class User extends Common
return DataReturn($ret, -1);
}
- // 先从数据库获取用户信息
- $user = UserService::AppUserInfoHandle(null, 'baidu_openid', $this->data_post['openid']);
- if(empty($user))
+ // 解密数据
+ $config = [
+ 'appid' => MyC('common_app_mini_baidu_appid'),
+ 'key' => MyC('common_app_mini_baidu_appkey'),
+ 'secret' => MyC('common_app_mini_baidu_appsecret'),
+ ];
+ $result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid'], 'mobile_bind');
+ if($result['status'] == 0 && !empty($result['data']))
{
- $config = [
- 'appid' => MyC('common_app_mini_baidu_appid'),
- 'key' => MyC('common_app_mini_baidu_appkey'),
- 'secret' => MyC('common_app_mini_baidu_appsecret'),
+ $data = [
+ 'openid' => $this->data_post['openid'],
+ 'mobile' => $result['data']['mobile'],
+ 'nickname' => isset($this->data_post['nickname']) ? $this->data_post['nickname'] : '',
+ 'avatar' => isset($this->data_post['avatar']) ? $this->data_post['avatar'] : '',
+ 'province' => isset($this->data_post['province']) ? $this->data_post['province'] : '',
+ 'city' => isset($this->data_post['city']) ? $this->data_post['city'] : '',
+ 'gender' => isset($this->data_post['gender']) ? intval($this->data_post['gender']) : '',
+ 'referrer' => isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0,
+ 'is_onekey_mobile_bind' => 1,
];
- $result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid'], 'mobile_bind');
- if($result['status'] == 0 && !empty($result['data']))
- {
- $data = [
- 'openid' => $this->data_post['openid'],
- 'mobile' => $result['data']['mobile'],
- 'nickname' => isset($this->data_post['nickname']) ? $this->data_post['nickname'] : '',
- 'avatar' => isset($this->data_post['avatar']) ? $this->data_post['avatar'] : '',
- 'province' => isset($this->data_post['province']) ? $this->data_post['province'] : '',
- 'city' => isset($this->data_post['city']) ? $this->data_post['city'] : '',
- 'gender' => isset($this->data_post['gender']) ? intval($this->data_post['gender']) : '',
- 'referrer' => isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0,
- 'is_onekey_mobile_bind' => 1,
- ];
- return UserService::AuthUserProgram($data, 'baidu_openid');
- } else {
- return DataReturn($result['msg'], -1);
- }
+ return UserService::AuthUserProgram($data, 'baidu_openid');
} else {
- return DataReturn('授权成功', 0, $user);
+ return DataReturn($result['msg'], -1);
+ }
+ }
+
+ /**
+ * 微信小程序用户手机绑定
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2020-09-20
+ * @desc description
+ */
+ public function WeixinUserMobileBind()
+ {
+ // 参数校验
+ $p = [
+ [
+ 'checked_type' => 'empty',
+ 'key_name' => 'openid',
+ 'error_msg' => 'openid为空',
+ ],
+ [
+ 'checked_type' => 'empty',
+ 'key_name' => 'encrypted_data',
+ 'error_msg' => '解密数据为空',
+ ],
+ [
+ 'checked_type' => 'empty',
+ 'key_name' => 'iv',
+ 'error_msg' => 'iv为空,请重试',
+ ]
+ ];
+ $ret = ParamsChecked($this->data_post, $p);
+ if($ret !== true)
+ {
+ return DataReturn($ret, -1);
+ }
+
+ // 解密数据
+ $result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
+ if(!empty($result) && is_array($result) && !empty($result['purePhoneNumber']))
+ {
+ $data = [
+ 'openid' => $this->data_post['openid'],
+ 'mobile' => $result['purePhoneNumber'],
+ 'nickname' => isset($this->data_post['nickname']) ? $this->data_post['nickname'] : '',
+ 'avatar' => isset($this->data_post['avatar']) ? $this->data_post['avatar'] : '',
+ 'province' => isset($this->data_post['province']) ? $this->data_post['province'] : '',
+ 'city' => isset($this->data_post['city']) ? $this->data_post['city'] : '',
+ 'gender' => isset($this->data_post['gender']) ? intval($this->data_post['gender']) : '',
+ 'referrer' => isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0,
+ 'is_onekey_mobile_bind' => 1,
+ ];
+ return UserService::AuthUserProgram($data, 'weixin_openid');
+ } else {
+ return DataReturn($result, -1);
}
- return DataReturn(empty($result) ? '获取用户手机号码失败' : $result, -100);
}
}
?>
\ No newline at end of file
diff --git a/application/service/UserService.php b/application/service/UserService.php
index e2ce16571..019e1db46 100755
--- a/application/service/UserService.php
+++ b/application/service/UserService.php
@@ -1708,10 +1708,31 @@ class UserService
'referrer' => isset($params['referrer']) ? $params['referrer'] : 0,
];
+ // 是否一键登录
+ $is_onekey_mobile_bind = isset($params['is_onekey_mobile_bind']) && $params['is_onekey_mobile_bind'] == 1 ? 1 : 0;
+
// 用户信息处理
$user = self::AppUserInfoHandle(null, $field, $params['openid']);
if(!empty($user))
{
+ // 如果是一键登录、如当前用户不存在手机号码则绑定
+ if(empty($user['mobile']) && !empty($data['mobile']) && $is_onekey_mobile_bind == 1)
+ {
+ // 手机号码不存在则绑定到当前账号下
+ $temp = self::AppUserInfoHandle(null, 'mobile', $data['mobile']);
+ if(empty($temp))
+ {
+ $upd_data = [
+ 'mobile' => $data['mobile'],
+ 'upd_time' => time(),
+ ];
+ if(Db::name('User')->where(['id'=>$user['id']])->update($upd_data))
+ {
+ return DataReturn('绑定成功', 0, self::AppUserInfoHandle($user['id']));
+ }
+ }
+ }
+
return DataReturn('授权成功', 0, $user);
} else {
// 用户unionid
@@ -1723,11 +1744,24 @@ class UserService
if(!empty($user_unionid))
{
// openid绑定
- if(Db::name('User')->where(['id'=>$user_unionid['id']])->update([$field=>$params['openid'], 'upd_time'=>time()]))
+ $upd_data = [
+ $field => $params['openid'],
+ 'upd_time' => time(),
+ ];
+
+ // 如果是一键登录、如当前用户不存在手机号码则绑定
+ if(empty($user['mobile']) && !empty($data['mobile']) && $is_onekey_mobile_bind == 1)
{
- // 直接返回用户信息
- $user_unionid[$field] = $params['openid'];
- return DataReturn('授权成功', 0, $user_unionid);
+ // 手机号码不存在则绑定到当前账号下
+ $temp = self::AppUserInfoHandle(null, 'mobile', $data['mobile']);
+ if(empty($temp))
+ {
+ $upd_data['mobile'] = $data['mobile'];
+ }
+ }
+ if(Db::name('User')->where(['id'=>$user_unionid['id']])->update($upd_data))
+ {
+ return DataReturn('绑定成功', 0, self::AppUserInfoHandle($user_unionid['id']));
}
}
@@ -1747,7 +1781,7 @@ class UserService
}
} else {
// 强制绑定手机号码、是否一键获取操作绑定
- if(isset($params['is_onekey_mobile_bind']) && $params['is_onekey_mobile_bind'] == 1 && !empty($data['mobile']))
+ if($is_onekey_mobile_bind == 1 && !empty($data['mobile']))
{
// 如果手机号码存在则直接绑定openid
// 不存在添加,存在更新openid
diff --git a/sourcecode/baidu/app.json b/sourcecode/baidu/app.json
index 1ff142845..b15ce9bc5 100755
--- a/sourcecode/baidu/app.json
+++ b/sourcecode/baidu/app.json
@@ -1,12 +1,11 @@
{
"pages": [
- "pages/login/login",
"pages/index/index",
"pages/goods-category/goods-category",
"pages/cart/cart",
"pages/user/user",
"pages/web-view/web-view",
-
+ "pages/login/login",
"pages/paytips/paytips",
"pages/goods-search/goods-search",
"pages/goods-detail/goods-detail",
diff --git a/sourcecode/baidu/pages/login/login.js b/sourcecode/baidu/pages/login/login.js
index 0cd4d8aa6..a48696a08 100755
--- a/sourcecode/baidu/pages/login/login.js
+++ b/sourcecode/baidu/pages/login/login.js
@@ -203,12 +203,12 @@ Page({
"encrypted_data": encrypted_data,
"iv": iv,
"openid": this.data.user.baidu_openid,
- "nickname": this.data.user.nickname,
- "avatar": this.data.user.avatar,
- "province": this.data.user.province,
- "city": this.data.user.city,
- "gender": this.data.user.gender,
- "referrer": referrer
+ "nickname": this.data.user.nickname || '',
+ "avatar": this.data.user.avatar || '',
+ "province": this.data.user.province || '',
+ "city": this.data.user.city || '',
+ "gender": this.data.user.gender || 0,
+ "referrer": referrer || 0
};
swan.showLoading({ title: "处理中..." });
var self = this;
diff --git a/sourcecode/baidu/pages/login/login.swan b/sourcecode/baidu/pages/login/login.swan
index 00502a6f9..5f05d0e58 100755
--- a/sourcecode/baidu/pages/login/login.swan
+++ b/sourcecode/baidu/pages/login/login.swan
@@ -9,19 +9,19 @@
-
+
- {{user.nickname}}
+ {{user.nickname}}
-
+
-
+
确认登录授权,为您提供更优质的服务
diff --git a/sourcecode/weixin/app.js b/sourcecode/weixin/app.js
index 0036ea296..16dc93f54 100755
--- a/sourcecode/weixin/app.js
+++ b/sourcecode/weixin/app.js
@@ -71,7 +71,7 @@ App({
// 请求地址
request_url: "{{request_url}}",
request_url: 'http://shopxo.com/',
- request_url: 'https://dev.shopxo.net/',
+ // request_url: 'https://dev.shopxo.net/',
// 基础信息
application_title: "{{application_title}}",
diff --git a/sourcecode/weixin/pages/login/login.js b/sourcecode/weixin/pages/login/login.js
index f25b4fd8e..523093204 100755
--- a/sourcecode/weixin/pages/login/login.js
+++ b/sourcecode/weixin/pages/login/login.js
@@ -10,20 +10,38 @@ Page({
form_submit_loading: false,
verify_time_total: 60,
temp_clear_time: null,
+
+ // 基础配置
+ // 0 确认绑定方式, 1 验证码绑定
+ login_type_status: 0,
+ common_user_is_onekey_bind_mobile: 0,
},
- /**
- * 页面加载初始化
- */
+ // 页面加载初始化
onLoad(option) {
- // 设置用户信息
this.setData({
params: option,
user: app.get_user_cache_info() || null
});
+ },
- // 标题设置
+ // 页面显示
+ onShow() {
wx.setNavigationBarTitle({ title: (this.data.user == null) ? '授权用户信息' : '手机绑定' });
+
+ // 初始化配置
+ this.init_config();
+ },
+
+ // 初始化配置
+ init_config(status) {
+ if((status || false) == true) {
+ this.setData({
+ common_user_is_onekey_bind_mobile: app.get_config('config.common_user_is_onekey_bind_mobile'),
+ });
+ } else {
+ app.is_config(this, 'init_config');
+ }
},
/**
@@ -104,14 +122,12 @@ Page({
}, 1000);
} else {
this.setData({verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false});
-
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
this.setData({verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false});
-
app.showToast("服务器请求出错");
}
});
@@ -178,18 +194,82 @@ Page({
}, 1000);
} else {
this.setData({form_submit_loading: false});
-
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
this.setData({form_submit_loading: false});
-
app.showToast("服务器请求出错");
}
});
}
- }
+ },
+
+ // 获取手机号码一键登录
+ confirm_phone_number_event(e) {
+ var encrypted_data = e.detail.encryptedData || null;
+ var iv = e.detail.iv || null;
+ if(encrypted_data != null && iv != null) {
+ // 邀请人参数
+ var params = wx.getStorageSync(this.data.cache_launch_info_key) || null;
+ var referrer = (params == null) ? 0 : (params.referrer || 0);
+
+ // 解密数据并绑定手机
+ var data = {
+ "encrypted_data": encrypted_data,
+ "iv": iv,
+ "openid": this.data.user.weixin_openid,
+ "nickname": this.data.user.nickname || '',
+ "avatar": this.data.user.avatar || '',
+ "province": this.data.user.province || '',
+ "city": this.data.user.city || '',
+ "gender": this.data.user.gender || 0,
+ "referrer": referrer || 0
+ };
+ wx.showLoading({ title: "处理中..." });
+ var self = this;
+ wx.request({
+ url: app.get_request_url('weixinusermobilebind', 'user'),
+ method: 'POST',
+ data: data,
+ dataType: 'json',
+ header: { 'content-type': 'application/x-www-form-urlencoded' },
+ success: (res) => {
+ wx.hideLoading();
+ if (res.data.code == 0 && (res.data.data || null) != null) {
+ app.showToast(res.data.msg, 'success');
+
+ wx.setStorage({
+ key: app.data.cache_user_info_key,
+ data: res.data.data
+ });
+
+ var event_callback = this.data.params.event_callback || null;
+ setTimeout(function()
+ {
+ // 触发回调函数
+ if(event_callback != null)
+ {
+ getCurrentPages()[getCurrentPages().length-2][event_callback]();
+ }
+ wx.navigateBack();
+ }, 1000);
+ } else {
+ app.showToast(res.data.msg);
+ }
+ },
+ fail: () => {
+ wx.hideLoading();
+ self.showToast('服务器请求出错');
+ },
+ });
+ }
+ },
+
+ // 确认使用验证码
+ confirm_verify_event(e) {
+ this.setData({login_type_status: 1});
+ },
});
diff --git a/sourcecode/weixin/pages/login/login.wxml b/sourcecode/weixin/pages/login/login.wxml
index 7a05fe491..c62c6a7de 100755
--- a/sourcecode/weixin/pages/login/login.wxml
+++ b/sourcecode/weixin/pages/login/login.wxml
@@ -1,5 +1,6 @@
-
+
+
+
+
+ {{user.nickname}}
+
+
+
+
+
-
+
+
确认登录授权,为您提供更优质的服务
diff --git a/sourcecode/weixin/pages/login/login.wxss b/sourcecode/weixin/pages/login/login.wxss
index c899160a2..d3359998f 100755
--- a/sourcecode/weixin/pages/login/login.wxss
+++ b/sourcecode/weixin/pages/login/login.wxss
@@ -7,7 +7,7 @@ page{
height: 100vh;
}
.content {
- padding: 30% 40rpx 0 40rpx;
+ padding: 25% 40rpx 0 40rpx;
}
.content .mobile{
width: 100%;
@@ -60,4 +60,23 @@ page{
}
.user-login button {
margin-top: 30rpx;
+}
+
+/**
+ * 登录确认
+ */
+.confirm-container .login-logo {
+ width: 200rpx;
+ height: 200rpx;
+ margin: 0 auto;
+ border-radius: 50%;
+}
+.confirm-container .nickname {
+ margin-top: 10rpx;
+}
+.confirm-container .submit-list {
+ margin-top: 100rpx;
+}
+.confirm-container .submit-list button:not(:last-child) {
+ margin-bottom: 40rpx;
}
\ No newline at end of file