webapi.py 16 KB

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