Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
ypt_mgw_local
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
苏星豪
ypt_mgw_local
Commits
15438a56
提交
15438a56
authored
12月 15, 2023
作者:
蒋代伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
智慧门店 摄像机视频流
上级
8582191b
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
133 行增加
和
77 行删除
+133
-77
urls.py
datacenter/urls.py
+2
-8
hikTools.py
smartdevice/hikTools.py
+93
-0
models.py
smartdevice/models.py
+2
-1
views.py
smartdevice/views.py
+36
-68
没有找到文件。
datacenter/urls.py
浏览文件 @
15438a56
...
...
@@ -1358,16 +1358,10 @@ urlpatterns = [
url
(
r'^sales/batch/batch_terminal/$'
,
sal_views
.
batch_terminal
),
url
(
r'^sales/activity/PromotionSeeds_lottery/$'
,
sal_views
.
PromotionSeeds_lottery
),
# 智慧门店 开通/关闭标准流预览
url
(
r'^smartdevice/hikvision/customization/liveVideo/(?P<channelIds>\d+)/(?P<what>\w+)/$'
,
sd_views
.
act_liveVideo
),
# 智慧门店 通过设备序列号查询通道列表
url
(
r'^smartdevice/hikvision/customization/getChannels/$'
,
sd_views
.
getChannels
),
# 智慧门店 开通标准流预览
#2023-12-13 智慧门店 海康威视获取视频流
url
(
r'^smartdevice/hikvision/
liveVideoOpen/$'
,
sd_views
.
liveVideoOpen
),
url
(
r'^smartdevice/hikvision/
liveVideoOpen/(?P<company_id>\d+)/$'
,
sd_views
.
liveVideoOpen
),
url
(
r'^smartdevice/hikvision/
getLiveAddress/(?P<company_id>\d+)/$'
,
sd_views
.
getLiveAddress
),
url
(
r'^smartdevice/hikvision/
getLiveAddress/(?P<company_id>\d+)/(?P<deviceSerial>\w+)/$'
,
sd_views
.
getLiveAddress
),
]
...
...
smartdevice/hikTools.py
0 → 100644
浏览文件 @
15438a56
import
json
import
redis
import
requests
from
datacenter
import
settings
from
smartdevice.models
import
Device
CILENT_ID
=
"7aab6665696b4027879a55332f001b8f"
CILENT_SECRET
=
"3a86ce7109734c7480f1d293e5dc01fe"
class
HikTools
():
def
__init__
(
self
):
super
()
.
__init__
()
# 智慧门店 获取hik校验token
def
get_hik_stoken
(
self
):
access_token
=
""
rd
=
redis
.
StrictRedis
(
connection_pool
=
settings
.
LABEL_CHECK_POOL
)
rd
.
select
(
15
)
access_token
=
rd
.
get
(
"hik_token"
)
if
access_token
:
access_token
=
json
.
loads
(
access_token
)
return
access_token
else
:
hik_url
=
"https://api2.hik-cloud.com/oauth/token"
headers
=
{
'Content-Type'
:
'application/x-www-form-urlencoded'
}
data
=
{
"client_id"
:
CILENT_ID
,
"client_secret"
:
CILENT_SECRET
,
"grant_type"
:
"client_credentials"
,
"scope"
:
"all"
}
res
=
requests
.
post
(
hik_url
,
headers
=
headers
,
data
=
data
)
if
res
.
status_code
==
200
:
res
=
res
.
json
()
rd
=
redis
.
StrictRedis
(
connection_pool
=
settings
.
LABEL_CHECK_POOL
)
rd
.
select
(
15
)
rd
.
setex
(
"hik_token"
,
res
[
'expires_in'
]
-
100
,
json
.
dumps
(
res
))
else
:
res
=
""
return
res
;
# 根据设备序列号查看设备通道
def
getChannels
(
self
,
deviceSerial
):
access_token
=
self
.
get_hik_stoken
()
if
access_token
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/devices/channels/actions/listByDevSerial?deviceSerial="
+
deviceSerial
headers
=
{
"Authorization"
:
"bearer "
+
access_token
[
'access_token'
]}
res
=
requests
.
get
(
video_url
,
headers
=
headers
)
if
res
.
status_code
==
200
:
res
=
res
.
json
()
else
:
res
=
""
return
res
;
else
:
return
{
"e"
:
"获取token校验错误"
}
# 根据通道 开启或者关闭标准视频流
def
act_liveVideo
(
self
,
deviceSerial
,
what
=
None
):
access_token
=
self
.
get_hik_stoken
()
if
access_token
:
video_url
=
""
headers
=
{
'Content-Type'
:
'application/x-www-form-urlencoded'
,
"Authorization"
:
"Bearer "
+
access_token
[
'access_token'
]}
if
what
==
'open'
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/liveVideoOpen"
elif
what
==
'close'
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/liveVideoClose"
else
:
pass
channels
=
self
.
getChannels
(
deviceSerial
)
if
channels
and
'data'
in
channels
:
channelId
=
channels
[
'data'
][
0
][
'channelId'
]
data
=
{
"channelIds"
:
channelId
,
}
res
=
requests
.
post
(
video_url
,
headers
=
headers
,
data
=
data
)
if
res
.
status_code
==
200
:
return
res
.
json
()
else
:
return
{
'code'
:
5200
,
"message"
:
"操作失败"
}
else
:
return
{
'code'
:
5200
,
"message"
:
"暂未获取通道"
}
else
:
return
{
'code'
:
5200
,
"message"
:
"获取token校验错误"
}
smartdevice/models.py
浏览文件 @
15438a56
...
...
@@ -30,13 +30,14 @@ class PlatForm(models.Model):
#设备
class
Device
(
models
.
Model
):
category
=
models
.
ForeignKey
(
Category
,
verbose_name
=
_
(
'设备类别'
),
on_delete
=
models
.
CASCADE
)
category
=
models
.
ForeignKey
(
'Category'
,
verbose_name
=
_
(
'设备类别'
),
on_delete
=
models
.
CASCADE
)
platform
=
models
.
ForeignKey
(
PlatForm
,
verbose_name
=
_
(
'设备类别'
),
on_delete
=
models
.
CASCADE
)
company
=
models
.
ForeignKey
(
'company.Company'
,
verbose_name
=
_
(
'公司名称'
),
on_delete
=
models
.
CASCADE
)
ancestor
=
models
.
ForeignKey
(
'company.Company'
,
verbose_name
=
_
(
'公司族系'
),
on_delete
=
models
.
CASCADE
,
related_name
=
'device_ancestor_id'
)
user
=
models
.
ForeignKey
(
'company.User'
,
verbose_name
=
_
(
'操作人'
),
on_delete
=
models
.
CASCADE
)
name
=
models
.
CharField
(
_
(
'设备名称'
),
max_length
=
50
,
db_index
=
True
)
status
=
models
.
SmallIntegerField
(
_
(
'设备状态'
),
default
=
1
,
choices
=
((
1
,
'正常'
),(
2
,
'休眠'
),(
3
,
'关闭'
)),
blank
=
True
,
null
=
True
)
is_open_live_video
=
models
.
BooleanField
(
_
(
'是否开通标准流预览'
),
default
=
False
)
is_active
=
models
.
BooleanField
(
_
(
'是否已激活'
),
default
=
True
)
is_delete
=
models
.
BooleanField
(
_
(
'是否已删除'
),
default
=
False
)
remark
=
models
.
CharField
(
_
(
'备注说明'
),
max_length
=
100
,
null
=
True
,
blank
=
True
)
...
...
smartdevice/views.py
浏览文件 @
15438a56
import
http
import
json
import
redis
import
requests
from
django.http
import
JsonResponse
from
django.shortcuts
import
render
from
smartdevice.utils
import
get_hik_stoken
from
datacenter
import
settings
from
smartdevice.hikTools
import
HikTools
from
.models
import
Device
# def get_token(request):
# hik_url = "https://api2.hik-cloud.com/oauth/token"
# headers = {'ContentType': 'application/x-www-form-urlencoded'}
# data= {
# "client_id":"a0b0f6d1f1e5467d8ca1d5aaf978f878",
# "client_secret":"b5fb5a3201e046f386eb387bc2f799eb",
# "grant_type":"client_credentials",
# "scope":"all"
# }
#
#
# res = requests.post(hik_url, headers=headers,data=data)
# print(res.json())
# return JsonResponse(res.json(), safe=False)
def
getLiveAddress
(
request
,
company_id
,
deviceSerial
=
None
):
def
getChannels
(
request
):
deviceSerial
=
request
.
GET
.
get
(
"deviceSerial"
)
access_token
=
get_hik_stoken
()
hikTools
=
HikTools
()
access_token
=
hikTools
.
get_hik_stoken
()
if
access_token
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/devices/channels/actions/listByDevSerial?deviceSerial="
+
deviceSerial
print
(
video_url
)
headers
=
{
"Authorization"
:
"bearer "
+
access_token
[
'access_token'
]}
# 查询当前公司设备是否存在设备并开启视频流
device
=
Device
.
objects
.
filter
(
company_id
=
company_id
)
if
device
is
not
None
:
deviceSerial
=
device
[
0
]
.
sn
if
device
[
0
]
.
is_open_live_video
==
False
:
is_open
=
hikTools
.
act_liveVideo
(
deviceSerial
,
'open'
)
if
is_open
[
'code'
]
==
200
:
device
[
0
]
.
is_open_live_video
=
True
device
[
0
]
.
save
()
res
=
requests
.
get
(
video_url
,
headers
=
headers
)
print
(
res
.
json
())
return
JsonResponse
(
res
.
json
(),
safe
=
False
)
else
:
return
JsonResponse
({
"e"
:
"获取token校验错误"
},
safe
=
False
)
def
act_liveVideo
(
request
,
channelIds
,
what
=
None
):
print
(
what
)
access_token
=
get_hik_stoken
()
if
access_token
:
video_url
=
""
headers
=
{
'ContentType'
:
'application/x-www-form-urlencoded'
,
"Authorization"
:
"Bearer "
+
access_token
[
'access_token'
]}
if
what
==
'open'
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/liveVideoOpen"
elif
what
==
'close'
:
video_url
=
"https://api2.hik-cloud.com/v1/customization/liveVideoClose"
hik_url
=
"https://api2.hik-cloud.com/v1/customization/liveStudio/actions/getLiveAddress"
headers
=
{
"Content-Type"
:
"application/json"
,
"Authorization"
:
"Bearer "
+
access_token
[
'access_token'
]}
data
=
json
.
dumps
({
"deviceSerial"
:
deviceSerial
,
"channelNo"
:
1
,
"protocol"
:
2
,
"expireTime"
:
3600
,
"type"
:
1
,
"quality"
:
2
})
res
=
requests
.
post
(
hik_url
,
headers
=
headers
,
data
=
data
);
if
res
.
status_code
==
200
:
res
=
res
.
json
()
return
JsonResponse
(
res
,
safe
=
False
)
else
:
pass
data
=
{
"channelIds"
:
"1"
}
res
=
requests
.
post
(
video_url
,
headers
=
headers
,
data
=
data
)
print
(
res
.
json
())
return
JsonResponse
(
res
.
json
(),
safe
=
False
)
return
JsonResponse
({
'code'
:
200
,
"message"
:
"获取预览播放地址失败"
},
safe
=
False
)
else
:
return
JsonResponse
({
"e"
:
"获取token校验错误"
},
safe
=
False
)
def
liveVideoOpen
(
request
,
company_id
=
None
):
print
(
company_id
)
hik_url
=
"https://api2.hik-cloud.com/v1/customization/liveStudio/actions/getLiveAddress"
headers
=
{
'ContentType'
:
'application/json'
}
data
=
{
"deviceSerial"
:
"DS-2CD2T26WDV3-I320231126AACHAE1254532"
,
"channelNo"
:
1
,
"protocol"
:
2
,
"expireTime"
:
3600
,
"type"
:
1
,
"quality"
:
2
}
res
=
requests
.
post
(
hik_url
,
headers
=
headers
,
data
=
data
)
print
(
res
)
return
JsonResponse
(
res
.
json
())
\ No newline at end of file
return
JsonResponse
({
'code'
:
200
,
"message"
:
"获取token校验错误"
},
safe
=
False
)
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论