Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
纵之格
ShopXO
提交
dd1fc7bd
ShopXO
项目概览
纵之格
/
ShopXO
通知
394
Star
16
Fork
11
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dd1fc7bd
编写于
9月 20, 2020
作者:
D
devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
百度小程序新增获取手机号码一键登录
上级
33f3ff6c
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
223 addition
and
29 deletion
+223
-29
application/api/controller/User.php
application/api/controller/User.php
+67
-11
application/service/UserService.php
application/service/UserService.php
+29
-1
changelog.txt
changelog.txt
+20
-0
extend/base/Baidu.php
extend/base/Baidu.php
+3
-2
sourcecode/baidu/app.js
sourcecode/baidu/app.js
+2
-2
sourcecode/baidu/app.json
sourcecode/baidu/app.json
+2
-1
sourcecode/baidu/pages/login/login.css
sourcecode/baidu/pages/login/login.css
+20
-5
sourcecode/baidu/pages/login/login.js
sourcecode/baidu/pages/login/login.js
+68
-6
sourcecode/baidu/pages/login/login.swan
sourcecode/baidu/pages/login/login.swan
+12
-1
未找到文件。
application/api/controller/User.php
浏览文件 @
dd1fc7bd
...
...
@@ -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
);
}
}
?>
\ No newline at end of file
application/service/UserService.php
浏览文件 @
dd1fc7bd
...
...
@@ -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
));
...
...
changelog.txt
浏览文件 @
dd1fc7bd
+=========================================================+
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
+=========================================================+
...
...
extend/base/Baidu.php
浏览文件 @
dd1fc7bd
...
...
@@ -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
];
...
...
sourcecode/baidu/app.js
浏览文件 @
dd1fc7bd
...
...
@@ -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}}
"
,
...
...
sourcecode/baidu/app.json
浏览文件 @
dd1fc7bd
{
"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"
,
...
...
sourcecode/baidu/pages/login/login.css
浏览文件 @
dd1fc7bd
...
...
@@ -17,7 +17,7 @@ page{
.content
input
{
font-size
:
28
rpx
;
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
:
10
rpx
;
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
:
30
rpx
;
}
/**
* 登录确认
*/
.login-logo
{
width
:
200
rpx
;
height
:
200
rpx
;
margin
:
0
auto
;
}
.submit-list
{
margin-top
:
100
rpx
;
}
.submit-list
button
:not
(
:last-child
)
{
margin-bottom
:
40
rpx
;
}
\ No newline at end of file
sourcecode/baidu/pages/login/login.js
浏览文件 @
dd1fc7bd
...
...
@@ -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
});
},
});
\ No newline at end of file
sourcecode/baidu/pages/login/login.swan
浏览文件 @
dd1fc7bd
<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>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录