Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_38335589
uni-app
提交
7e159890
U
uni-app
项目概览
weixin_38335589
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
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 = [
'
login
'
,
'
checkSession
'
,
'
getUserInfo
'
,
'
preLogin
'
,
'
onAuthViewOtherLoginButtonClick
'
,
'
closeAuthView
'
,
'
share
'
,
'
shareWithSystem
'
,
'
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
{
invoke
}
from
'
../../bridge
'
import
{
warpPlusSuccessCallback
,
warpPlusErrorCallback
}
from
'
../util
'
const
loginServices
=
{}
function
getService
(
provider
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
plus
.
oauth
.
getServices
(
services
=>
{
const
service
=
services
.
find
(({
id
})
=>
id
===
provider
)
service
?
resolve
(
service
)
:
reject
(
new
Error
(
'
provider not find
'
))
},
reject
)
})
}
const
loginByService
=
(
provider
,
callbackId
)
=>
{
/**
* 微信登录
*/
export
function
login
(
params
,
callbackId
)
{
const
provider
=
params
.
provider
||
'
weixin
'
getService
(
provider
).
then
(
service
=>
{
function
login
()
{
loginServices
[
provider
]
.
login
(
res
=>
{
service
.
login
(
res
=>
{
const
authResult
=
res
.
target
.
authResult
invoke
(
callbackId
,
{
code
:
authResult
.
code
,
...
...
@@ -18,53 +34,27 @@ const loginByService = (provider, callbackId) => {
code
:
err
.
code
,
errMsg
:
'
login:fail:
'
+
err
.
message
})
},
provider
===
'
apple
'
?
{
scope
:
'
email
'
}
:
{})
},
provider
===
'
apple
'
?
{
scope
:
'
email
'
}
:
params
.
univerifyStyle
||
{})
}
// 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname
if
(
provider
===
'
apple
'
)
{
login
()
}
else
{
loginServices
[
provider
].
logout
(
login
,
login
)
service
.
logout
(
login
,
login
)
}
}
/**
* 微信登录
*/
export
function
login
(
params
,
callbackId
)
{
const
provider
=
params
.
provider
||
'
weixin
'
if
(
loginServices
[
provider
])
{
loginByService
(
provider
,
callbackId
)
}
else
{
plus
.
oauth
.
getServices
(
services
=>
{
loginServices
[
provider
]
=
services
.
find
(({
id
})
=>
id
===
provider
)
if
(
!
loginServices
[
provider
])
{
}).
catch
(
err
=>
{
invoke
(
callbackId
,
{
code
:
''
,
errMsg
:
'
login:fail:登录服务[
'
+
provider
+
'
]不存在
'
})
}
else
{
loginByService
(
provider
,
callbackId
)
}
},
err
=>
{
invoke
(
callbackId
,
{
code
:
err
.
code
,
code
:
err
.
code
||
''
,
errMsg
:
'
login:fail:
'
+
err
.
message
})
})
}
}
export
function
getUserInfo
(
params
,
callbackId
)
{
const
provider
=
params
.
provider
||
'
weixin
'
const
loginService
=
loginServices
[
provider
]
if
(
!
loginService
||
!
loginService
.
authResult
)
{
return
invoke
(
callbackId
,
{
errMsg
:
'
operateWXData:fail:请先调用 uni.login
'
})
}
const
errorCallback
=
warpPlusErrorCallback
(
callbackId
,
'
operateWXData
'
)
getService
(
provider
).
then
(
loginService
=>
{
loginService
.
getUserInfo
(
res
=>
{
let
userInfo
if
(
provider
===
'
weixin
'
)
{
...
...
@@ -90,12 +80,10 @@ export function getUserInfo (params, callbackId) {
realUserStatus
:
appleInfo
.
realUserStatus
}
}
else
{
loginService
.
userInfo
.
openId
=
loginService
.
userInfo
.
openId
||
loginService
.
userInfo
.
openid
||
loginService
.
authResult
.
openid
loginService
.
userInfo
.
nickName
=
loginService
.
userInfo
.
nickName
||
loginService
.
userInfo
.
nickname
loginService
.
userInfo
.
avatarUrl
=
loginService
.
userInfo
.
avatarUrl
||
loginService
.
userInfo
.
avatarUrl
||
loginService
.
userInfo
.
headimgurl
userInfo
=
loginService
.
userInfo
userInfo
.
openId
=
userInfo
.
openId
||
userInfo
.
openid
||
loginService
.
authResult
.
openid
userInfo
.
nickName
=
userInfo
.
nickName
||
userInfo
.
nickname
userInfo
.
avatarUrl
=
userInfo
.
avatarUrl
||
userInfo
.
headimgurl
}
const
result
=
{
errMsg
:
'
operateWXData:ok
'
...
...
@@ -112,9 +100,10 @@ export function getUserInfo (params, callbackId) {
result
.
userInfo
=
userInfo
}
invoke
(
callbackId
,
result
)
},
err
=>
{
},
errorCallback
)
}).
catch
(()
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
operateWXData:fail:
'
+
err
.
message
errMsg
:
'
operateWXData:fail:
请先调用 uni.login
'
})
})
}
...
...
@@ -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) {
}
}
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
)
{
return
function
errorCallback
(
error
)
{
error
=
error
||
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录