Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
python_shell
/
pythonworkspace
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 160b1ffd
authored
Dec 01, 2023
by
王欣伟
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加ROP服务调用工具类
1 parent
ab8d21f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
djcardrenewal/imageequity/roputil.py
djcardrenewal/imageequity/roputil.py
0 → 100644
View file @
160b1ff
import
hashlib
import
uuid
import
requests
class
RopUtils
:
@staticmethod
def
sign
(
param_values
,
ignore_param_names
=
None
,
secret
=
""
):
try
:
param_names
=
sorted
(
param_values
.
keys
())
if
ignore_param_names
:
param_names
=
[
name
for
name
in
param_names
if
name
not
in
ignore_param_names
]
data_to_sign
=
[
secret
]
data_to_sign
.
extend
(
f
"{name}{param_values[name]}"
for
name
in
param_names
)
data_to_sign
.
append
(
secret
)
data_to_sign_str
=
''
.
join
(
data_to_sign
)
sha1_digest
=
RopUtils
.
get_sha1_digest
(
data_to_sign_str
.
encode
(
"utf-8"
))
return
RopUtils
.
byte2hex
(
sha1_digest
)
except
Exception
as
e
:
raise
Exception
(
e
)
@staticmethod
def
utf8_encoding
(
value
,
source_charset_name
):
try
:
return
value
.
encode
(
source_charset_name
)
.
decode
(
"utf-8"
)
except
Exception
as
e
:
raise
ValueError
(
e
)
@staticmethod
def
get_sha1_digest
(
data
):
try
:
sha1_digest
=
hashlib
.
sha1
(
data
)
.
digest
()
return
sha1_digest
except
Exception
as
e
:
raise
ValueError
(
e
)
@staticmethod
def
get_md5_digest
(
data
):
try
:
md5_digest
=
hashlib
.
md5
(
data
)
.
digest
()
return
md5_digest
except
Exception
as
e
:
raise
ValueError
(
e
)
@staticmethod
def
byte2hex
(
data
):
return
''
.
join
(
f
"{byte:02X}"
for
byte
in
data
)
@staticmethod
def
get_uuid
():
return
str
(
uuid
.
uuid4
())
.
upper
()
@staticmethod
def
invokerEquityServer
(
orderNo
):
param_values
=
{
"appKey"
:
"48e5e13229b82c1b4e6e8c96151f0637"
,
"format"
:
"json"
,
"locale"
:
"zh_CN"
,
"method"
:
"scrm.api.equity.car.service.get.by.id"
,
"v"
:
"1.0.0"
}
param_values
[
'id'
]
=
'12'
secret_key
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
ignore_param_names
=
[]
sign
=
RopUtils
.
sign
(
param_values
,
ignore_param_names
,
secret_key
)
param_values
[
'sign'
]
=
sign
serverUrl
=
'https://scrm.test.glsx.com.cn/rop-scrm-equity/router'
try
:
#response = requests.get(serverUrl, params=param_values)
print
(
"Generated Signature:"
,
serverUrl
)
print
(
"Generated Signature:"
,
param_values
)
response
=
requests
.
post
(
serverUrl
,
data
=
param_values
)
print
(
response
)
# 检查响应状态码
if
response
.
status_code
==
200
:
return
response
.
text
else
:
return
f
"Error: {response.status_code}"
except
Exception
as
e
:
return
f
"Exception: {str(e)}"
# 示例用法
param_values
=
{
"param1"
:
"value1"
,
"param2"
:
"value2"
,
"param3"
:
"value3"
}
ignore_param_names
=
[
"param2"
]
secret_key
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
signature
=
RopUtils
.
sign
(
param_values
,
ignore_param_names
,
secret_key
)
print
(
"Generated Signature:"
,
signature
)
# 其他方法的使用方式也类似,根据需要调用相应的方法
orderNo
=
12
response
=
RopUtils
.
invokerEquityServer
(
orderNo
)
print
(
"response text:"
,
response
)
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment