sc-common-interface 2.9.0__tar.gz → 2.9.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc_common_interface
3
- Version: 2.9.0
3
+ Version: 2.9.2
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -239,7 +239,8 @@ def get_str_time(time_type="add",unit="days",num=1,format='%Y-%m-%dT%H:%M:%S.%f'
239
239
 
240
240
 
241
241
  if __name__=="__main__":
242
- pass
242
+ format_time = get_str_time(num=179,time_type="add")
243
+ print(format_time)
243
244
 
244
245
 
245
246
 
@@ -1796,6 +1796,7 @@ def get_produnct_set_detail(data):
1796
1796
 
1797
1797
  def add_product_set_to_live(data):
1798
1798
  "添加组合商品到直播间"
1799
+ global title
1799
1800
  env = data["env"]
1800
1801
  headers = data["headers"]
1801
1802
  sales_id = data["sales_id"]
@@ -1816,7 +1817,6 @@ def add_product_set_to_live(data):
1816
1817
  spu_ids = list(childrenInfo.keys())
1817
1818
  # necessaryQuantitys = jsonpath(data_list, "$..necessaryQuantity")
1818
1819
  data["product_id"] = product_id
1819
-
1820
1820
  # 查询组合商品详情信息
1821
1821
  response = get_produnct_set_detail(data)
1822
1822
  # print(response)
@@ -1883,7 +1883,7 @@ def add_product_set_to_live(data):
1883
1883
  time.sleep(2)
1884
1884
  data_res = requests.post(url, headers=headers, json=add_body).json()
1885
1885
  # print(data_res)
1886
- return product_id,products,keyword,data_res
1886
+ return product_id,products,keyword,title,data_res
1887
1887
  except Exception:
1888
1888
  print("出现异常")
1889
1889
 
@@ -2455,11 +2455,8 @@ def get_merchant_currency(data):
2455
2455
 
2456
2456
 
2457
2457
  if __name__=="__main__":
2458
- stamp1 = get_stamp_time({"num":5040})
2459
- print(stamp1)
2460
- stamp2 = get_stamp_time({"num": 6000})
2461
- print(stamp2)
2462
-
2458
+ data = {'env': 'https://front-service.shoplinestg.com', 'headers': {'Content-Type': 'application/json', 'authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIwMzkzZTdlODQ2MDMzZmUyOTViMjllY2I1OWVjOTgwOSIsImRhdGEiOnsibWVyY2hhbnRfaWQiOiI2MjI5YTdiYWVhNzA2NDJhOGI2NWViZGEiLCJhcHBsaWNhdGlvbl9pZCI6IjYwZWVjNWViZjhkYzkyMDAwNjUyZTAwNiJ9LCJpc3MiOiJodHRwczovL2RldmVsb3BlcnMteXkuc2hvcGxpbmVzdGcuY29tIiwiYXVkIjpbXSwic3ViIjoiNjIyOWE3YmFlYTcwNjQyYThiNjVlYmRhIn0.pKkJD01uFDUfiVR2gBJQFd_EtIvQkHR2ScJzRTTOxxg', 'lang': 'en'}, 'sales_id': '90566', 'arr': 0}
2459
+ add_product_set_to_live(data)
2463
2460
 
2464
2461
 
2465
2462
 
@@ -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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.9.0
3
+ Version: 2.9.2
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -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,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc_common_interface',
5
- version='2.9.0',
5
+ version='2.9.2',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),