Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
fbfc8066
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fbfc8066
编写于
7月 06, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: save device info into opendb-device
上级
8b15df03
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
103 addition
and
52 deletion
+103
-52
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/validator.js
+30
-40
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+1
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/set-push-cid.js
...oud/cloudfunctions/uni-id-co/module/utils/set-push-cid.js
+72
-11
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
浏览文件 @
fbfc8066
...
@@ -160,49 +160,39 @@ function validate (value = {}, schema = {}) {
...
@@ -160,49 +160,39 @@ function validate (value = {}, schema = {}) {
}
}
function
checkClientInfo
(
clientInfo
)
{
function
checkClientInfo
(
clientInfo
)
{
const
stringNotRequired
=
{
required
:
false
,
type
:
'
string
'
}
const
numberNotRequired
=
{
required
:
false
,
type
:
'
string
'
}
const
schema
=
{
const
schema
=
{
uniPlatform
:
'
string
'
,
uniPlatform
:
'
string
'
,
appId
:
'
string
'
,
appId
:
'
string
'
,
deviceId
:
{
deviceId
:
stringNotRequired
,
required
:
false
,
osName
:
stringNotRequired
,
type
:
'
string
'
locale
:
stringNotRequired
,
},
clientIP
:
stringNotRequired
,
osName
:
{
appName
:
stringNotRequired
,
required
:
false
,
appVersion
:
stringNotRequired
,
type
:
'
string
'
appVersionCode
:
stringNotRequired
,
},
channel
:
stringNotRequired
,
locale
:
{
userAgent
:
stringNotRequired
,
required
:
false
,
uniIdToken
:
stringNotRequired
,
type
:
'
string
'
deviceBrand
:
stringNotRequired
,
},
deviceModel
:
stringNotRequired
,
clientIP
:
{
osVersion
:
stringNotRequired
,
required
:
false
,
osLanguage
:
stringNotRequired
,
type
:
'
string
'
osTheme
:
stringNotRequired
,
},
romName
:
stringNotRequired
,
appName
:
{
romVersion
:
stringNotRequired
,
required
:
false
,
devicePixelRatio
:
numberNotRequired
,
type
:
'
string
'
windowWidth
:
numberNotRequired
,
},
windowHeight
:
numberNotRequired
,
appVersion
:
{
screenWidth
:
numberNotRequired
,
required
:
false
,
screenHeight
:
numberNotRequired
type
:
'
string
'
},
appVersionCode
:
{
required
:
false
,
type
:
'
string
'
},
channel
:
{
required
:
false
,
type
:
'
string
'
},
userAgent
:
{
required
:
false
,
type
:
'
string
'
},
uniIdToken
:
{
required
:
false
,
type
:
'
string
'
}
}
}
const
validateRes
=
validate
(
clientInfo
,
schema
)
const
validateRes
=
validate
(
clientInfo
,
schema
)
if
(
validateRes
)
{
if
(
validateRes
)
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
fbfc8066
...
@@ -87,7 +87,7 @@ module.exports = {
...
@@ -87,7 +87,7 @@ module.exports = {
break
break
case
'
web
'
:
case
'
web
'
:
case
'
h5
'
:
case
'
h5
'
:
clientPlatform
=
'
h5
'
clientPlatform
=
'
web
'
break
break
default
:
default
:
break
break
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/set-push-cid.js
浏览文件 @
fbfc8066
...
@@ -5,6 +5,67 @@ const {
...
@@ -5,6 +5,67 @@ const {
ERROR
ERROR
}
=
require
(
'
../../common/error
'
)
}
=
require
(
'
../../common/error
'
)
async
function
setOpendbDevice
({
pushClientId
}
=
{})
{
// 仅新增,如果存在进行更新操作
const
{
appId
,
deviceId
,
deviceBrand
,
deviceModel
,
osName
,
osVersion
,
osLanguage
,
osTheme
,
devicePixelRatio
,
windowWidth
,
windowHeight
,
screenWidth
,
screenHeight
,
romName
,
romVersion
}
=
this
.
getClientInfo
()
const
platform
=
this
.
clientPlatform
const
now
=
Date
.
now
()
const
db
=
uniCloud
.
database
()
const
opendbDeviceCollection
=
db
.
collection
(
'
opendb-device
'
)
const
getDeviceRes
=
await
opendbDeviceCollection
.
where
({
device_id
:
deviceId
}).
get
()
const
data
=
{
appid
:
appId
,
device_id
:
deviceId
,
vendor
:
deviceBrand
,
model
:
deviceModel
,
uni_platform
:
platform
,
os_name
:
osName
,
os_version
:
osVersion
,
os_language
:
osLanguage
,
os_theme
:
osTheme
,
pixel_ratio
:
devicePixelRatio
,
window_width
:
windowWidth
,
window_height
:
windowHeight
,
screen_width
:
screenWidth
,
screen_height
:
screenHeight
,
rom_name
:
romName
,
rom_version
:
romVersion
,
last_update_date
:
now
,
push_clientid
:
pushClientId
}
if
(
getDeviceRes
.
data
.
length
>
0
)
{
await
opendbDeviceCollection
.
where
({
device_id
:
deviceId
}).
update
(
data
)
return
}
data
.
create_date
=
now
await
opendbDeviceCollection
.
where
({
device_id
:
deviceId
}).
add
(
data
)
}
/**
/**
* 更新device表的push_clien_id
* 更新device表的push_clien_id
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid
...
@@ -19,15 +80,14 @@ module.exports = async function (params = {}) {
...
@@ -19,15 +80,14 @@ module.exports = async function (params = {}) {
this
.
middleware
.
validate
(
params
,
schema
)
this
.
middleware
.
validate
(
params
,
schema
)
const
{
const
{
deviceId
,
deviceId
,
"
appId
"
:
dcloud_appid
,
appId
,
uniPlatform
,
osName
osName
}
=
this
.
getClientInfo
()
}
=
this
.
getClientInfo
()
let
platform
=
uni
Platform
let
platform
=
this
.
client
Platform
if
(
platform
==
"
app
"
)
{
if
(
platform
===
'
app
'
)
{
platform
+=
osName
platform
+=
osName
}
}
const
{
const
{
uid
,
uid
,
exp
exp
...
@@ -44,14 +104,16 @@ module.exports = async function (params = {}) {
...
@@ -44,14 +104,16 @@ module.exports = async function (params = {}) {
}
}
}
}
const
deviceRecord
=
getDeviceRes
.
data
[
0
]
const
deviceRecord
=
getDeviceRes
.
data
[
0
]
await
setOpendbDevice
({
pushClientId
})
if
(
!
deviceRecord
)
{
if
(
!
deviceRecord
)
{
await
deviceCollection
.
add
({
await
deviceCollection
.
add
({
user_id
:
uid
,
user_id
:
uid
,
device_id
:
deviceId
,
device_id
:
deviceId
,
token_expired
:
tokenExpired
,
token_expired
:
tokenExpired
,
push_clientid
:
pushClientId
,
push_clientid
:
pushClientId
,
dcloud_appid
,
dcloud_appid
:
appId
platform
})
})
return
{
return
{
errCode
:
0
errCode
:
0
...
@@ -68,8 +130,7 @@ module.exports = async function (params = {}) {
...
@@ -68,8 +130,7 @@ module.exports = async function (params = {}) {
user_id
:
uid
,
user_id
:
uid
,
token_expired
:
tokenExpired
,
token_expired
:
tokenExpired
,
push_clientid
:
pushClientId
,
push_clientid
:
pushClientId
,
dcloud_appid
,
dcloud_appid
:
appId
platform
})
})
return
{
return
{
errCode
:
0
errCode
:
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录