123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import requests, json
- from hytest.common import *
- from cfg import cfg
- from requests.packages import urllib3
- #存放公用方法
- # 存储 全局共享 数据
- GSTORE = {}
- class APIMgr():
- #打印https请求与消息
- 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 = {
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67"
- }
- #headers设置为全局变量
- GSTORE['headers'] = headers
- # session对象设置为全局变量
- s = requests.Session()
- GSTORE['s'] = s
- #登录接口
- def mgr_login(self, phone='18211989987', password='123456',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}/phone/login",headers=headers,data=
- {
- 'reqType': 'phoneLogin',
- 'isAutoLogin': 'false',
- 'phone':phone,
- 'password':password
- })
- self.printResponse(response)
- # 把response对象返回出去
- return response
- def mgr_logout(self):
- url = f"{cfg.target_host}/front/signOut"
- headers = GSTORE['headers']
- s = GSTORE['s']
- s.post(url=url, headers=headers)
- # self.printResponse(res)
- # return res
- def search(self, keywords="建筑", publishtime="fiveyear", selectType="content"):
- #使用全局变量
- headers = GSTORE['headers']
- #保存session
- session = self.s
- response = session.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, data={
- 'keywords': keywords,
- 'publishtime': publishtime,
- 'selectType': selectType
- })
- self.printResponse(response)
- return response
- # 企业搜索
- def enterpriseSearch(self, match="北京剑鱼信息技术有限公司河南分公司", matchType="A", pageSize="10", pageNum="0"):
- # 使用全局变量
- headers = GSTORE['headers']
- # 保存session
- session = self.s
- response = session.post(f"{cfg.target_host}/publicapply/enterpriseSearch/doQuery", headers=headers, data={
- 'match': match,
- 'matchType': matchType,
- 'pageSize': pageSize,
- 'pageNum': pageNum
- })
- self.printResponse(response)
- return response
- # 供应搜索
- def supplySearch(self, keywords="PH计", searchType="title", province="", city="", time="", status="0",
- pageSize=50, pageIndex=1):
- headers = GSTORE['headers']
- headers['Content-Type'] = 'application/json' # 添加Content-Type头部
- url = f"{cfg.target_host}/jyinfo/supplySearch"
- data = {
- "keywords": keywords,
- "searchType": searchType,
- "province": province,
- "city": city,
- "time": time,
- "status": status,
- "pageSize": pageSize,
- "pageIndex": pageIndex
- }
- session=self.s
- response = session.post(url=url, headers=headers, data=json.dumps(data))
- self.printResponse(response)
- return response
- #采购单位搜索
- def buyersousuo(self, buyerName, province=[], city=[], buyerClass=[], isCheckFollow=True, isCheckReceive=True,
- isContact=0, pageSize=10,pageNum=1):
- url = f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList"
- data = {
- "buyerName": buyerName,
- "province": province,
- "city": city,
- "buyerClass": buyerClass,
- "isCheckFollow": isCheckFollow,
- "isCheckReceive": isCheckReceive,
- "isContact": isContact,
- "pageSize": pageSize,
- "pageNum":pageNum
- }
- response = requests.post(url=url, data=json.dumps(data), headers=self.headers)
- self.printResponse(response)
- return response
- #获取推送记录接口
- def push_list(self):
- headers=GSTORE['headers']
- s = GSTORE['s']
- response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/fType/list",headers=headers,json=
- {"pageNum": 1, "pageSize": 50, "format": "table", "area": "", "selectTime": "all", "city": "", "buyerClass": "",
- "subtype": "", "industry": "", "keyWords": "", "fileExists": "", "price": "", "source": "", "exportNum": "",
- "vt": ""})
- return response
- #不登录招标搜索
- def notloggedin_search(self, keyword='科技', publishtime='thisyear', selectType='content,title'):
- headers = GSTORE['headers']
- params={"keywords": keyword , "publishtime": publishtime, "timeslot": "", "area": "", "subtype": "",
- "minprice": "", "maxprice": "", "industry": "", "buyerclass": "", "buyertel": "", "winnertel": "",
- "selectType": selectType, "notkey": "", "fileExists": "0", "city": "", "searchGroup": "0",
- "searchMode": "0", "wordsMode": "0", "additionalWords": ""}
- response = requests.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, params=params)
- response.raise_for_status() # 如果请求失败,会抛出异常
- return response
- #不登录采购单位搜索
- def notloggedin_buysearch(self,keyword):
- headers = GSTORE['headers']
- s = GSTORE['s']
- data = {"buyerName":keyword,"province":[],"city":[],"buyerClass":[],"isCheckFollow":False,"isCheckReceive":False,"isContact":0,"pageSize":10,"pageNum":1}
- response =s.post(f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList", headers=headers, json=data)
- # response.raise_for_status() # 如果请求失败,会抛出异常
- return response
- apimgr = APIMgr()
|