webapi.py 13 KB

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