webapi.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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",pageSize=50, pageIndex=1):
  120. headers = GSTORE['headers']
  121. headers['Content-Type'] = 'application/json' # 添加Content-Type头部
  122. url = f"{cfg.target_host}/jyinfo/supplySearch"
  123. data = {
  124. "keywords": keywords,
  125. "searchType": searchType,
  126. "province": province,
  127. "city": city,
  128. "time": time,
  129. "status": status,
  130. "pageSize": pageSize,
  131. "pageIndex": pageIndex
  132. }
  133. session=self.s
  134. response = session.post(url=url, headers=headers, data=json.dumps(data))
  135. self.printResponse(response)
  136. return response
  137. #采购单位搜索
  138. def buyersousuo(self, buyerName, province=None, city=None, buyerClass=None, isCheckFollow=True, isCheckReceive=True,isContact=0, pageSize=10, pageNum=1):
  139. if buyerClass is None:
  140. buyerClass = []
  141. if city is None:
  142. city = []
  143. if province is None:
  144. province = []
  145. url = f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList"
  146. data = {
  147. "buyerName": buyerName,
  148. "province": province,
  149. "city": city,
  150. "buyerClass": buyerClass,
  151. "isCheckFollow": isCheckFollow,
  152. "isCheckReceive": isCheckReceive,
  153. "isContact": isContact,
  154. "pageSize": pageSize,
  155. "pageNum":pageNum
  156. }
  157. response = requests.post(url=url, json=data, headers=self.headers)
  158. self.printResponse(response)
  159. return response
  160. #融创用户搜索
  161. def rc_search(self):
  162. headers = GSTORE['headers']
  163. headers['Content-Type'] = 'application/json' # 添加Content-Type头部
  164. url = f"{cfg.target_host}/jyapi/jybx/core/mType/searchList"
  165. params={
  166. "searchGroup": 0,
  167. "reqType": "lastNews",
  168. "pageNum": 1,
  169. "pageSize": 50,
  170. "keyWords": "医疗设备",
  171. "searchMode": 0,
  172. "bidField": "",
  173. "publishTime": "1654704000-1657900799",
  174. "selectType": "title,content",
  175. "subtype": "",
  176. "exclusionWords": "",
  177. "buyer": "",
  178. "winner": "",
  179. "agency": "",
  180. "industry": "",
  181. "province": "",
  182. "city": "",
  183. "district": "",
  184. "buyerClass": "",
  185. "fileExists": "",
  186. "price": "",
  187. "buyerTel": "",
  188. "winnerTel": "",
  189. "mobileTag": [
  190. "军队类",
  191. "武警类",
  192. "融通类",
  193. "退役类",
  194. "融办类",
  195. "某某类",
  196. "all"
  197. ]
  198. }
  199. session = self.s
  200. response = session.post(url=url, headers=headers, params=params)
  201. self.printResponse(response)
  202. return response
  203. """三级页公告摘要"""
  204. #两个接口,
  205. def preagent(self):
  206. headers = {
  207. 'Referer': 'https://www.jianyu360.cn/nologin/content/ApGY1xdfTI4LyMsM3d4cE8JIzAvFj1jcXNlKwUkPT0dY2BwDidUCZM%3D.html'
  208. }
  209. s = GSTORE["s"]
  210. response = s.get(f"{cfg.target_host}/publicapply/detail/preAgent", headers=headers)
  211. response_data=json.loads(response.text)
  212. token=response_data["data"]["token"]
  213. return token
  214. def detail_baseinfo(self):
  215. headers = GSTORE['headers']
  216. s = GSTORE["s"]
  217. token=self.preagent()
  218. params = {
  219. "token":token
  220. }
  221. response = s.post(f"{cfg.target_host}/publicapply/detail/baseInfo", headers=headers, params=params)
  222. return response
  223. """三级页商机推荐"""
  224. def detail_advancedinfo(self):
  225. headers = GSTORE['headers']
  226. s = GSTORE["s"]
  227. res = self.detail_baseinfo()
  228. response_data = json.loads(res.text)
  229. token = response_data["data"]["token"]
  230. params = {
  231. "token": token
  232. }
  233. response = s.post(f"{cfg.target_host}/publicapply/detail/advancedInfo", headers=headers, params=params)
  234. return response
  235. #接口数据传值常用三种方式:urlencoded---params,键值对---data,json格式---json
  236. #获取推送记录接口
  237. def push_list(self):
  238. headers=GSTORE['headers']
  239. s = GSTORE['s']
  240. response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/fType/list",headers=headers,json=
  241. {"pageNum": 1, "pageSize": 50, "format": "table", "area": "", "selectTime": "all", "city": "", "buyerClass": "",
  242. "subtype": "", "industry": "", "keyWords": "", "fileExists": "", "price": "", "source": "", "exportNum": "",
  243. "vt": ""})
  244. return response
  245. # 不登录招标搜索
  246. def notloggedin_search(self, keyword='科技', publishtime='thisyear', selectType='content,title'):
  247. headers = GSTORE['headers']
  248. params={"keywords": keyword , "publishtime": publishtime, "timeslot": "", "area": "", "subtype": "",
  249. "minprice": "", "maxprice": "", "industry": "", "buyerclass": "", "buyertel": "", "winnertel": "",
  250. "selectType": selectType, "notkey": "", "fileExists": "0", "city": "", "searchGroup": "0",
  251. "searchMode": "0", "wordsMode": "0", "additionalWords": ""}
  252. response = requests.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, params=params)
  253. response.raise_for_status() # 如果请求失败,会抛出异常
  254. return response
  255. #不登录采购单位搜索
  256. def notloggedin_buysearch(self,keyword):
  257. headers = GSTORE['headers']
  258. s = GSTORE['s']
  259. data = {"buyerName":keyword,"province":[],"city":[],"buyerClass":[],"isCheckFollow":False,"isCheckReceive":False,"isContact":0,"pageSize":10,"pageNum":1}
  260. response =s.post(f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList", headers=headers, json=data)
  261. # response.raise_for_status() # 如果请求失败,会抛出异常
  262. return response
  263. #消息中心列表
  264. def get_messagelist(self):
  265. headers = GSTORE['headers']
  266. s = GSTORE['s']
  267. response=s.post(f"{cfg.target_host}/jyapi/messageCenter/MessageList",headers=headers,json=
  268. {"msgType":-1,"isRead":-1,"offset":1,"size":20})
  269. return response
  270. """用户中台"""
  271. def get_userCenter(self):
  272. hearders = GSTORE['headers']
  273. s = GSTORE['s']
  274. response = s.post(f"{cfg.target_host}/userCenter/workDesktop/menuInfo", headers=hearders)
  275. return response
  276. """我的订单"""
  277. def get_myOrder(self):
  278. hearders = GSTORE['headers']
  279. s = GSTORE['s']
  280. params = {
  281. "type": 0,
  282. "pageNum": 1,
  283. "fromPage": "pc",
  284. "page_size": 10
  285. }
  286. response = s.post(f"{cfg.target_host}/subscribepay/orderListDetails/myOrder", headers=hearders, params=params)
  287. return response
  288. """优惠卷"""
  289. def get_coupon(self):
  290. hearders = GSTORE['headers']
  291. s = GSTORE['s']
  292. params={
  293. "mold": 4,
  294. "currentPage": 1,
  295. "pageSize": 8,
  296. "platform": "P"
  297. }
  298. response= s.post(f"{cfg.target_host}/jyCoupon/getInfoByUser", headers=hearders,params=params)
  299. return response
  300. """数据自动导出"""
  301. def get_dataExport(self,publishtime=1672502400_1688951529,keyword='数据',selectType='title'):
  302. hearders = GSTORE['headers']
  303. s = GSTORE['s']
  304. params={
  305. "publishtime":publishtime,
  306. "area":"",
  307. "city":"",
  308. "region":"",
  309. "industry":"",
  310. "buyerclass":"",
  311. "keyword": [{"keyword":keyword,"appended":[],"exclude":[]}],
  312. "selectType":selectType,
  313. "minprice":"",
  314. "maxprice":"",
  315. "subtype":"",
  316. "buyer":"",
  317. "winner":"",
  318. "dataType": 2
  319. }
  320. response = s.post(f"{cfg.target_host}/front/dataExport/sieveData", headers=hearders, params=params)
  321. return response
  322. """数据导出记录"""
  323. def Export_recordList(self):
  324. hearders = GSTORE['headers']
  325. s = GSTORE['s']
  326. params={
  327. "pageNum": 0,
  328. "pageSize": 10
  329. }
  330. response = s.post(f"{cfg.target_host}/subscribepay/dataExportPack/recordList", headers=hearders, params=params)
  331. return response
  332. """剑鱼文库搜索"""
  333. def Library_search(self,keyWord='数据'):
  334. hearders = GSTORE['headers']
  335. s = GSTORE['s']
  336. params={
  337. "keyWord":keyWord,
  338. "tag":"",
  339. "sort": "tSort",
  340. "num": 1,
  341. "size": 10
  342. }
  343. response = s.post(f"{cfg.target_host}/jydocs/search", headers=hearders, params=params)
  344. return response
  345. """剑鱼文库收藏"""
  346. def Library_collection(self):
  347. hearders = GSTORE['headers']
  348. s = GSTORE['s']
  349. params={
  350. "sign": 1,
  351. "num": 1,
  352. "size": 10
  353. }
  354. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  355. return response
  356. """剑鱼文库我的文库"""
  357. def My_library(self):
  358. hearders = GSTORE['headers']
  359. s = GSTORE['s']
  360. params={
  361. "sign": 0,
  362. "num": 1,
  363. "size": 10
  364. }
  365. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  366. return response
  367. """项目进度监控"""
  368. def Project_monitoring(self):
  369. hearders = GSTORE['headers']
  370. s = GSTORE['s']
  371. params={
  372. "pageNum": 0,
  373. "pageSize": 500
  374. }
  375. response = s.post(f"{cfg.target_host}/bigmember/follow/project/list", headers=hearders, params=params)
  376. return response
  377. """企业情报监控"""
  378. def Enterprise_monitoring(self):
  379. hearders = GSTORE['headers']
  380. s = GSTORE['s']
  381. params={
  382. "pageNum": 0,
  383. "pageSize": 10,
  384. "match":"",
  385. "group":"",
  386. }
  387. response = s.post(f"{cfg.target_host}/bigmember/follow/ent/list", headers=hearders, params=params)
  388. return response
  389. """客户监控"""
  390. def Customer_monitoring(self,):
  391. hearders = GSTORE['headers']
  392. s = GSTORE['s']
  393. params = {
  394. "pagesize": 10,
  395. "pageno": 0,
  396. "keyword":""
  397. }
  398. response = s.post(f"{cfg.target_host}/publicapply/customer/list", headers=hearders, params=params)
  399. return response
  400. """标讯收藏"""
  401. def Message_Collection(self):
  402. hearders = GSTORE['headers']
  403. s = GSTORE['s']
  404. params={
  405. "buyerPhone":0,
  406. "buyerclass":"",
  407. "label":"",
  408. "pagenum":1,
  409. "pagesize":50,
  410. "selectTime":"",
  411. "winnerPhone":0
  412. }
  413. response = s.post(f"{cfg.target_host}/publicapply/bidcoll/list", headers=hearders, params=params)
  414. return response
  415. """标讯收藏"""
  416. #信息获取
  417. def Getuser(self):
  418. headers = GSTORE['headers']
  419. s = GSTORE['s']
  420. response = s.get(f"{cfg.target_host}/jypay/user/getAccountInfo", headers=headers)
  421. return response
  422. #密码校验
  423. def Check_password(self):
  424. headers = GSTORE['headers']
  425. s = GSTORE['s']
  426. params = {
  427. "password": "123456"
  428. }
  429. response = s.post(f"{cfg.target_host}/publicapply/password/check", headers=headers, params=params)
  430. return response
  431. #身份获取
  432. def Identity_list(self,n=0):
  433. headers = GSTORE['headers']
  434. s = GSTORE['s']
  435. params = {
  436. }
  437. response = s.post(f"{cfg.target_host}/publicapply/identity/list",headers=headers, params=params)
  438. # 解析响应内容为JSON
  439. response_json = response.json()
  440. # 从JSON响应中提取token
  441. self.token = response_json['data'][n]['token']
  442. return response
  443. def Identity_switch(self):
  444. headers = GSTORE["headers"]
  445. s = GSTORE["s"]
  446. params = {
  447. "token":self.token
  448. }
  449. response =s.post(f"{cfg.target_host}/publicapply/identity/switch", headers=self.headers,params=params)
  450. return response
  451. def User_info(self):
  452. headers = {
  453. 'content-Type': 'application/json',
  454. 'appId': '10000',
  455. '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'
  456. }
  457. s = GSTORE["s"]
  458. params = {}
  459. response =s.post(f"{cfg.target_host}/userCenter/ent/userInfo",headers=headers,params=params)
  460. return response
  461. def Whether_buy(self):
  462. headers = GSTORE["headers"]
  463. s = GSTORE["s"]
  464. response =s.get(f"{cfg.target_host}/entnicheNew/buy/whetherbuy",headers=headers)
  465. return response
  466. def Commonly_List(self):
  467. headers = {
  468. 'content-Type': 'application/json',
  469. 'appId': '10000',
  470. 'userid': '63a41aa5cd7ea10389b2a8f3'
  471. }
  472. s = GSTORE['s']
  473. response =s.post(f"{cfg.target_host}/userCenter/workDesktop/renew/commonlyList",headers=headers)
  474. return response
  475. def Authorised_info(self):
  476. headers = {
  477. "Content-Type":"application/json",
  478. "functionCode":"znsj_kf_use"
  479. }
  480. s = GSTORE['s']
  481. response =s.post(f"{cfg.target_host}/resourceCenter/waitEmpowerDetail",headers=headers)
  482. return response
  483. apimgr = APIMgr()