webapi.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import json
  2. import requests
  3. from hytest.common import *
  4. from cfg import cfg
  5. #存放公用方法
  6. # 存储 全局共享 数据
  7. GSTORE = {}
  8. class APIMgr():
  9. #打印https请求与消息
  10. def __init__(self):
  11. self.ui = None
  12. def printRequest(self,req):
  13. if req.body==None:
  14. msgBody=''
  15. else:
  16. msgBody=req.body
  17. self.ui.outputWindow.append(
  18. '{}\n{}\n{}\n\n{}'.format(
  19. '\n\n-------发送请求--------',
  20. req.method+''+req.url,
  21. '\n'.join('{}:{}'.format(k,v) for k,v in req.headers.items()),
  22. msgBody,
  23. ))
  24. # 打印http相应消息的函数
  25. def printResponse(self, response):
  26. print('\n\n----- https response begin -----')
  27. print(response.status_code)
  28. # print(response.headers)
  29. for k, v in response.headers.items():
  30. print(f'{k}:{v}')
  31. print(response.content.decode('utf8'))
  32. print('----- https response end-----\n\n')
  33. headers = {
  34. "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"
  35. }
  36. #headers设置为全局变量
  37. GSTORE['headers'] = headers
  38. # session对象设置为全局变量
  39. s = requests.Session()
  40. GSTORE['s'] = s
  41. #pc登录接口
  42. def mgr_login(self, phone='18211989987', password='123456',useproxies=False):
  43. headers=GSTORE['headers']
  44. s = GSTORE['s']
  45. if useproxies:
  46. self.s.proxies.update({'http':'127.0.0.1:8888'})
  47. response = self.s.post(f"{cfg.target_host}/phone/login",headers=headers,data=
  48. {
  49. 'reqType': 'phoneLogin',
  50. 'isAutoLogin': 'false',
  51. 'phone':phone,
  52. 'password':password
  53. })
  54. self.printResponse(response)
  55. # 把response对象返回出去
  56. return response
  57. # app登录接口
  58. def mgr_login_app(self, phone='18211989987', password='123456',useproxies=False):
  59. headers=GSTORE['headers']
  60. s = GSTORE['s']
  61. if useproxies:
  62. self.s.proxies.update({'http':'127.0.0.1:8888'})
  63. response = self.s.post(f"{cfg.target_host_app}/jyapp/free/login",headers=headers,params=
  64. {
  65. 'reqType': 'phoneLogin',
  66. 'phone':phone,
  67. 'password':password,
  68. 'rid':'',
  69. 'oid': '',
  70. 'phoneType': '',
  71. 'channel': '',
  72. 'deviceId': ''
  73. })
  74. self.printResponse(response)
  75. # 把response对象返回出去
  76. return response
  77. """退出登录pc"""
  78. def mgr_logout(self):
  79. url = f"{cfg.target_host}/front/signOut"
  80. headers = GSTORE['headers']
  81. s = GSTORE['s']
  82. s.post(url=url, headers=headers)
  83. # self.printResponse(res)
  84. # return res
  85. """退出登录app"""
  86. def mgr_logout_app(self):
  87. url = f"{cfg.target_host_app}/jyapp/free/signOut"
  88. headers = GSTORE['headers']
  89. s = GSTORE['s']
  90. s.post(url=url, headers=headers)
  91. #招标搜索
  92. def bidsearch(self, keywords="建筑", publishtime="fiveyear", selectType="content"):
  93. #使用全局变量
  94. headers = GSTORE['headers']
  95. params={"keywords":keywords,"publishtime":publishtime,"timeslot":"","area":"","subtype":"","minprice":"","maxprice":"","industry":"","buyerclass":"","buyertel":"","winnertel":"","selectType":selectType,"notkey":"","fileExists":"0","city":"","searchGroup":"0","searchMode":"0","wordsMode":"0","additionalWords":""}
  96. #保存session
  97. session = self.s
  98. response = session.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, params=params)
  99. self.printResponse(response)
  100. return response
  101. # 企业搜索
  102. def enterpriseSearch(self, match="北京剑鱼信息技术有限公司河南分公司", matchType="A", pageSize="10", pageNum="0"):
  103. # 使用全局变量
  104. headers = GSTORE['headers']
  105. # 保存session
  106. session = self.s
  107. response = session.post(f"{cfg.target_host}/publicapply/enterpriseSearch/doQuery", headers=headers, data={
  108. 'match': match,
  109. 'matchType': matchType,
  110. 'pageSize': pageSize,
  111. 'pageNum': pageNum
  112. })
  113. self.printResponse(response)
  114. return response
  115. # 供应搜索
  116. def supplySearch(self, keywords="PH计", searchType="title", province="", city="", time="", status="0",
  117. pageSize=50, pageIndex=1):
  118. headers = GSTORE['headers']
  119. headers['Content-Type'] = 'application/json' # 添加Content-Type头部
  120. url = f"{cfg.target_host}/jyinfo/supplySearch"
  121. data = {
  122. "keywords": keywords,
  123. "searchType": searchType,
  124. "province": province,
  125. "city": city,
  126. "time": time,
  127. "status": status,
  128. "pageSize": pageSize,
  129. "pageIndex": pageIndex
  130. }
  131. session=self.s
  132. response = session.post(url=url, headers=headers, data=json.dumps(data))
  133. self.printResponse(response)
  134. return response
  135. #采购单位搜索
  136. def buyersousuo(self, buyerName, province=None, city=None, buyerClass=None, isCheckFollow=True, isCheckReceive=True,
  137. isContact=0, pageSize=10, pageNum=1):
  138. if buyerClass is None:
  139. buyerClass = []
  140. if city is None:
  141. city = []
  142. if province is None:
  143. province = []
  144. url = f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList"
  145. data = {
  146. "buyerName": buyerName,
  147. "province": province,
  148. "city": city,
  149. "buyerClass": buyerClass,
  150. "isCheckFollow": isCheckFollow,
  151. "isCheckReceive": isCheckReceive,
  152. "isContact": isContact,
  153. "pageSize": pageSize,
  154. "pageNum":pageNum
  155. }
  156. response = requests.post(url=url, json=data, headers=self.headers)
  157. self.printResponse(response)
  158. return response
  159. #接口数据传值常用三种方式:urlencoded---params,键值对---data,json格式---json
  160. #获取推送记录接口
  161. def push_list(self):
  162. headers=GSTORE['headers']
  163. s = GSTORE['s']
  164. response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/fType/list",headers=headers,json=
  165. {"pageNum": 1, "pageSize": 50, "format": "table", "area": "", "selectTime": "all", "city": "", "buyerClass": "",
  166. "subtype": "", "industry": "", "keyWords": "", "fileExists": "", "price": "", "source": "", "exportNum": "",
  167. "vt": ""})
  168. return response
  169. # 不登录招标搜索
  170. def notloggedin_search(self, keyword='科技', publishtime='thisyear', selectType='content,title'):
  171. headers = GSTORE['headers']
  172. params={"keywords": keyword , "publishtime": publishtime, "timeslot": "", "area": "", "subtype": "",
  173. "minprice": "", "maxprice": "", "industry": "", "buyerclass": "", "buyertel": "", "winnertel": "",
  174. "selectType": selectType, "notkey": "", "fileExists": "0", "city": "", "searchGroup": "0",
  175. "searchMode": "0", "wordsMode": "0", "additionalWords": ""}
  176. response = requests.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, params=params)
  177. response.raise_for_status() # 如果请求失败,会抛出异常
  178. return response
  179. #不登录采购单位搜索
  180. def notloggedin_buysearch(self,keyword):
  181. headers = GSTORE['headers']
  182. s = GSTORE['s']
  183. data = {"buyerName":keyword,"province":[],"city":[],"buyerClass":[],"isCheckFollow":False,"isCheckReceive":False,"isContact":0,"pageSize":10,"pageNum":1}
  184. response =s.post(f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList", headers=headers, json=data)
  185. # response.raise_for_status() # 如果请求失败,会抛出异常
  186. return response
  187. #消息中心列表
  188. def get_messagelist(self):
  189. headers = GSTORE['headers']
  190. s = GSTORE['s']
  191. response=s.post(f"{cfg.target_host}/jyapi/messageCenter/MessageList",headers=headers,json=
  192. {"msgType":-1,"isRead":-1,"offset":1,"size":20})
  193. return response
  194. """用户中台"""
  195. def get_userCenter(self):
  196. hearders = GSTORE['headers']
  197. s = GSTORE['s']
  198. response = s.post(f"{cfg.target_host}/userCenter/workDesktop/menuInfo", headers=hearders)
  199. return response
  200. """我的订单"""
  201. def get_myOrder(self):
  202. hearders = GSTORE['headers']
  203. s = GSTORE['s']
  204. params = {
  205. "type": 0,
  206. "pageNum": 1,
  207. "fromPage": "pc",
  208. "page_size": 10
  209. }
  210. response = s.post(f"{cfg.target_host}/subscribepay/orderListDetails/myOrder", headers=hearders, params=params)
  211. return response
  212. """优惠卷"""
  213. def get_coupon(self):
  214. hearders = GSTORE['headers']
  215. s = GSTORE['s']
  216. params={
  217. "mold": 4,
  218. "currentPage": 1,
  219. "pageSize": 8,
  220. "platform": "P"
  221. }
  222. response= s.post(f"{cfg.target_host}/jyCoupon/getInfoByUser", headers=hearders,params=params)
  223. return response
  224. """数据自动导出"""
  225. def get_dataExport(self,publishtime=1672502400_1688951529,keyword='数据',selectType='title'):
  226. hearders = GSTORE['headers']
  227. s = GSTORE['s']
  228. params={
  229. "publishtime":publishtime,
  230. "area":"",
  231. "city":"",
  232. "region":"",
  233. "industry":"",
  234. "buyerclass":"",
  235. "keyword": [{"keyword":keyword,"appended":[],"exclude":[]}],
  236. "selectType":selectType,
  237. "minprice":"",
  238. "maxprice":"",
  239. "subtype":"",
  240. "buyer":"",
  241. "winner":"",
  242. "dataType": 2
  243. }
  244. response = s.post(f"{cfg.target_host}/front/dataExport/sieveData", headers=hearders, params=params)
  245. return response
  246. """数据导出记录"""
  247. def Export_recordList(self):
  248. hearders = GSTORE['headers']
  249. s = GSTORE['s']
  250. params={
  251. "pageNum": 0,
  252. "pageSize": 10
  253. }
  254. response = s.post(f"{cfg.target_host}/subscribepay/dataExportPack/recordList", headers=hearders, params=params)
  255. return response
  256. """剑鱼文库搜索"""
  257. def Library_search(self,keyWord='数据'):
  258. hearders = GSTORE['headers']
  259. s = GSTORE['s']
  260. params={
  261. "keyWord":keyWord,
  262. "tag":"",
  263. "sort": "tSort",
  264. "num": 1,
  265. "size": 10
  266. }
  267. response = s.post(f"{cfg.target_host}/jydocs/search", headers=hearders, params=params)
  268. return response
  269. """剑鱼文库收藏"""
  270. def Library_collection(self):
  271. hearders = GSTORE['headers']
  272. s = GSTORE['s']
  273. params={
  274. "sign": 1,
  275. "num": 1,
  276. "size": 10
  277. }
  278. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  279. return response
  280. """剑鱼文库我的文库"""
  281. def My_library(self):
  282. hearders = GSTORE['headers']
  283. s = GSTORE['s']
  284. params={
  285. "sign": 0,
  286. "num": 1,
  287. "size": 10
  288. }
  289. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  290. return response
  291. """项目进度监控"""
  292. def Project_monitoring(self):
  293. hearders = GSTORE['headers']
  294. s = GSTORE['s']
  295. params={
  296. "pageNum": 0,
  297. "pageSize": 500
  298. }
  299. response = s.post(f"{cfg.target_host}/bigmember/follow/project/list", headers=hearders, params=params)
  300. return response
  301. """企业情报监控"""
  302. def Enterprise_monitoring(self):
  303. hearders = GSTORE['headers']
  304. s = GSTORE['s']
  305. params={
  306. "pageNum": 0,
  307. "pageSize": 10,
  308. "match":"",
  309. "group":"",
  310. }
  311. response = s.post(f"{cfg.target_host}/bigmember/follow/ent/list", headers=hearders, params=params)
  312. return response
  313. """客户监控"""
  314. def Customer_monitoring(self,):
  315. hearders = GSTORE['headers']
  316. s = GSTORE['s']
  317. params = {
  318. "pagesize": 10,
  319. "pageno": 0,
  320. "keyword":""
  321. }
  322. response = s.post(f"{cfg.target_host}/publicapply/customer/list", headers=hearders, params=params)
  323. return response
  324. """标讯收藏"""
  325. def Message_Collection(self):
  326. hearders = GSTORE['headers']
  327. s = GSTORE['s']
  328. params={
  329. "buyerPhone":0,
  330. "buyerclass":"",
  331. "label":"",
  332. "pagenum":1,
  333. "pagesize":50,
  334. "selectTime":"",
  335. "winnerPhone":0
  336. }
  337. response = s.post(f"{cfg.target_host}/publicapply/bidcoll/list", headers=hearders, params=params)
  338. return response
  339. """标讯收藏"""
  340. apimgr = APIMgr()