sc-common-interface 2.9.6__tar.gz → 2.9.8__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.
Files changed (16) hide show
  1. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/PKG-INFO +1 -1
  2. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/LiveCommonInterface.py +0 -1
  3. sc_common_interface-2.9.8/sc_common_interface/OperaMysql.py +193 -0
  4. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/ScWebsocket.py +56 -32
  5. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface.egg-info/PKG-INFO +1 -1
  6. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface.egg-info/SOURCES.txt +1 -0
  7. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface.egg-info/requires.txt +1 -0
  8. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/setup.py +3 -2
  9. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/CommonOa.py +0 -0
  10. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/McCommonInterface.py +0 -0
  11. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/Platform.py +0 -0
  12. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/PostCommonInterface.py +0 -0
  13. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface/__init__.py +0 -0
  14. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface.egg-info/dependency_links.txt +0 -0
  15. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/sc_common_interface.egg-info/top_level.txt +0 -0
  16. {sc_common_interface-2.9.6 → sc_common_interface-2.9.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc_common_interface
3
- Version: 2.9.6
3
+ Version: 2.9.8
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -234,7 +234,6 @@ def send__live_comment(data):
234
234
  num = random.randint(100000, 999999)
235
235
  user_id = "488864%d" % int(time.time())
236
236
  name = "test live%d" % int(time.time())
237
-
238
237
  keyword = "接口测试普通留言"
239
238
  user_id = data.get("user_id", user_id)
240
239
  name = data.get("name", name)
@@ -0,0 +1,193 @@
1
+ import random
2
+ import time
3
+ import random
4
+ import secrets
5
+ import string
6
+ from datetime import datetime
7
+
8
+ import pymysql
9
+
10
+
11
+
12
+ class OperaMysql():
13
+ def __init__(self,host,username,password,db,port):
14
+ self.host= host
15
+ self.username = username
16
+ self.password = password
17
+ self.db = db
18
+ self.port = port
19
+ self.con = pymysql.connect(host=self.host,user=self.username,password=self.password,database=self.db,port=self.port)
20
+ #whatsapp 广播
21
+ def whatsapp_broadcast_update(self,num,merchantId,waba,phone,country_code="86"):
22
+ """
23
+ :param num: 要插入的数据条数
24
+ :param merchantId:店铺ID
25
+ :param phone:插入的号码,插入的号码不能一样,所以会从这个递增
26
+ :param waba:店铺的wabaid
27
+ :return:
28
+ """
29
+ cur = self.con.cursor()
30
+ phone = phone
31
+ name = "jmeter压测%d"%int(time.time())
32
+ select_sql = """
33
+ select max(id) from sl_uc_test.whatsapp_contact;
34
+ """
35
+ cur.execute(select_sql)
36
+ id = cur.fetchone()[0]
37
+ # 准备批量插入的数据
38
+ insert_data = []
39
+ formatted_time =get_strf_time()
40
+ # print(id)
41
+ for i in range(num):
42
+ phone+=1
43
+ id+=1
44
+ phone_str = str(phone)
45
+ insert_data.append((
46
+ id,
47
+ merchantId,
48
+ waba,
49
+ name,
50
+ country_code,
51
+ phone_str,
52
+ phone_str,
53
+ phone_str,
54
+ 2,
55
+ None,
56
+ None,
57
+ None,
58
+ phone_str,
59
+ 1,
60
+ formatted_time,
61
+ formatted_time
62
+ ))
63
+
64
+ # 批量插入或更新
65
+ insert_sql = """
66
+ INSERT INTO sl_uc_test.whatsapp_contact
67
+ (id, merchant_id, merchant_waba_id, name, country_code, phone_number, display_phone_number, head_img, optin_status, interaction_time, customer_name, customer_id, waba_id, is_wabaaccount, update_time, create_time)
68
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
69
+ ON DUPLICATE KEY UPDATE
70
+ phone_number = VALUES(phone_number),
71
+ display_phone_number = VALUES(display_phone_number);
72
+ """
73
+ try:
74
+ # 开始事务
75
+ self.con.begin()
76
+ cur.executemany(insert_sql, insert_data)
77
+ # 提交事务
78
+ self.con.commit()
79
+ except Exception as e:
80
+ print(f"Error: {e}")
81
+ self.con.rollback() # 回滚事务
82
+ finally:
83
+ cur.close()
84
+ self.con.close()
85
+ #line、faceboook 、instagram 平台广播
86
+ def other_broadcast_update(self,num,page_id,platform):
87
+ """
88
+ page_id、platform 需要替换成自己店铺的数据,
89
+ num 为 插入的条数
90
+ """
91
+ interaction_time = get_strf_time()
92
+ cur = self.con.cursor()
93
+ select_sql = """
94
+ select max(id) from sl_uc_test.uc_user_interaction ;
95
+ """
96
+ cur.execute(select_sql)
97
+ id = cur.fetchone()[0]
98
+ # 准备批量插入的数据
99
+ formatted_time = get_strf_time()
100
+ insert_data = []
101
+ for i in range(num):
102
+ id+=1
103
+ user_id = '{}c4af{}k74{}9'.format(random.randint(100, 999), int(time.time()), generate_random_string(4))
104
+ insert_data.append((
105
+ id,
106
+ user_id,
107
+ page_id,
108
+ platform,
109
+ interaction_time,
110
+ formatted_time,
111
+ formatted_time
112
+ ))
113
+ # 批量插入或更新
114
+ insert_sql ="""
115
+ INSERT INTO sl_uc_test.uc_user_interaction
116
+ (id, platform_user_id, platform_channel_id, platform, interaction_time, create_time, update_time)
117
+ VALUES(%s, %s, %s, %s, %s, %s, %s);
118
+ """
119
+ try:
120
+ # 开始事务
121
+ self.con.begin()
122
+ cur.executemany(insert_sql, insert_data)
123
+ # 提交事务
124
+ self.con.commit()
125
+ except Exception as e:
126
+ print(f"Error: {e}")
127
+ self.con.rollback() # 回滚事务
128
+ finally:
129
+ cur.close()
130
+ self.con.close()
131
+
132
+
133
+ def select(self,select_sql):
134
+ # con = con_mysql()
135
+ cur = self.con.cursor()
136
+ cur.execute(select_sql)
137
+ data = cur.fetchall()
138
+ return data
139
+
140
+ def generate_random_string(length):
141
+ characters = string.ascii_letters + string.digits
142
+ return ''.join(secrets.choice(characters) for _ in range(length))
143
+
144
+ def get_strf_time():
145
+ # 获取当前时间
146
+ now = datetime.now()
147
+ # 格式化为字符串,确保微秒部分有 9 位数
148
+ formatted_time = now.strftime('%Y-%m-%d %H:%M:%S.%f')
149
+ # 将微秒部分填充到 9 位
150
+ formatted_time = formatted_time[:-3] + formatted_time[-3:].ljust(9, '0')
151
+ return formatted_time
152
+
153
+
154
+
155
+
156
+
157
+
158
+ if __name__=="__main__":
159
+ # host = "10.98.32.7"
160
+ # port = 6303
161
+ # db = "sl_sc_medium_test"
162
+ # username = "sl_sc2_backend"
163
+ # password = "XVPt6eS7r9nHZF8qlfoivy9u"
164
+
165
+ # host = "10.98.216.252"
166
+ # port = 3306
167
+ # db = "sl_uc_test"
168
+ # username = "admin"
169
+ # password = "p2qJrad0rr5AxfGGe3gN69fF"
170
+
171
+ host = "10.98.32.38"
172
+ port = 6304
173
+ db = "sl_uc_test"
174
+ username = "sl_sc_1_dev_test"
175
+ password = "VJ6H54iSPjStkFZqWiTYHJNe"
176
+ operaMysql = OperaMysql(host,username,password,db,port)
177
+ phone = 1827679999
178
+ num = 10
179
+ merchant_id = "613581c9820e260046693ef5"
180
+ waba = "102324679313339"
181
+ # operaMysql.whatsapp_broadcast_update(num,merchant_id,waba,phone)
182
+ # page_id = "110234798670383"
183
+ # platform = "FACEBOOK"
184
+ # ig
185
+ page_id = "17841453464121067"
186
+ platform = "INSTAGRAM"
187
+ operaMysql.other_broadcast_update(10,page_id,platform)
188
+
189
+
190
+
191
+
192
+
193
+
@@ -2,16 +2,13 @@ import json
2
2
  import ssl
3
3
  import time
4
4
 
5
+ import websockets
6
+ import asyncio
5
7
  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
8
  import websocket
12
9
 
13
10
  # 定义回调函数
14
- class WebSocketClient:
11
+ class WebSocketClient():
15
12
  def __init__(self, url,admin_url, sales_id):
16
13
  self.url = url
17
14
  self.admin_url = admin_url
@@ -66,6 +63,7 @@ class WebSocketClient:
66
63
 
67
64
  def run(self):
68
65
  self.ws.run_forever()
66
+
69
67
  def close(self):
70
68
  print("主动关闭")
71
69
  self.ws.close()
@@ -82,39 +80,65 @@ def get_imtoken(admin_url,sales_id):
82
80
  return subscribeToken,userToken
83
81
 
84
82
 
83
+ async def client(url,message):
84
+ async with websockets.connect(url) as websocket:
85
+ for msg in message:
86
+ await websocket.send(json.dumps(msg))
87
+ response = await websocket.recv()
88
+ print(response)
89
+
90
+ async def live_view_client(socket_url,admin_url,sales_id):
91
+ subscribeToken, userToken = get_imtoken(admin_url, sales_id)
92
+ message = []
93
+ stamp = int(time.time() * 1000)
94
+ reqid = "53%d" % stamp
95
+ #绑定设备
96
+ device = {
97
+ "version": 1,
98
+ "reqid": reqid,
99
+ "payload": {
100
+ "appid": "SL101-web",
101
+ "devid": "7ecce8fc-44af-4c65-b75b-aa84b%d" % stamp,
102
+ "sdkver": "1.1.0"
103
+ },
104
+ "type": "REQUEST",
105
+ "url": "ap://auth/device",
106
+ "sign": "TDbwNFgmAPEPG5VGn5ozdSShpPPHK8PVsir9VXQ1ygx/RaeKjJ8lRnWf+gZ9wUH72EkgjSFGHaisv77wE8sgBBxxUud81V19t/mJY03MUwPQLSxJEY0hPPPr4mGhDK4IxYx154OJieyiDKNR5zO3jiGrEFWSn1Ft/0uMugkHQe8="
107
+ }
108
+ # 订阅 将消息转换为 JSON 格式并发送
109
+
110
+ subscribe = {
111
+ "version": 1,
112
+ "reqid": reqid,
113
+ "payload": {
114
+ "groups": [
115
+ "POST_%d" % sales_id,
116
+ "VIEW_ONLINE_%d" % sales_id
117
+ ],
118
+ "token": subscribeToken
119
+ },
120
+ "type": "REQUEST",
121
+ "url": "http://broadcast/broadcast/subscribe",
122
+ "sign": "gaoLzQ6q1+Fn5uq0UqHAamaKJieEvMXRqo+rwR0u9WZnBhJ27StRlWohqCsO89/QyJvxupaGPuCwLpPji/xfMpeHacmodUrWO3J/EffRX0lGeIo+Zz35XjqleFruaXmu1GGkCQ82SZmNdaAo6YrGN//twyiIPNH3KZ7xNRO/+dI="
123
+ }
124
+ message.append(device)
125
+ message.append(subscribe)
126
+ await client(socket_url,message)
85
127
 
86
- def sign(msg, private_key):
87
- # 将消息编码为字节
88
- # 从 字符串加载私钥
89
- loaded_private_key = load_private_key(private_key)
90
- message_bytes = msg.encode('utf-8')
91
- # 使用私钥进行签名
92
- signature = loaded_private_key.sign(
93
- message_bytes,
94
- padding.PKCS1v15(),
95
- hashes.SHA1()
96
- )
97
- # 将签名转换为 Base64 编码
98
- return base64.b64encode(signature).decode('utf-8')
99
128
 
100
- def load_private_key(pri_key_str):
101
- # 从 PEM 格式字符串加载私钥
102
- return serialization.load_pem_private_key(
103
- pri_key_str.encode(),
104
- password=None,
105
- backend=default_backend()
106
- )
107
129
 
108
130
 
109
131
  if __name__=="__main__":
132
+ pass
110
133
  # admin_url = "https://front-service.shoplinestg.com"
111
134
  # url = "ws://service-websocket.myshoplinestg.com/"
112
135
  # url = "ws://api-webservice-preview.myshopline.com"
113
- url = "ws://api-webservice.myshopline.com"
114
- admin_url = "https://front-admin.shoplineapp.com"
115
-
116
- webSocketClient = WebSocketClient(url,admin_url,561242)
117
- webSocketClient.run()
118
- webSocketClient.close()
136
+ # url = "ws://api-webservice.myshopline.com"
137
+ # admin_url = "https://front-admin.shoplineapp.com"
138
+ # webSocketClient = WebSocketClient(url,admin_url,561242)
139
+ # webSocketClient.run()
140
+ # webSocketClient.close()
141
+ # asyncio.run(live_view_client(url,admin_url,561242))
142
+ #启用多个客户端
119
143
 
120
144
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.9.6
3
+ Version: 2.9.8
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -2,6 +2,7 @@ setup.py
2
2
  sc_common_interface/CommonOa.py
3
3
  sc_common_interface/LiveCommonInterface.py
4
4
  sc_common_interface/McCommonInterface.py
5
+ sc_common_interface/OperaMysql.py
5
6
  sc_common_interface/Platform.py
6
7
  sc_common_interface/PostCommonInterface.py
7
8
  sc_common_interface/ScWebsocket.py
@@ -1,3 +1,4 @@
1
1
  requests>=2.0.0
2
2
  jsonpath>=0.82
3
3
  websocket-client>=1.6.1
4
+ websockets>=15.0.1
@@ -2,14 +2,15 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc_common_interface',
5
- version='2.9.6',
5
+ version='2.9.8',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),
9
9
  install_requires=[
10
10
  "requests>=2.0.0",
11
11
  "jsonpath>=0.82",
12
- "websocket-client>=1.6.1"
12
+ "websocket-client>=1.6.1",
13
+ "websockets>=15.0.1"
13
14
  ]
14
15
  )
15
16