sc-common-interface 2.9.1__tar.gz → 2.9.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/PKG-INFO +1 -1
- sc_common_interface-2.9.3/sc_common_interface/ScWebsocket.py +121 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/PKG-INFO +1 -1
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/SOURCES.txt +1 -0
- sc_common_interface-2.9.3/sc_common_interface.egg-info/requires.txt +4 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/setup.py +4 -2
- sc_common_interface-2.9.1/sc_common_interface.egg-info/requires.txt +0 -2
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/CommonOa.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/LiveCommonInterface.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/McCommonInterface.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/Platform.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/PostCommonInterface.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/__init__.py +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/dependency_links.txt +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/top_level.txt +0 -0
- {sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/setup.cfg +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import ssl
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from cryptography.hazmat.primitives import hashes
|
|
7
|
+
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
|
8
|
+
from cryptography.hazmat.primitives import serialization
|
|
9
|
+
from cryptography.hazmat.backends import default_backend
|
|
10
|
+
import base64
|
|
11
|
+
import websocket
|
|
12
|
+
|
|
13
|
+
# 定义回调函数
|
|
14
|
+
class WebSocketClient:
|
|
15
|
+
def __init__(self, url,admin_url, sales_id):
|
|
16
|
+
self.url = url
|
|
17
|
+
self.admin_url = admin_url
|
|
18
|
+
self.sales_id = sales_id
|
|
19
|
+
self.ws = websocket.WebSocketApp(self.url, on_open=self.on_open,on_message=self.on_message,
|
|
20
|
+
on_error=self.on_error,on_close=self.on_close)
|
|
21
|
+
|
|
22
|
+
def on_open(self, ws):
|
|
23
|
+
print("连接已打开")
|
|
24
|
+
subscribeToken, userToken = get_imtoken(self.admin_url,self.sales_id)
|
|
25
|
+
stamp = int(time.time()*1000)
|
|
26
|
+
reqid = "53%d"%stamp
|
|
27
|
+
device = {
|
|
28
|
+
"version": 1,
|
|
29
|
+
"reqid": reqid,
|
|
30
|
+
"payload": {
|
|
31
|
+
"appid": "SL101-web",
|
|
32
|
+
"devid": "7ecce8fc-44af-4c65-b75b-aa84b%d"%stamp,
|
|
33
|
+
"sdkver": "1.1.0"
|
|
34
|
+
},
|
|
35
|
+
"type": "REQUEST",
|
|
36
|
+
"url": "ap://auth/device",
|
|
37
|
+
"sign": "TDbwNFgmAPEPG5VGn5ozdSShpPPHK8PVsir9VXQ1ygx/RaeKjJ8lRnWf+gZ9wUH72EkgjSFGHaisv77wE8sgBBxxUud81V19t/mJY03MUwPQLSxJEY0hPPPr4mGhDK4IxYx154OJieyiDKNR5zO3jiGrEFWSn1Ft/0uMugkHQe8="
|
|
38
|
+
}
|
|
39
|
+
# 将消息转换为 JSON 格式并发送
|
|
40
|
+
ws.send(json.dumps(device))
|
|
41
|
+
subscribe = {
|
|
42
|
+
"version": 1,
|
|
43
|
+
"reqid": reqid,
|
|
44
|
+
"payload": {
|
|
45
|
+
"groups": [
|
|
46
|
+
"POST_%d"%self.sales_id,
|
|
47
|
+
"VIEW_ONLINE_%d"%self.sales_id
|
|
48
|
+
],
|
|
49
|
+
"token": subscribeToken
|
|
50
|
+
},
|
|
51
|
+
"type": "REQUEST",
|
|
52
|
+
"url": "http://broadcast/broadcast/subscribe",
|
|
53
|
+
"sign": "gaoLzQ6q1+Fn5uq0UqHAamaKJieEvMXRqo+rwR0u9WZnBhJ27StRlWohqCsO89/QyJvxupaGPuCwLpPji/xfMpeHacmodUrWO3J/EffRX0lGeIo+Zz35XjqleFruaXmu1GGkCQ82SZmNdaAo6YrGN//twyiIPNH3KZ7xNRO/+dI="
|
|
54
|
+
}
|
|
55
|
+
ws.send(json.dumps(subscribe))
|
|
56
|
+
|
|
57
|
+
def on_message(self, ws,message):
|
|
58
|
+
print("收到消息:", message)
|
|
59
|
+
|
|
60
|
+
def on_error(self,ws,error):
|
|
61
|
+
print("发生错误:", error)
|
|
62
|
+
|
|
63
|
+
def on_close(self,ws, res1, res2):
|
|
64
|
+
print("连接已关闭", res1, res2)
|
|
65
|
+
|
|
66
|
+
def run(self):
|
|
67
|
+
self.ws.run_forever()
|
|
68
|
+
#20秒后关闭
|
|
69
|
+
time.sleep(10)
|
|
70
|
+
print("10秒后主动关闭")
|
|
71
|
+
self.ws.close()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_imtoken(admin_url,sales_id):
|
|
77
|
+
url = "%s/api/posts/live/viewer/unauthorized/post/sales/%d/user/info?appId=SL101-web"%(admin_url,sales_id)
|
|
78
|
+
headers = {"content-type":"application/json"}
|
|
79
|
+
response = requests.get(url,headers=headers).json()
|
|
80
|
+
subscribeToken = response["data"]["subscribeToken"]
|
|
81
|
+
userToken = response["data"]["userToken"]
|
|
82
|
+
# print(subscribeToken)
|
|
83
|
+
return subscribeToken,userToken
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sign(msg, private_key):
|
|
88
|
+
# 将消息编码为字节
|
|
89
|
+
# 从 字符串加载私钥
|
|
90
|
+
loaded_private_key = load_private_key(private_key)
|
|
91
|
+
message_bytes = msg.encode('utf-8')
|
|
92
|
+
# 使用私钥进行签名
|
|
93
|
+
signature = loaded_private_key.sign(
|
|
94
|
+
message_bytes,
|
|
95
|
+
padding.PKCS1v15(),
|
|
96
|
+
hashes.SHA1()
|
|
97
|
+
)
|
|
98
|
+
# 将签名转换为 Base64 编码
|
|
99
|
+
return base64.b64encode(signature).decode('utf-8')
|
|
100
|
+
|
|
101
|
+
def load_private_key(pri_key_str):
|
|
102
|
+
# 从 PEM 格式字符串加载私钥
|
|
103
|
+
return serialization.load_pem_private_key(
|
|
104
|
+
pri_key_str.encode(),
|
|
105
|
+
password=None,
|
|
106
|
+
backend=default_backend()
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
if __name__=="__main__":
|
|
112
|
+
# admin_url = "https://front-service.shoplinestg.com"
|
|
113
|
+
# url = "ws://service-websocket.myshoplinestg.com/"
|
|
114
|
+
# url = "ws://api-webservice-preview.myshopline.com"
|
|
115
|
+
url = "ws://api-webservice.myshopline.com"
|
|
116
|
+
admin_url = "https://front-admin.shoplineapp.com"
|
|
117
|
+
|
|
118
|
+
webSocketClient = WebSocketClient(url,admin_url,561242)
|
|
119
|
+
webSocketClient.run()
|
|
120
|
+
|
|
121
|
+
|
{sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/SOURCES.txt
RENAMED
|
@@ -4,6 +4,7 @@ sc_common_interface/LiveCommonInterface.py
|
|
|
4
4
|
sc_common_interface/McCommonInterface.py
|
|
5
5
|
sc_common_interface/Platform.py
|
|
6
6
|
sc_common_interface/PostCommonInterface.py
|
|
7
|
+
sc_common_interface/ScWebsocket.py
|
|
7
8
|
sc_common_interface/__init__.py
|
|
8
9
|
sc_common_interface.egg-info/PKG-INFO
|
|
9
10
|
sc_common_interface.egg-info/SOURCES.txt
|
|
@@ -2,13 +2,15 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='sc_common_interface',
|
|
5
|
-
version='2.9.
|
|
5
|
+
version='2.9.3',
|
|
6
6
|
description='SC贴文销售公用的接口',
|
|
7
7
|
author='river',
|
|
8
8
|
packages=find_packages(),
|
|
9
9
|
install_requires=[
|
|
10
10
|
"requests>=2.0.0",
|
|
11
|
-
"jsonpath>=0.82"
|
|
11
|
+
"jsonpath>=0.82",
|
|
12
|
+
"websocket-client>=1.8.0",
|
|
13
|
+
"cryptography>=44.0.2"
|
|
12
14
|
],
|
|
13
15
|
)
|
|
14
16
|
|
|
File without changes
|
{sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/LiveCommonInterface.py
RENAMED
|
File without changes
|
{sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/McCommonInterface.py
RENAMED
|
File without changes
|
|
File without changes
|
{sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface/PostCommonInterface.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sc_common_interface-2.9.1 → sc_common_interface-2.9.3}/sc_common_interface.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|