Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tour_business
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
魏强
tour_business
Commits
ba1d7071
Commit
ba1d7071
authored
Apr 17, 2020
by
魏强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update;
parent
74837024
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletions
+52
-1
Config/common_config.py
+2
-0
Libs/Onenet/OneNetApi.py
+50
-1
No files found.
Config/common_config.py
View file @
ba1d7071
...
...
@@ -12,6 +12,8 @@ if is_prod:
else
:
ONENET_CONFIG
[
'api_key'
]
=
"H9x=yfGVGPPPBZxzyaaGhbaJ6kM="
LIUYUAN_CONFIG
=
"DS1=GyIEzsNvpET8HOTcYPuZlak=="
MINA_APP
=
{
"app_id"
:
"wx3185fb4a3633beb0"
,
"app_key"
:
"d0fee84366bfb19c95505f4ddfa47b63"
,
...
...
Libs/Onenet/OneNetApi.py
View file @
ba1d7071
...
...
@@ -5,7 +5,7 @@ import urllib.parse
import
requests
from
Config.common_config
import
ONENET_CONFIG
as
config
from
Config.common_config
import
ONENET_CONFIG
as
config
,
LIUYUAN_CONFIG
class
OneNetApi
(
object
):
...
...
@@ -37,6 +37,9 @@ class OneNetApi(object):
def
get_cur_api_key
(
self
):
return
config
[
"api_key"
]
def
get_liuyuan_api_key
(
self
):
return
LIUYUAN_CONFIG
def
device
(
self
,
id
):
if
not
id
:
return
False
...
...
@@ -285,6 +288,10 @@ class OneNetApi(object):
api
=
"/cmds?device_id={device_id}&qos={qos}&timeout={timeout}"
.
format
(
device_id
=
device_id
,
qos
=
qos
,
timeout
=
timeout
)
if
device_id
in
[
'83803512'
,
'83803513'
,
'83803514'
,
'83803515'
]:
return
self
.
_call_liuyuan
(
api
,
"POST"
,
sms
)
return
self
.
_call
(
api
,
"POST"
,
sms
)
def
send_data_to_mqtt
(
self
,
topic
,
sms
):
...
...
@@ -345,6 +352,48 @@ class OneNetApi(object):
else
:
return
{}
def
_call_liuyuan
(
self
,
url
,
method
=
"GET"
,
data
=
None
,
heasers
=
None
):
result
=
self
.
_rawcall_liuyuan
(
url
,
method
,
data
,
heasers
)
if
not
result
:
return
False
return
result
def
_rawcall_liuyuan
(
self
,
url
,
method
,
data
=
None
,
heasers
=
None
):
url
=
self
.
_paddingUrl
(
url
)
self
.
_error_no
=
0
self
.
_error
=
None
if
not
url
:
self
.
_http_code
=
500
return
False
if
method
not
in
self
.
_ALLOW_METHODS
:
self
.
_http_code
=
500
return
False
if
heasers
:
heasers
=
heasers
kwargs
=
{
"headers"
:
{
"api-key"
:
self
.
get_liuyuan_api_key
()}}
if
data
:
if
isinstance
(
data
,
list
)
or
isinstance
(
data
,
dict
):
data
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
kwargs
[
"data"
]
=
data
if
heasers
:
kwargs
[
"headers"
]
.
update
(
heasers
)
result
=
requests
.
request
(
method
,
url
,
**
kwargs
)
print
(
result
.
text
)
if
result
:
self
.
_http_code
=
result
.
status_code
result
=
json
.
loads
(
result
.
text
)
return
result
else
:
return
{}
def
_paddingUrl
(
self
,
url
):
if
not
url
:
return
url
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment