import json import requests from hytest.common import * from cfg import cfg from bs4 import BeautifulSoup from requests.packages import urllib3 #存放公用方法 # 存储 全局共享 数据 GSTORE = {} class APIMgr(): #打印https请求与消息 def __init__(self): self.ui = None self.token = None def printRequest(self,req): if req.body==None: msgBody='' else: msgBody=req.body self.ui.outputWindow.append( '{}\n{}\n{}\n\n{}'.format( '\n\n-------发送请求--------', req.method+''+req.url, '\n'.join('{}:{}'.format(k,v) for k,v in req.headers.items()), msgBody, )) # 打印http相应消息的函数 def printResponse(self, response): print('\n\n----- https response begin -----') print(response.status_code) # print(response.headers) for k, v in response.headers.items(): print(f'{k}:{v}') print(response.content.decode('utf8')) print('----- https response end-----\n\n') headers = { 'Accept-Charset':'utf-8', 'Accept':'*/*', 'Accept-Encoding':'gzip, deflate, br', 'User-Agent':'Apifox/1.0.0 (https://apifox.com)', 'Content-Type':'application/json', 'MiniprogramCode':'wy_zbxm' } #headers设置为全局变量 GSTORE['headers'] = headers # session对象设置为全局变量 s = requests.Session() GSTORE['s'] = s # 小程序登录接口 def mgr_login_wxapi(self, useproxies=False): headers=GSTORE['headers'] s = GSTORE['s'] if useproxies: self.s.proxies.update({'http':'127.0.0.1:8888'}) response = self.s.post(f"{cfg.target_host_wxapi}/debrisproduct/free/autologin",headers=headers,json= { 'phone':'15037870765', 'token':'8817684142977367381' }) self.printResponse(response) # 把response对象返回出去 return response """退出登录小程序""" def mgr_logout_wxapi(self): url = f"{cfg.target_host_wxapi}/debrisproduct/logout" headers = GSTORE['headers'] s = GSTORE['s'] s.post(url=url, headers=headers) """我的用户信息""" def myuser_information(self): hearders = GSTORE['headers'] s = GSTORE['s'] response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/myinfo", headers=hearders) return response """招标项目搜索-搜索入口""" def bidding_project_search(self): hearders = GSTORE['headers'] s = GSTORE['s'] json={ "area": "河南", "propertyForm": "医院", "OwnerType": "医疗单位", "Page": 1, "PageSize": 1, "KeyWords": "物业" } response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/bidList", headers=hearders, json=json) return response """采购意向搜索-搜索入口""" def purchase_intention_search(self): hearders = GSTORE['headers'] s = GSTORE['s'] json={ "area": "安徽", "propertyForm": "学校", "OwnerType": "教育单位", "Page": 1, "PageSize": 1, "KeyWords": "数据" } response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/buyPurposeList", headers=hearders, json=json) return response """招标项目搜索-订阅入口""" def tender_subscription(self): hearders = GSTORE['headers'] s = GSTORE['s'] json={ "area": "河南", "propertyForm": "医院", "OwnerType": "医疗单位", "Page": 1, "PageSize": 1, "KeyWords": "物业" } response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/bidSubscribeList", headers=hearders, json=json) return response """采购意向搜索-订阅入口""" def purchase_intention_subscription(self): hearders = GSTORE['headers'] s = GSTORE['s'] json={ "area": "安徽", "propertyForm": "学校", "OwnerType": "教育单位", "Page": 1, "PageSize": 1, "KeyWords": "数据" } response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/buyPurposeSubscribeList", headers=hearders, json=json) return response apimgr = APIMgr()