def get_qrCode(surroundings, orderId, cookies): # 获取买家订单序列号 OrderDetail_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/batchOrders/queryOrderDetail' OrderDetail_data = {"orderId": orderId, "buyOrSell": 1} OrderDetail_headers = {'login': ''} OrderDetail_res = HttpRequest().http_request(OrderDetail_url, 'post', data=OrderDetail_data, headers=OrderDetail_headers, cookies=cookies) qrCode = OrderDetail_res.json()['data']['qrCode'] return qrCode
def Pay(surroundings, orderNum, payPassword, payType, cookies): # 查询买家各种钱包明细 myPayWay_url = f"http://m.{surroundings}.hobay.com.cn/ribbon-api/userWallet/myPayWay" myPayWay_headers = {"login": ""} myPayWay_res = HttpRequest().http_request(myPayWay_url, "get", headers=myPayWay_headers, cookies=cookies) # 支付订单 pay_headers = {"login": "", "payPassword": payPassword} if payType in [3, 4]: pay_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/batchOrders/payAllCBP' pay_data = { "tradeNUm": orderNum, "payType": payType, "shareWalletUserId": "", "shareWalletId": "" } pay_res = HttpRequest().http_request(pay_url, "post", json=pay_data, cookies=cookies, headers=pay_headers) elif payType in [5, 6]: if payType == 5: shareWalletUserId = myPayWay_res.json( )['results']['myPayWay']['myKinship'][0]['shareWalletUserId'] shareWalletId = myPayWay_res.json( )['results']['myPayWay']['myKinship'][0]['shareWalletId'] elif payType == 6: shareWalletUserId = myPayWay_res.json( )['results']['myPayWay']['myWages']['shareWalletUserId'] shareWalletId = myPayWay_res.json( )['results']['myPayWay']['myWages']['shareWalletId'] pay_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/batchOrders/payAllCBP' pay_data = { "tradeNUm": orderNum, "payType": payType, "shareWalletUserId": shareWalletUserId, "shareWalletId": shareWalletId } pay_res = HttpRequest().http_request(pay_url, "post", json=pay_data, cookies=cookies, headers=pay_headers) elif payType == 7: pay_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/pay/payCash' pay_data = {"tradeNum": orderNum} pay_res = HttpRequest().http_request(pay_url, "post", data=pay_data, cookies=cookies, headers=pay_headers) return pay_res
def suer(surroundings, orderId, payType, sellerUserId, payPassword, cookies): # 确认收货 suer_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/orders/recieve' suer_data = {'orderId': orderId, 'payType': payType, 'sellerUserId': sellerUserId} suer_headers = {'login': '', 'payPassword': payPassword} suer_res = HttpRequest().http_request(suer_url, 'post', data=suer_data, headers=suer_headers, cookies=cookies) return suer_res
def get_productStockId(surroundings, product_name, cookies): # 卖家-商品管理 product_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/product/queryPageProductsByType?currentPage=1&type=2&pageSize=10' product_headers = {"login": ""} product_res = HttpRequest().http_request(product_url, "get", headers=product_headers, cookies=cookies) my_logger.debug(f"商品管理出售中的商品是:{product_res.json()}") # 获取商品规格id product_data = product_res.json()['data']['result'] for i in range(0, len(product_data)): if product_data[i]['title'] == product_name: productId = product_data[i]['id'] productStockId = product_data[i]['productStockWithStockImages'][0][ 'id'] return productId, productStockId
def login(surroundings, phone): login_url = f'http://m.{surroundings}.hobay.com.cn/api/app/user/login' # 登录 login_data = { "loginValidateType": "CODE", "phone": phone, "validateValue": "666666" } login_res = HttpRequest().http_request(login_url, "post", json=login_data) return login_res
def boss_setting_requests(surroundings, phone, operational_setting): ''' Parameters ---------- surroundings:test/dev1/mtest phone:手机号 operational_setting:[{'个人焕商': 1000650}, {'省代理商': 1000646, '市代理商': 1000647, '区代理商': 1000648}] Returns:None ------- ''' if operational_setting == "未设置": salesRatio = "0" freeSalesRatio = "0" tcoRatio = "0" else: salesRatio = str(operational_setting['销售']) freeSalesRatio = str(operational_setting['业务焕商']) tcoRatio = str(operational_setting['TCO']) # 登录 login_url = f'http://boss.{surroundings}.hobay.com.cn/bosszuul/boss/user/login' # 登录 login_data = {"phone": phone, "password": "******"} login_res = HttpRequest().http_request(login_url, "post", data=login_data) my_logger.debug(f"BOSS登录结果是:{login_res.json()}") # 设置运营比例 agentId = login_res.json()['id'] secondPayagentRatio_url = f'http://boss.{surroundings}.hobay.com.cn/bosszuul/order/secondPayagentRatio/addOrUpdateSecondPayagentRatio' secondPayagentRatio_data = { "agentId": agentId, "freeSalesRatio": freeSalesRatio, "salesRatio": salesRatio, "tcoRatio": tcoRatio } secondPayagentRatio_res = HttpRequest().http_request( secondPayagentRatio_url, "post", data=secondPayagentRatio_data, cookies=login_res.cookies) my_logger.debug(f"设置运营比例的结果是:{secondPayagentRatio_res.json()}")
def AcceptOrder(surroundings, orderId, cookies): order_data = {'orderStatus': 0, 'buyOrSell': 2, 'type': 0, 'currentPage': 1, 'pageSize': 10} AcceptOrder_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/orders/acceptOrder?orderId={orderId}' AcceptOrder_headers = {"login": ""} AcceptOrder_res = HttpRequest().http_request(AcceptOrder_url, "get", json=order_data, cookies=cookies, headers=AcceptOrder_headers) return AcceptOrder_res
def recharge(surroundings, payAmount, cookies): # 提交充值订单 recharge_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/charge/saveServiceFeeOrders' recharge_data = {"payAmount": payAmount} recharge_headers = {"login": ""} recharge_res = HttpRequest.http_request(recharge_url, "post", data=recharge_data, headers=recharge_headers, cookies=cookies) return recharge_res
def delete_partner(surroundings, seller_phone, userId): # 卖家登录 login_url = f'http://m.{surroundings}.hobay.com.cn/api/app/user/login' # 登录 seller_login_data = { "loginValidateType": "CODE", "phone": seller_phone, "validateValue": "666666" } seller_login_res = HttpRequest().http_request(login_url, "post", json=seller_login_data) my_logger.debug(f"登录结果是:{seller_login_res.json()}") url = f'http://m.{surroundings}.hobay.com.cn/api/user/partnership/delPartnership?userId={userId}' headers = {"login": ""} res = HttpRequest.http_request(url, "get", headers=headers, cookies=seller_login_res.cookies) my_logger.debug(f"删除伙伴的结果是:{res.status_code}")
def get_address_id(surroundings, cookies): address_url = f'http://m.{surroundings}.hobay.com.cn/api/user/graphql/flat' address_data = { "query": "query currentUser{\n currentUser{\n receiveAddress(page:1,pageSize:100){\n numPerPage\n pageNum\n totalCount\n totalPage\n recordList{\n id\n name\n provinceName\n cityName\n areaName\n detailAddress\n phone\n default\n }\n }\n }\n }" } address_headers = {"login": ""} address_res = HttpRequest().http_request(address_url, 'post', json=address_data, cookies=cookies, headers=address_headers) return address_res
def SaveOrder(surroundings, productId, productStockId, cookies, addressId=""): SaveOrder_headers = {"login": ""} # 获取商品类型 type_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/batchCart/immediatelyBuySettlement' type_data = { "productStockIdAndNums": [{ "num": 1, "productStockId": productStockId, "productId": productId }] } type_res = HttpRequest().http_request(type_url, "post", json=type_data, cookies=cookies, headers=SaveOrder_headers) goods_type = type_res.json()['data']['type'] # 提交订单 SaveOrder_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/batchOrders/immediatelySaveOrder' SaveOrder_data = { "message": "", "couponUserId": "", "addressId": addressId, "productStockIdAndNums": [{ "num": 1, "productStockId": productStockId }], "type": goods_type } SaveOrder_res = HttpRequest().http_request(SaveOrder_url, "post", json=SaveOrder_data, cookies=cookies, headers=SaveOrder_headers) return SaveOrder_res
def signed(surroundings, orderId, payType, sellerUserId, payPassword, cookies): # 签约 buyer_signed_url = f"http://m.{surroundings}.hobay.com.cn/ribbon-api/orders/signed" buyer_signed_data = { "orderId": orderId, "payType": payType, "sellerUserId": sellerUserId } buyer_signed_headers = {"login": "", "payPassword": payPassword} buyer_signed_res = HttpRequest().http_request(buyer_signed_url, "post", data=buyer_signed_data, cookies=cookies, headers=buyer_signed_headers) return buyer_signed_res
def consume(surroundings, orderId, payType, buyerUserId, qrCode, payPassword, cookies): # 卖家确认序列号 consume_url = f'http://m.{surroundings}.hobay.com.cn/ribbon-api/orders/consume' consume_data = { "orderId": orderId, "payType": payType, "buyerUserId": buyerUserId, "qrCode": qrCode } consume_headers = {'login': '', 'payPassword': payPassword} consume_res = HttpRequest().http_request(consume_url, 'post', data=consume_data, headers=consume_headers, cookies=cookies) return consume_res
def ship(surroundings, orderId, payType, buyer_userId, cookies): # 发货 ship_url = f'http://m.{surroundings}.hobay.com.cn/orders/sendProduct' ship_data = { 'orderId': orderId, 'payType': payType, 'buyerUserId': buyer_userId, 'type': 1, 'logisticsCompany': '德邦物流', 'companyNum': 'debangwuliu', 'logisticsNum': '123456789' } ship_headers = {'login': ''} ship_res = HttpRequest().http_request(ship_url, 'post', data=ship_data, headers=ship_headers, cookies=cookies) return ship_res