Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
7e159890
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
730
Star
38706
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7e159890
编写于
11月 17, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: univerify
上级
ac1c9ca4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
132 addition
and
99 deletion
+132
-99
lib/apis.js
lib/apis.js
+3
-0
src/core/helpers/protocol/plugin/pre-login.js
src/core/helpers/protocol/plugin/pre-login.js
+16
-0
src/platforms/app-plus/service/api/plugin/oauth.js
src/platforms/app-plus/service/api/plugin/oauth.js
+103
-98
src/platforms/app-plus/service/api/util.js
src/platforms/app-plus/service/api/util.js
+10
-1
未找到文件。
lib/apis.js
浏览文件 @
7e159890
...
@@ -204,6 +204,9 @@ const third = [
...
@@ -204,6 +204,9 @@ const third = [
'
login
'
,
'
login
'
,
'
checkSession
'
,
'
checkSession
'
,
'
getUserInfo
'
,
'
getUserInfo
'
,
'
preLogin
'
,
'
onAuthViewOtherLoginButtonClick
'
,
'
closeAuthView
'
,
'
share
'
,
'
share
'
,
'
shareWithSystem
'
,
'
shareWithSystem
'
,
'
showShareMenu
'
,
'
showShareMenu
'
,
...
...
src/core/helpers/protocol/plugin/pre-login.js
0 → 100644
浏览文件 @
7e159890
const
provider
=
{
UNIVERIFY
:
'
univerify
'
}
export
const
preLogin
=
{
provider
:
{
type
:
String
,
required
:
true
,
default
:
provider
.
UNIVERIFY
,
validator
(
value
,
params
)
{
if
(
Object
.
values
(
provider
).
indexOf
(
value
)
<
0
)
{
return
'
provider error
'
}
}
}
}
src/platforms/app-plus/service/api/plugin/oauth.js
浏览文件 @
7e159890
import
{
import
{
invoke
invoke
}
from
'
../../bridge
'
}
from
'
../../bridge
'
import
{
warpPlusSuccessCallback
,
warpPlusErrorCallback
}
from
'
../util
'
const
loginServices
=
{}
function
getService
(
provider
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
loginByService
=
(
provider
,
callbackId
)
=>
{
plus
.
oauth
.
getServices
(
services
=>
{
function
login
()
{
const
service
=
services
.
find
(({
id
})
=>
id
===
provider
)
loginServices
[
provider
].
login
(
res
=>
{
service
?
resolve
(
service
)
:
reject
(
new
Error
(
'
provider not find
'
))
const
authResult
=
res
.
target
.
authResult
},
reject
)
invoke
(
callbackId
,
{
})
code
:
authResult
.
code
,
authResult
:
authResult
,
errMsg
:
'
login:ok
'
})
},
err
=>
{
invoke
(
callbackId
,
{
code
:
err
.
code
,
errMsg
:
'
login:fail:
'
+
err
.
message
})
},
provider
===
'
apple
'
?
{
scope
:
'
email
'
}
:
{})
}
// 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname
if
(
provider
===
'
apple
'
)
{
login
()
}
else
{
loginServices
[
provider
].
logout
(
login
,
login
)
}
}
}
/**
/**
* 微信登录
* 微信登录
*/
*/
export
function
login
(
params
,
callbackId
)
{
export
function
login
(
params
,
callbackId
)
{
const
provider
=
params
.
provider
||
'
weixin
'
const
provider
=
params
.
provider
||
'
weixin
'
if
(
loginServices
[
provider
])
{
getService
(
provider
).
then
(
service
=>
{
loginByService
(
provider
,
callbackId
)
function
login
()
{
}
else
{
service
.
login
(
res
=>
{
plus
.
oauth
.
getServices
(
services
=>
{
const
authResult
=
res
.
target
.
authResult
loginServices
[
provider
]
=
services
.
find
(({
id
})
=>
id
===
provider
)
if
(
!
loginServices
[
provider
])
{
invoke
(
callbackId
,
{
invoke
(
callbackId
,
{
code
:
''
,
code
:
authResult
.
code
,
errMsg
:
'
login:fail:登录服务[
'
+
provider
+
'
]不存在
'
authResult
:
authResult
,
errMsg
:
'
login:ok
'
})
})
}
else
{
},
err
=>
{
loginByService
(
provider
,
callbackId
)
invoke
(
callbackId
,
{
}
code
:
err
.
code
,
},
err
=>
{
errMsg
:
'
login:fail:
'
+
err
.
message
invoke
(
callbackId
,
{
})
code
:
err
.
code
,
},
provider
===
'
apple
'
?
{
scope
:
'
email
'
}
:
params
.
univerifyStyle
||
{})
errMsg
:
'
login:fail:
'
+
err
.
message
}
})
// 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname
if
(
provider
===
'
apple
'
)
{
login
()
}
else
{
service
.
logout
(
login
,
login
)
}
}).
catch
(
err
=>
{
invoke
(
callbackId
,
{
code
:
err
.
code
||
''
,
errMsg
:
'
login:fail:
'
+
err
.
message
})
})
}
}
)
}
}
export
function
getUserInfo
(
params
,
callbackId
)
{
export
function
getUserInfo
(
params
,
callbackId
)
{
const
provider
=
params
.
provider
||
'
weixin
'
const
provider
=
params
.
provider
||
'
weixin
'
const
loginService
=
loginServices
[
provider
]
const
errorCallback
=
warpPlusErrorCallback
(
callbackId
,
'
operateWXData
'
)
if
(
!
loginService
||
!
loginService
.
authResult
)
{
getService
(
provider
).
then
(
loginService
=>
{
return
invoke
(
callbackId
,
{
loginService
.
getUserInfo
(
res
=>
{
errMsg
:
'
operateWXData:fail:请先调用 uni.login
'
let
userInfo
})
if
(
provider
===
'
weixin
'
)
{
}
const
wechatUserInfo
=
loginService
.
userInfo
loginService
.
getUserInfo
(
res
=>
{
userInfo
=
{
let
userInfo
openId
:
wechatUserInfo
.
openid
,
if
(
provider
===
'
weixin
'
)
{
nickName
:
wechatUserInfo
.
nickname
,
const
wechatUserInfo
=
loginService
.
userInfo
gender
:
wechatUserInfo
.
sex
,
userInfo
=
{
city
:
wechatUserInfo
.
city
,
openId
:
wechatUserInfo
.
openid
,
province
:
wechatUserInfo
.
province
,
nickName
:
wechatUserInfo
.
nickname
,
country
:
wechatUserInfo
.
country
,
gender
:
wechatUserInfo
.
sex
,
avatarUrl
:
wechatUserInfo
.
headimgurl
,
city
:
wechatUserInfo
.
city
,
unionId
:
wechatUserInfo
.
unionid
province
:
wechatUserInfo
.
province
,
}
country
:
wechatUserInfo
.
country
,
}
else
if
(
provider
===
'
apple
'
)
{
avatarUrl
:
wechatUserInfo
.
headimgurl
,
const
appleInfo
=
loginService
.
appleInfo
unionId
:
wechatUserInfo
.
unionid
userInfo
=
{
openId
:
appleInfo
.
user
,
fullName
:
appleInfo
.
fullName
,
email
:
appleInfo
.
email
,
authorizationCode
:
appleInfo
.
authorizationCode
,
identityToken
:
appleInfo
.
identityToken
,
realUserStatus
:
appleInfo
.
realUserStatus
}
}
else
{
userInfo
=
loginService
.
userInfo
userInfo
.
openId
=
userInfo
.
openId
||
userInfo
.
openid
||
loginService
.
authResult
.
openid
userInfo
.
nickName
=
userInfo
.
nickName
||
userInfo
.
nickname
userInfo
.
avatarUrl
=
userInfo
.
avatarUrl
||
userInfo
.
headimgurl
}
}
}
else
if
(
provider
===
'
apple
'
)
{
const
result
=
{
const
appleInfo
=
loginService
.
appleInfo
errMsg
:
'
operateWXData:ok
'
userInfo
=
{
}
openId
:
appleInfo
.
user
,
if
(
params
.
data
&&
params
.
data
.
api_name
===
'
webapi_getuserinfo
'
)
{
fullName
:
appleInfo
.
fullName
,
result
.
data
=
{
email
:
appleInfo
.
email
,
data
:
JSON
.
stringify
(
userInfo
),
authorizationCode
:
appleInfo
.
authorizationCode
,
rawData
:
''
,
identityToken
:
appleInfo
.
identityToken
,
signature
:
''
,
realUserStatus
:
appleInfo
.
realUserStatus
encryptedData
:
''
,
}
iv
:
''
}
else
{
}
loginService
.
userInfo
.
openId
=
loginService
.
userInfo
.
openId
||
loginService
.
userInfo
.
openid
||
}
else
{
loginService
.
authResult
.
openid
result
.
userInfo
=
userInfo
loginService
.
userInfo
.
nickName
=
loginService
.
userInfo
.
nickName
||
loginService
.
userInfo
.
nickname
}
loginService
.
userInfo
.
avatarUrl
=
loginService
.
userInfo
.
avatarUrl
||
loginService
.
userInfo
.
avatarUrl
||
invoke
(
callbackId
,
result
)
loginService
.
userInfo
.
headimgurl
},
errorCallback
)
userInfo
=
loginService
.
userInfo
}).
catch
(()
=>
{
}
const
result
=
{
errMsg
:
'
operateWXData:ok
'
}
if
(
params
.
data
&&
params
.
data
.
api_name
===
'
webapi_getuserinfo
'
)
{
result
.
data
=
{
data
:
JSON
.
stringify
(
userInfo
),
rawData
:
''
,
signature
:
''
,
encryptedData
:
''
,
iv
:
''
}
}
else
{
result
.
userInfo
=
userInfo
}
invoke
(
callbackId
,
result
)
},
err
=>
{
invoke
(
callbackId
,
{
invoke
(
callbackId
,
{
errMsg
:
'
operateWXData:fail:
'
+
err
.
message
errMsg
:
'
operateWXData:fail:
请先调用 uni.login
'
})
})
})
})
}
}
...
@@ -133,3 +122,19 @@ export function operateWXData (params, callbackId) {
...
@@ -133,3 +122,19 @@ export function operateWXData (params, callbackId) {
}
}
}
}
}
}
export
function
preLogin
(
params
,
callbackId
)
{
const
successCallback
=
warpPlusSuccessCallback
(
callbackId
,
'
preLogin
'
)
const
errorCallback
=
warpPlusErrorCallback
(
callbackId
,
'
preLogin
'
)
getService
(
params
.
provider
).
then
(
service
=>
service
.
preLogin
(
successCallback
,
errorCallback
)).
catch
(
errorCallback
)
}
export
function
onAuthViewOtherLoginButtonClick
(
callbackId
)
{
getService
(
'
univerify
'
).
then
(
service
=>
service
.
onOtherLoginButtonClick
(()
=>
{
invoke
(
callbackId
,
{})
}))
}
export
function
closeAuthView
()
{
getService
(
'
univerify
'
).
then
(
service
=>
service
.
closeAuthView
())
}
\ No newline at end of file
src/platforms/app-plus/service/api/util.js
浏览文件 @
7e159890
...
@@ -178,6 +178,15 @@ export function warpPlusEvent (module, name) {
...
@@ -178,6 +178,15 @@ export function warpPlusEvent (module, name) {
}
}
}
}
export
function
warpPlusSuccessCallback
(
callbackId
,
neme
)
{
return
function
errorCallback
(
result
)
{
result
=
result
||
{}
invoke
(
callbackId
,
Object
.
assign
({},
result
,
{
errMsg
:
`
${
neme
}
:ok`
}))
}
}
export
function
warpPlusErrorCallback
(
callbackId
,
neme
,
errMsg
)
{
export
function
warpPlusErrorCallback
(
callbackId
,
neme
,
errMsg
)
{
return
function
errorCallback
(
error
)
{
return
function
errorCallback
(
error
)
{
error
=
error
||
{}
error
=
error
||
{}
...
@@ -214,4 +223,4 @@ export function getFileName (path) {
...
@@ -214,4 +223,4 @@ export function getFileName (path) {
export
function
getExtName
(
path
)
{
export
function
getExtName
(
path
)
{
const
array
=
path
.
split
(
'
.
'
)
const
array
=
path
.
split
(
'
.
'
)
return
array
.
length
>
1
?
'
.
'
+
array
[
array
.
length
-
1
]
:
''
return
array
.
length
>
1
?
'
.
'
+
array
[
array
.
length
-
1
]
:
''
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录