mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-11-30 02:49:03 +08:00
百度小程序新增获取手机号码一键登录
This commit is contained in:
parent
33f3ff6c81
commit
dd1fc7bd54
@ -544,10 +544,6 @@ class User extends Common
|
||||
'avatar' => $this->user['avatar'],
|
||||
'nickname' => $this->user['nickname'],
|
||||
'username' => $this->user['username'],
|
||||
// 'customer_service_tel' => MyC('common_app_customer_service_tel', null, true),
|
||||
// 'common_user_center_notice' => MyC('common_user_center_notice', null, true),
|
||||
// 'common_app_is_online_service' => (int) MyC('common_app_is_online_service', 0),
|
||||
// 'common_app_is_head_vice_nav' => (int) MyC('common_app_is_head_vice_nav', 0),
|
||||
'user_order_status' => $user_order_status['data'],
|
||||
'user_order_count' => $user_order_count,
|
||||
'user_goods_favor_count' => $user_goods_favor_count,
|
||||
@ -557,15 +553,75 @@ class User extends Common
|
||||
'common_cart_total' => BuyService::UserCartTotal(['user'=>$this->user]),
|
||||
);
|
||||
|
||||
// 支付宝小程序在线客服
|
||||
// if(APPLICATION_CLIENT_TYPE == 'alipay')
|
||||
// {
|
||||
// $result['common_app_mini_alipay_tnt_inst_id'] = MyC('common_app_mini_alipay_tnt_inst_id', null, true);
|
||||
// $result['common_app_mini_alipay_scene'] = MyC('common_app_mini_alipay_scene', null, true);
|
||||
// }
|
||||
|
||||
// 返回数据
|
||||
return DataReturn('success', 0, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度小程序用户手机绑定
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2020-09-20
|
||||
* @desc description
|
||||
*/
|
||||
public function BaiduUserMobileBind()
|
||||
{
|
||||
// 参数校验
|
||||
$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);
|
||||
}
|
||||
|
||||
// 先从数据库获取用户信息
|
||||
$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']))
|
||||
{
|
||||
$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);
|
||||
}
|
||||
} else {
|
||||
return DataReturn('授权成功', 0, $user);
|
||||
}
|
||||
return DataReturn(empty($result) ? '获取用户手机号码失败' : $result, -100);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1704,6 +1704,7 @@ class UserService
|
||||
'gender' => empty($params['gender']) ? 0 : intval($params['gender']),
|
||||
'province' => empty($params['province']) ? '' : $params['province'],
|
||||
'city' => empty($params['city']) ? '' : $params['city'],
|
||||
'mobile' => empty($params['mobile']) ? '' : $params['mobile'],
|
||||
'referrer' => isset($params['referrer']) ? $params['referrer'] : 0,
|
||||
];
|
||||
|
||||
@ -1718,7 +1719,7 @@ class UserService
|
||||
if(!empty($unionid['field']) && !empty($unionid['value']))
|
||||
{
|
||||
// unionid字段是否存在用户
|
||||
$user_unionid = UserService::AppUserInfoHandle(null, $unionid['field'], $unionid['value']);
|
||||
$user_unionid = self::AppUserInfoHandle(null, $unionid['field'], $unionid['value']);
|
||||
if(!empty($user_unionid))
|
||||
{
|
||||
// openid绑定
|
||||
@ -1744,6 +1745,33 @@ class UserService
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
} else {
|
||||
// 强制绑定手机号码、是否一键获取操作绑定
|
||||
if(isset($params['is_onekey_mobile_bind']) && $params['is_onekey_mobile_bind'] == 1 && !empty($data['mobile']))
|
||||
{
|
||||
// 如果手机号码存在则直接绑定openid
|
||||
// 不存在添加,存在更新openid
|
||||
$user = self::AppUserInfoHandle(null, 'mobile', $data['mobile']);
|
||||
if(!empty($user))
|
||||
{
|
||||
$upd_data = [
|
||||
$field => $params['openid'],
|
||||
'upd_time' => time(),
|
||||
];
|
||||
if(Db::name('User')->where(['id'=>$user['id']])->update($upd_data))
|
||||
{
|
||||
return DataReturn('绑定成功', 0, self::AppUserInfoHandle($user['id']));
|
||||
}
|
||||
} else {
|
||||
$ret = self::UserInsert($data, $params);
|
||||
if($ret['code'] == 0)
|
||||
{
|
||||
return DataReturn('绑定成功', 0, self::AppUserInfoHandle($ret['data']['user_id']));
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataReturn('授权成功', 0, self::AppUserInfoHandle(null, null, null, $data));
|
||||
|
@ -1,3 +1,23 @@
|
||||
+=========================================================+
|
||||
ShopXO 1.9.1 Release --- http://shopxo.net
|
||||
+=========================================================+
|
||||
全局
|
||||
1. 支持货币功能
|
||||
2. 新增快捷导航
|
||||
3. 新增商品属性参数
|
||||
4. 新增附件、css/js静态可配置CDN域名
|
||||
5. 网站首页可后台控制配置
|
||||
|
||||
web端
|
||||
1.
|
||||
|
||||
小程序
|
||||
1. QQ小程序支持微信支付
|
||||
|
||||
插件
|
||||
1. 汇率插件支持货币自由切换
|
||||
|
||||
|
||||
+=========================================================+
|
||||
ShopXO 1.9.0 Release 20200818 http://shopxo.net
|
||||
+=========================================================+
|
||||
|
@ -50,9 +50,10 @@ class Baidu
|
||||
* @param [string] $encrypted_data [加密的用户数据]
|
||||
* @param [string] $iv [与用户数据一同返回的初始向量]
|
||||
* @param [string] $openid [解密后的原文]
|
||||
* @param [string] $key [当时业务key]
|
||||
* @return [array|string] [成功返回用户信息数组, 失败返回错误信息]
|
||||
*/
|
||||
public function DecryptData($encrypted_data, $iv, $openid)
|
||||
public function DecryptData($encrypted_data, $iv, $openid, $key = 'user_info')
|
||||
{
|
||||
// 登录授权session
|
||||
$login_key = 'baidu_user_login_'.$openid;
|
||||
@ -111,7 +112,7 @@ class Baidu
|
||||
}
|
||||
|
||||
// 缓存存储
|
||||
$data_key = 'baidu_user_info_'.$openid;
|
||||
$data_key = 'baidu_'.$key.'_'.$openid;
|
||||
cache($data_key, $data);
|
||||
|
||||
return ['status'=>0, 'data'=>$data];
|
||||
|
@ -70,8 +70,8 @@ App({
|
||||
|
||||
// 请求地址
|
||||
request_url: "{{request_url}}",
|
||||
// request_url: 'http://shopxo.com/',
|
||||
request_url: 'https://dev.shopxo.net/',
|
||||
request_url: 'http://shopxo.com/',
|
||||
// request_url: 'https://dev.shopxo.net/',
|
||||
|
||||
// 基础信息
|
||||
application_title: "{{application_title}}",
|
||||
|
@ -1,11 +1,12 @@
|
||||
{
|
||||
"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",
|
||||
|
@ -17,7 +17,7 @@ page{
|
||||
.content input{
|
||||
font-size: 28rpx;
|
||||
color: #4e4e4e;
|
||||
height: 40px;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
}
|
||||
.content .code{
|
||||
@ -26,13 +26,13 @@ page{
|
||||
position: relative;
|
||||
}
|
||||
.content .code .verify{
|
||||
width: 63%;
|
||||
width: 63%;
|
||||
}
|
||||
.content .code .verify-sub{
|
||||
border: solid 1px #ff6482;
|
||||
border: solid 1px #ff6482;
|
||||
color: #ff6482;
|
||||
width: 35%;
|
||||
height: 35px;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
border-radius: 10rpx;
|
||||
position: absolute;
|
||||
@ -40,7 +40,7 @@ page{
|
||||
right: 0;
|
||||
}
|
||||
.content .code .verify-sub.sub-disabled{
|
||||
border: solid 1px #eee;
|
||||
border: solid 1px #eee;
|
||||
color: #a6a6a6
|
||||
}
|
||||
.content .submit{
|
||||
@ -60,4 +60,19 @@ page{
|
||||
}
|
||||
.user-login button {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录确认
|
||||
*/
|
||||
.login-logo {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.submit-list {
|
||||
margin-top: 100rpx;
|
||||
}
|
||||
.submit-list button:not(:last-child) {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
@ -9,7 +9,9 @@ Page({
|
||||
verify_disabled: false,
|
||||
form_submit_loading: false,
|
||||
verify_time_total: 60,
|
||||
temp_clear_time: null
|
||||
temp_clear_time: null,
|
||||
// 0确认页面, 1验证码绑定, 2一键获取绑定
|
||||
login_status: 2,
|
||||
},
|
||||
|
||||
/**
|
||||
@ -97,14 +99,12 @@ Page({
|
||||
}, 1000);
|
||||
} else {
|
||||
this.setData({ verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false });
|
||||
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.hideLoading();
|
||||
this.setData({ verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false });
|
||||
|
||||
app.showToast("服务器请求出错");
|
||||
}
|
||||
});
|
||||
@ -161,18 +161,80 @@ Page({
|
||||
}, 1000);
|
||||
} else {
|
||||
this.setData({ form_submit_loading: false });
|
||||
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.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 = swan.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.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
|
||||
};
|
||||
swan.showLoading({ title: "处理中..." });
|
||||
var self = this;
|
||||
swan.request({
|
||||
url: app.get_request_url('baiduusermobilebind', 'user'),
|
||||
method: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
header: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
success: (res) => {
|
||||
swan.hideLoading();
|
||||
if (res.data.code == 0 && (res.data.data || null) != null) {
|
||||
app.showToast(res.data.msg, 'success');
|
||||
|
||||
swan.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]();
|
||||
}
|
||||
swan.navigateBack();
|
||||
}, 1000);
|
||||
} else {
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.hideLoading();
|
||||
self.showToast('服务器请求出错');
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 确认使用验证码
|
||||
confirm_verify_event(e) {
|
||||
this.setData({login_status: 1});
|
||||
},
|
||||
|
||||
});
|
@ -1,5 +1,6 @@
|
||||
<view s-if="user != null" class="content">
|
||||
<form bindsubmit="formSubmit">
|
||||
<!-- 表单验证码 -->
|
||||
<form s-if="login_status == 1" bindsubmit="formSubmit">
|
||||
<input type="number" placeholder="输入手机号码" maxlength="11" name="mobile" bindinput="bind_key_input" class="mobile" />
|
||||
<view class="code clearfix">
|
||||
<input type="number" placeholder="验证码" maxlength="4" name="verify" class="verify" />
|
||||
@ -7,8 +8,18 @@
|
||||
</view>
|
||||
<button type="default" formType="submit" hover-class="none" plain loading="{{form_submit_loading}}" disabled="{{form_submit_loading}}" class="submit {{form_submit_loading ? 'my-btn-gray' : 'my-btn-default'}}">确认绑定</button>
|
||||
</form>
|
||||
|
||||
<!-- 确认授权方式 -->
|
||||
<view s-if="login_status == 2" class="tc">
|
||||
<image class="login-logo" src="/images/user-nav-customer-service-icon.png" mode="widthFix" />
|
||||
<view class="submit-list">
|
||||
<button type="warn" class="mobile-submit" open-type="getPhoneNumber" bindgetphonenumber="confirm_phone_number_event">获取手机号码一键登录</button>
|
||||
<button type="warn" class="mobile-submit" plain="{{true}}" bindtap="confirm_verify_event">验证码登录</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 获取用户信息授权 -->
|
||||
<view s-if="user == null" class="user-login tc">
|
||||
<view class="cr-888 fs-12">确认登录授权,为您提供更优质的服务</view>
|
||||
<button type="primary" size="mini" open-type="getUserInfo" bindgetuserinfo="get_user_info_event">授权登录</button>
|
||||
|
Loading…
Reference in New Issue
Block a user