Arthur-Wu committed this file on 2024-11-15
This commit is contained in:
198
YiMao/businessFunc/ClientApiLib.py
Normal file
198
YiMao/businessFunc/ClientApiLib.py
Normal file
@ -0,0 +1,198 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/11/14-14:35
|
||||
# @Description::
|
||||
import requests,json, logging
|
||||
from commons.SignatureYM import SignatureYM2
|
||||
|
||||
|
||||
|
||||
class YMClientApi(object):
|
||||
def __init__(self):
|
||||
self.Domain = "https://api.test.yimaogo.com/cart"
|
||||
self.headerss = SignatureYM2(Mac="b8:2d:28:04:c7:5c")._headers()
|
||||
|
||||
def session_start(self):
|
||||
logging.info("========== [前置] session_start ==========")
|
||||
url = self.Domain+"/v1/session/start"
|
||||
payload = ""
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
def session_end(self):
|
||||
logging.info("========== [后置] session_end ==========")
|
||||
url = self.Domain+"/v1/session/end?reason"
|
||||
payload = {}
|
||||
response = requests.request("PUT", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
def login_app_v2(self, Payload):
|
||||
'''
|
||||
1-匿名登录
|
||||
{"action": 0, "isAnon": True}
|
||||
2-会员登录
|
||||
{"action":1,"code":"18052753212","isAnon":False}
|
||||
:param Payload:
|
||||
:return:
|
||||
'''
|
||||
logging.info("========== [登录] login_app_v2 ==========")
|
||||
payload = json.dumps(Payload)
|
||||
url = self.Domain+"/v2/login"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def get_login_type(self):
|
||||
logging.info("========== [获取登录方式] get_login_type ==========")
|
||||
payload = {}
|
||||
url = self.Domain+"/v2/login/type?action=1"
|
||||
response = requests.request("GET", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
def get_goods_info(self, InputCode):
|
||||
logging.info("========== [获取商品信息] get_goods_info ==========")
|
||||
payload = {}
|
||||
url = self.Domain+"/v2/shopping/{inputCode}".replace("{inputCode}", str(InputCode))
|
||||
response = requests.request("GET", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def add_retire_purchase(self, GoodsInfoData, LoginData):
|
||||
logging.info("========== [加入购物车] add_retire_purchase ==========")
|
||||
payload = json.dumps({
|
||||
"addGoods":[{
|
||||
"inputCode": GoodsInfoData["data"]["inputCode"],
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": GoodsInfoData["data"]["qty"],
|
||||
"weight": int(GoodsInfoData["data"]["weight"]),
|
||||
}],
|
||||
"autoSelectCoupon": True,
|
||||
"coupons": [],
|
||||
"deleteGoods": [],
|
||||
"existGoods": [],
|
||||
"orderNo": LoginData["data"][0]["orderNo"]
|
||||
})
|
||||
url = self.Domain+"/v2/shopping/add/retire/purchase"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
def get_coupon_list(self):
|
||||
logging.info("========== [获取优惠券列表] get_coupon_list ==========")
|
||||
payload = json.dumps({
|
||||
"code":"4",
|
||||
"value":""
|
||||
})
|
||||
url = self.Domain+"/v1/coupon/list"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def receive_coupon(self, CouponListData):
|
||||
logging.info("========== [领取优惠券] receive_coupon ==========")
|
||||
CouponList = []
|
||||
for i in CouponListData["data"]:
|
||||
CouponList.append(i["name"])
|
||||
payload = json.dumps({"activityIds": CouponList})
|
||||
url = self.Domain+"/v1/coupon/receive"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def query_coupon_list_user(self):
|
||||
logging.info("========== [查询优惠券列表] query_coupon_list_user ==========")
|
||||
payload = {}
|
||||
url = self.Domain+"/v1/coupon/list/user?state=2&page=0&pageSize=10"
|
||||
response = requests.request("GET", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def get_cart_goods_info(self, GoodsInfoData):
|
||||
logging.info("========== [获取购物车商品信息] get_cart_goods_info ==========")
|
||||
payload = json.dumps({"goodsParamList":[{
|
||||
"inputCode": GoodsInfoData["data"]["inputCode"],
|
||||
"qty": GoodsInfoData["data"]["qty"],
|
||||
"weight": int(GoodsInfoData["data"]["weight"]),
|
||||
}]})
|
||||
url = self.Domain+"/v2/shopping/cart/goods/info"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def request_order_settlement(self, LoginData):
|
||||
logging.info("========== [请求订单结算] request_order_settlement ==========")
|
||||
payload = json.dumps({
|
||||
"orderNo": LoginData["data"][0]["orderNo"],
|
||||
"setCouponFlag": False,
|
||||
"setPayMethodFlag": False
|
||||
})
|
||||
url = self.Domain+"/v2/shopping/order/settle"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
''' 加购购物袋
|
||||
POST
|
||||
https://api.test.yimaogo.com/cart/v2/shopping/add/retire/purchase
|
||||
|
||||
payload = {"addGoods":[{"inputCode":"6942728414063","isNormalAddPurchase":true,"qty":1,"weight":0}],"autoSelectCoupon":true,"coupons":[],"deleteGoods":[],"existGoods":[],"orderNo":"1857003957307801600"}
|
||||
'''
|
||||
|
||||
|
||||
|
||||
''' 2- without sessionid '''
|
||||
def get_ads_list(self):
|
||||
logging.info("========== [获取广告列表] get_ads_list ==========")
|
||||
''' method 1 '''
|
||||
payload = {}
|
||||
url = self.Domain+"/v1/ads/list?areaCode&userId&barcode&adsAreaIds=1,2,3,4,5,6"
|
||||
logging.info(f"---url: {url}---")
|
||||
logging.info(f"---headers: {self.headerss}---")
|
||||
response = requests.request("GET", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def query_ad_detail(self, ADsId:str):
|
||||
logging.info("========== [查询广告详情] query_ad_detail ==========")
|
||||
payload = {}
|
||||
url = self.Domain+"/v1/ads/{adsId}".replace("{adsId}", str(ADsId))
|
||||
response = requests.request("GET", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ym = YMClientApi()
|
||||
''' 01- '''
|
||||
ym.session_start() # step1:session开始
|
||||
Payload01 = {"action": 0, "isAnon": True}
|
||||
LoginData = ym.login_app_v2(Payload01) # step2:匿名登录
|
||||
ym.get_login_type() # step3:获取登录方式
|
||||
Payload02 = {"action": 1, "code": "18052753212", "isAnon": False}
|
||||
ym.login_app_v2(Payload02) # step4:切换会员登录
|
||||
GoodsInfoData = ym.get_goods_info(InputCode=6924882486100) # step5:获取商品信息
|
||||
CouponListData = ym.get_coupon_list() # step6:获取优惠券列表
|
||||
ym.receive_coupon(CouponListData) # step7:领取优惠券
|
||||
ym.query_coupon_list_user() # step8:查询用户持有的优惠券列表
|
||||
ym.add_retire_purchase(GoodsInfoData, LoginData) # step9:加购商品
|
||||
ym.get_cart_goods_info(GoodsInfoData) # step10:获取购物车商品信息
|
||||
ym.request_order_settlement(LoginData) # step11:请求订单结算
|
||||
|
||||
ym.session_end()
|
||||
|
78
YiMao/businessFunc/ServiceApiLib.py
Normal file
78
YiMao/businessFunc/ServiceApiLib.py
Normal file
@ -0,0 +1,78 @@
|
||||
# !/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author:: Arthur Wu
|
||||
# @Date:: 2024/11/15-13:10
|
||||
# @Description::
|
||||
import requests,json, time, logging
|
||||
from configs.globalParams import *
|
||||
from commons.SignatureYM import SignatureYM
|
||||
|
||||
|
||||
class YMServiceApi(object):
|
||||
def __init__(self):
|
||||
self.Domain = "https://api.test.yimaogo.com/"
|
||||
self.headerss = SignatureYM().return_headers()
|
||||
|
||||
''' 1-广告模块 '''
|
||||
def publish_ad(self, ADDetail, MarketAndStoreDetail):
|
||||
logging.info("========== [发布广告] ==========")
|
||||
timeStamp = str(int(time.time()))
|
||||
PublicParams = {
|
||||
"status": 4, "name": "Auto"+timeStamp,
|
||||
"agencyId": 3, "agencyName": "洪家班", "advertiserId": 3,
|
||||
"advertiserName": "阿宝传媒", "adsUse": 1, "customerTag": 3,
|
||||
"putRangeCycle": "[7,6,5,1,2,3,4]",
|
||||
"addType": 1, "pricingType": 1, "standardPrice": "1", "minPrice": "1",
|
||||
"putStart": GlobalParams["todayDate"], "putEnd": GlobalParams["todayDate"],
|
||||
"putStartTime": "00:00:00", "putEndTime": "23:00:00"
|
||||
}
|
||||
payload = json.dumps(PublicParams | ADDetail | MarketAndStoreDetail)
|
||||
url = self.Domain + "admin/ads"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
yms = YMServiceApi()
|
||||
''' 武商 '''
|
||||
ADDetail = [
|
||||
{ # 登录页
|
||||
"adsAreaId": 1, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/534ae9d7-3f65-48da-bc2e-3d5e66fe56d8.jpg",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 登录后弹窗
|
||||
"adsAreaId": 2, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/93e34d0e-9f4c-499b-ad8b-5741e55528b5.jpg",
|
||||
},
|
||||
{ # 购物车主页
|
||||
"adsAreaId": 3, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/581ec30a-4d90-43f3-b0e9-b5c8fe0006b4.jpg",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 待机页
|
||||
"adsAreaId": 4, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/8c8f6de0-6eb7-4b66-98cd-2c85eb057ed5.png",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 扫码
|
||||
"adsAreaId": 5, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/9d5555e3-fec1-4e1a-94e7-b517f4e88aba.jpg",
|
||||
},
|
||||
{ # 支付后
|
||||
"adsAreaId": 6, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/e2e2e892-1a81-4b0f-9af2-cb46f04a5dc4.jpg",
|
||||
},
|
||||
{ # 小票
|
||||
"adsAreaId": 7, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/6d9c14ca-3fd1-4fe7-b04a-84cf18937e60.jpg",
|
||||
}
|
||||
]
|
||||
MarketAndStoreDetail = {"putMarketId": 50, "putStoreId": ["29"]}
|
||||
for ad in ADDetail:
|
||||
yms.publish_ad(ad, MarketAndStoreDetail)
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user