sc-common-interface 2.2.8__tar.gz → 2.3.0__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.2.8
3
+ Version: 2.3.0
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -19,6 +19,7 @@ def create_activity(data):
19
19
  if "platform" in data:
20
20
  platform = data["platform"].upper()
21
21
  response = requests.post(url,headers=headers,json=body)
22
+ print(response.json())
22
23
  if response.status_code==200:
23
24
  activity_id = response.json()["data"]
24
25
  return activity_id
@@ -96,6 +97,47 @@ def send__live_comment(data):
96
97
  response = requests.post(url, headers=header, data=json.dumps(body))
97
98
  return user_id, name, comment_id
98
99
 
100
+ def send_mc_message(data):
101
+ env = data["env"]
102
+ key = data["key"]
103
+ stamp = int(time.time()*1000)
104
+ user_id = "488864%d" % int(time.time())
105
+ if "user_id" in data:
106
+ user_id = data['user_id']
107
+ name = "test live%d" % int(time.time())
108
+ if "name" in data:
109
+ name = data['name']
110
+ message = "接口测试普通留言"
111
+ if "message" in data:
112
+ message = data['message']
113
+ page_id = ""
114
+ if "page_id" in data:
115
+ page_id = data['page_id']
116
+ platform = "FACEBOOK"
117
+ if "platform" in data:
118
+ platform = data['platform']
119
+ if page_id=="":
120
+ info = get_live_info(data)
121
+ platform_list = jsonpath(info, "$..relatedPostList..platform")
122
+ i = platform_list.index(platform)
123
+ page_id = info["data"]["relatedPostList"][i]["page_id"]
124
+ platform = info["data"]["relatedPostList"][i]["platform"]
125
+ body = {}
126
+ if platform.upper()=="FACEBOOK":
127
+ body = {"entry":[{"id":"%s"%page_id,"messaging":[{"message":
128
+ {"mid":"m_hhAqPhSlMTY4En2oWjSB59T3BFjeU97DdDV4WHr3DLWnPrO0iCsjQlG3hBN%d-sBlT26-6oNg"%stamp,"text":"%s"%message},
129
+ "recipient":{"id":"%s"%page_id},"sender":{"id":"%s"%user_id},"timestamp":stamp}],"time":stamp}],"object":"page"}
130
+ elif platform.upper()=="INSTAGRAM":
131
+ body={"object":"instagram","entry":[{"time":stamp,"id":"%s"%page_id,"messaging":[{"sender":{"id":"%s"%user_id},"recipient":{"id":"%s"%page_id},
132
+ "timestamp":stamp,"message":{"mid":"aWdfZAG1faXRlbToxOklHTWVzc2FnZAUlEOjE3ODQxNDUwMzgwODgwNTMzOjM0MDI4MjM2Njg0MTcxMDMwMTI0NDI3NjAyNDExMzcwMDc2NTA5MDozMTgzODU0Mzg3NTY4MDYwMTE3ODUxOTE2MD%d"%stamp,"text":"%s"%message}}]}]}
133
+ url = "%s/facebook/webhook" % env
134
+ sign_text = hmac.new(key.encode("utf-8"), json.dumps(body).encode("utf-8"), sha1)
135
+ signData = sign_text.hexdigest()
136
+ header = {"Content-Type": "application/json", "x-hub-signature": "sha1=%s" % signData}
137
+ response = requests.post(url, headers=header, data=json.dumps(body))
138
+ return user_id, name
139
+
140
+
99
141
 
100
142
  def get_live_info(data):
101
143
  env = data["env"]
@@ -167,6 +209,71 @@ def live_search_oa_gift(data):
167
209
  spu_id = gift_info["id"]
168
210
  return spu_id,gift_info,response
169
211
 
212
+ def live_search_oa_product(data):
213
+ """
214
+ 查询OA的商品,并返回响应,返回第一个有库存的商品
215
+ spu:返回无规格
216
+ sku:返回多规格
217
+ quantity:0 返回无库存商品
218
+ :param data:
219
+ :return:
220
+ """
221
+ env = data["env"]
222
+ headers = data["headers"]
223
+ url = "%s/openApi/proxy/v1/products?page=1&per_page=20" %env
224
+ type = "spu"
225
+ quantity = 100
226
+ if "type" in data:
227
+ type = data["type"]
228
+ if "quantity" in data:
229
+ quantity = data["quantity"]
230
+ if "query" in data:
231
+ query = data["query"]
232
+ url = "%s/openApi/proxy/v1/products?page=1&per_page=4&query=%s" % (env,query)
233
+ response = requests.get(url, headers=headers).json()
234
+ items = response["data"]["items"]
235
+ variant_options_list = jsonpath(items,"$..variations")
236
+ product_info = ""
237
+ spu_id = ""
238
+ sku_id = ""
239
+ sku_id_quantity =[]
240
+ for a, b in enumerate(variant_options_list):
241
+ if type=="spu" and b==[] and quantity!=0:
242
+ quantitys=items[a]["total_orderable_quantity"]
243
+ unlimited_quantity = items[a]["unlimited_quantity"]
244
+ if quantitys!=0 or unlimited_quantity==True:
245
+ product_info=items[a]
246
+ spu_id = items[a]["id"]
247
+ break
248
+ elif type=="sku" and b!=[] and quantity!=0:
249
+ quantitys = items[a]["total_orderable_quantity"]
250
+ unlimited_quantity = items[a]["unlimited_quantity"]
251
+ if quantitys!=0 or unlimited_quantity==True:
252
+ product_info = items[a]
253
+ spu_id = items[a]["id"]
254
+ sku_id = jsonpath(items[a]["variations"],"$..id")
255
+ sku_id_quantity = jsonpath(items[a]["variations"],"$..total_orderable_quantity")
256
+ break
257
+ elif type == "spu" and b == [] and quantity == 0:
258
+ quantitys = items[a]["total_orderable_quantity"]
259
+ unlimited_quantity = items[a]["unlimited_quantity"]
260
+ if quantitys != 0 or unlimited_quantity == True:
261
+ product_info = items[a]
262
+ spu_id = items[a]["id"]
263
+ break
264
+ elif type == "sku" and b != [] and quantity == 0:
265
+ quantitys = items[a]["total_orderable_quantity"]
266
+ unlimited_quantity = items[a]["unlimited_quantity"]
267
+ if quantitys != 0 or unlimited_quantity == True:
268
+ product_info = items[a]
269
+ spu_id = items[a]["id"]
270
+ sku_id = jsonpath(items[a]["variations"], "$..id")
271
+ sku_id_quantity = jsonpath(items[a]["variations"], "$..total_orderable_quantity")
272
+ break
273
+ return spu_id,sku_id,sku_id_quantity,product_info
274
+
275
+
276
+
170
277
  def get_merchant_info(data):
171
278
  env = data["env"]
172
279
  headers = data["headers"]
@@ -188,4 +295,4 @@ def get_merchant_info(data):
188
295
 
189
296
 
190
297
  if __name__=="__main__":
191
- pass
298
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.2.8
3
+ Version: 2.3.0
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc-common-interface',
5
- version='2.2.8',
5
+ version='2.3.0',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),