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 = {}) {
}
function
checkClientInfo
(
clientInfo
)
{
const
stringNotRequired
=
{
required
:
false
,
type
:
'
string
'
}
const
numberNotRequired
=
{
required
:
false
,
type
:
'
string
'
}
const
schema
=
{
uniPlatform
:
'
string
'
,
appId
:
'
string
'
,
deviceId
:
{
required
:
false
,
type
:
'
string
'
},
osName
:
{
required
:
false
,
type
:
'
string
'
},
locale
:
{
required
:
false
,
type
:
'
string
'
},
clientIP
:
{
required
:
false
,
type
:
'
string
'
},
appName
:
{
required
:
false
,
type
:
'
string
'
},
appVersion
:
{
required
:
false
,
type
:
'
string
'
},
appVersionCode
:
{
required
:
false
,
type
:
'
string
'
},
channel
:
{
required
:
false
,
type
:
'
string
'
},
userAgent
:
{
required
:
false
,
type
:
'
string
'
},
uniIdToken
:
{
required
:
false
,
type
:
'
string
'
}
deviceId
:
stringNotRequired
,
osName
:
stringNotRequired
,
locale
:
stringNotRequired
,
clientIP
:
stringNotRequired
,
appName
:
stringNotRequired
,
appVersion
:
stringNotRequired
,
appVersionCode
:
stringNotRequired
,
channel
:
stringNotRequired
,
userAgent
:
stringNotRequired
,
uniIdToken
:
stringNotRequired
,
deviceBrand
:
stringNotRequired
,
deviceModel
:
stringNotRequired
,
osVersion
:
stringNotRequired
,
osLanguage
:
stringNotRequired
,
osTheme
:
stringNotRequired
,
romName
:
stringNotRequired
,
romVersion
:
stringNotRequired
,
devicePixelRatio
:
numberNotRequired
,
windowWidth
:
numberNotRequired
,
windowHeight
:
numberNotRequired
,
screenWidth
:
numberNotRequired
,
screenHeight
:
numberNotRequired
}
const
validateRes
=
validate
(
clientInfo
,
schema
)
if
(
validateRes
)
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
fbfc8066
...
...
@@ -87,7 +87,7 @@ module.exports = {
break
case
'
web
'
:
case
'
h5
'
:
clientPlatform
=
'
h5
'
clientPlatform
=
'
web
'
break
default
:
break
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/set-push-cid.js
浏览文件 @
fbfc8066
...
...
@@ -5,6 +5,67 @@ const {
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
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-push-cid
...
...
@@ -19,15 +80,14 @@ module.exports = async function (params = {}) {
this
.
middleware
.
validate
(
params
,
schema
)
const
{
deviceId
,
"
appId
"
:
dcloud_appid
,
uniPlatform
,
osName
appId
,
osName
}
=
this
.
getClientInfo
()
let
platform
=
uni
Platform
if
(
platform
==
"
app
"
)
{
platform
+=
osName
let
platform
=
this
.
client
Platform
if
(
platform
===
'
app
'
)
{
platform
+=
osName
}
const
{
uid
,
exp
...
...
@@ -44,14 +104,16 @@ module.exports = async function (params = {}) {
}
}
const
deviceRecord
=
getDeviceRes
.
data
[
0
]
await
setOpendbDevice
({
pushClientId
})
if
(
!
deviceRecord
)
{
await
deviceCollection
.
add
({
user_id
:
uid
,
device_id
:
deviceId
,
token_expired
:
tokenExpired
,
push_clientid
:
pushClientId
,
dcloud_appid
,
platform
dcloud_appid
:
appId
})
return
{
errCode
:
0
...
...
@@ -68,8 +130,7 @@ module.exports = async function (params = {}) {
user_id
:
uid
,
token_expired
:
tokenExpired
,
push_clientid
:
pushClientId
,
dcloud_appid
,
platform
dcloud_appid
:
appId
})
return
{
errCode
:
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录