webapi.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. #接口数据传值常用三种方式:urlencoded---params,键值对---data,json格式---json
  224. #获取推送记录接口
  225. def push_list(self):
  226. headers=GSTORE['headers']
  227. s = GSTORE['s']
  228. response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/fType/list",headers=headers,json=
  229. {"pageNum": 1, "pageSize": 50, "format": "table", "area": "", "selectTime": "all", "city": "", "buyerClass": "",
  230. "subtype": "", "industry": "", "keyWords": "", "fileExists": "", "price": "", "source": "", "exportNum": "",
  231. "vt": ""})
  232. return response
  233. # 不登录招标搜索
  234. def notloggedin_search(self, keyword='科技', publishtime='thisyear', selectType='content,title'):
  235. headers = GSTORE['headers']
  236. params={"keywords": keyword , "publishtime": publishtime, "timeslot": "", "area": "", "subtype": "",
  237. "minprice": "", "maxprice": "", "industry": "", "buyerclass": "", "buyertel": "", "winnertel": "",
  238. "selectType": selectType, "notkey": "", "fileExists": "0", "city": "", "searchGroup": "0",
  239. "searchMode": "0", "wordsMode": "0", "additionalWords": ""}
  240. response = requests.post(f"{cfg.target_host}/jylab/supsearch/index.html", headers=headers, params=params)
  241. response.raise_for_status() # 如果请求失败,会抛出异常
  242. return response
  243. #不登录采购单位搜索
  244. def notloggedin_buysearch(self,keyword):
  245. headers = GSTORE['headers']
  246. s = GSTORE['s']
  247. data = {"buyerName":keyword,"province":[],"city":[],"buyerClass":[],"isCheckFollow":False,"isCheckReceive":False,"isContact":0,"pageSize":10,"pageNum":1}
  248. response =s.post(f"{cfg.target_host}/jyapi/jybx/buyer/eType/buyerList", headers=headers, json=data)
  249. # response.raise_for_status() # 如果请求失败,会抛出异常
  250. return response
  251. #消息中心列表
  252. def get_messagelist(self):
  253. headers = GSTORE['headers']
  254. s = GSTORE['s']
  255. response=s.post(f"{cfg.target_host}/jyapi/messageCenter/MessageList",headers=headers,json=
  256. {"msgType":-1,"isRead":-1,"offset":1,"size":20})
  257. return response
  258. """用户中台"""
  259. def get_userCenter(self):
  260. hearders = GSTORE['headers']
  261. s = GSTORE['s']
  262. response = s.post(f"{cfg.target_host}/userCenter/workDesktop/menuInfo", headers=hearders)
  263. return response
  264. """我的订单"""
  265. def get_myOrder(self):
  266. hearders = GSTORE['headers']
  267. s = GSTORE['s']
  268. params = {
  269. "type": 0,
  270. "pageNum": 1,
  271. "fromPage": "pc",
  272. "page_size": 10
  273. }
  274. response = s.post(f"{cfg.target_host}/subscribepay/orderListDetails/myOrder", headers=hearders, params=params)
  275. return response
  276. """优惠卷"""
  277. def get_coupon(self):
  278. hearders = GSTORE['headers']
  279. s = GSTORE['s']
  280. params={
  281. "mold": 4,
  282. "currentPage": 1,
  283. "pageSize": 8,
  284. "platform": "P"
  285. }
  286. response= s.post(f"{cfg.target_host}/jyCoupon/getInfoByUser", headers=hearders,params=params)
  287. return response
  288. """数据自动导出"""
  289. def get_dataExport(self,publishtime=1672502400_1688951529,keyword='数据',selectType='title'):
  290. hearders = GSTORE['headers']
  291. s = GSTORE['s']
  292. params={
  293. "publishtime":publishtime,
  294. "area":"",
  295. "city":"",
  296. "region":"",
  297. "industry":"",
  298. "buyerclass":"",
  299. "keyword": [{"keyword":keyword,"appended":[],"exclude":[]}],
  300. "selectType":selectType,
  301. "minprice":"",
  302. "maxprice":"",
  303. "subtype":"",
  304. "buyer":"",
  305. "winner":"",
  306. "dataType": 2
  307. }
  308. response = s.post(f"{cfg.target_host}/front/dataExport/sieveData", headers=hearders, params=params)
  309. return response
  310. """数据导出记录"""
  311. def Export_recordList(self):
  312. hearders = GSTORE['headers']
  313. s = GSTORE['s']
  314. params={
  315. "pageNum": 0,
  316. "pageSize": 10
  317. }
  318. response = s.post(f"{cfg.target_host}/subscribepay/dataExportPack/recordList", headers=hearders, params=params)
  319. return response
  320. """剑鱼文库搜索"""
  321. def Library_search(self,keyWord='数据'):
  322. hearders = GSTORE['headers']
  323. s = GSTORE['s']
  324. params={
  325. "keyWord":keyWord,
  326. "tag":"",
  327. "sort": "tSort",
  328. "num": 1,
  329. "size": 10
  330. }
  331. response = s.post(f"{cfg.target_host}/jydocs/search", headers=hearders, params=params)
  332. return response
  333. """剑鱼文库收藏"""
  334. def Library_collection(self):
  335. hearders = GSTORE['headers']
  336. s = GSTORE['s']
  337. params={
  338. "sign": 1,
  339. "num": 1,
  340. "size": 10
  341. }
  342. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  343. return response
  344. """剑鱼文库我的文库"""
  345. def My_library(self):
  346. hearders = GSTORE['headers']
  347. s = GSTORE['s']
  348. params={
  349. "sign": 0,
  350. "num": 1,
  351. "size": 10
  352. }
  353. response = s.post(f"{cfg.target_host}/jydocs/user/list", headers=hearders, params=params)
  354. return response
  355. """项目进度监控"""
  356. def Project_monitoring(self):
  357. hearders = GSTORE['headers']
  358. s = GSTORE['s']
  359. params={
  360. "pageNum": 0,
  361. "pageSize": 500
  362. }
  363. response = s.post(f"{cfg.target_host}/bigmember/follow/project/list", headers=hearders, params=params)
  364. return response
  365. """企业情报监控"""
  366. def Enterprise_monitoring(self):
  367. hearders = GSTORE['headers']
  368. s = GSTORE['s']
  369. params={
  370. "pageNum": 0,
  371. "pageSize": 10,
  372. "match":"",
  373. "group":"",
  374. }
  375. response = s.post(f"{cfg.target_host}/bigmember/follow/ent/list", headers=hearders, params=params)
  376. return response
  377. """客户监控"""
  378. def Customer_monitoring(self,):
  379. hearders = GSTORE['headers']
  380. s = GSTORE['s']
  381. params = {
  382. "pagesize": 10,
  383. "pageno": 0,
  384. "keyword":""
  385. }
  386. response = s.post(f"{cfg.target_host}/publicapply/customer/list", headers=hearders, params=params)
  387. return response
  388. """标讯收藏"""
  389. def Message_Collection(self):
  390. hearders = GSTORE['headers']
  391. s = GSTORE['s']
  392. params={
  393. "buyerPhone":0,
  394. "buyerclass":"",
  395. "label":"",
  396. "pagenum":1,
  397. "pagesize":50,
  398. "selectTime":"",
  399. "winnerPhone":0
  400. }
  401. response = s.post(f"{cfg.target_host}/publicapply/bidcoll/list", headers=hearders, params=params)
  402. return response
  403. """标讯收藏"""
  404. #信息获取
  405. def Getuser(self):
  406. headers = GSTORE['headers']
  407. s = GSTORE['s']
  408. response = s.get(f"{cfg.target_host}/jypay/user/getAccountInfo", headers=headers)
  409. return response
  410. #密码校验
  411. def Check_password(self):
  412. headers = GSTORE['headers']
  413. s = GSTORE['s']
  414. params = {
  415. "password": "123456"
  416. }
  417. response = s.post(f"{cfg.target_host}/publicapply/password/check", headers=headers, params=params)
  418. return response
  419. #身份获取
  420. def Identity_list(self,n=0):
  421. headers = GSTORE['headers']
  422. s = GSTORE['s']
  423. params = {
  424. }
  425. response = s.post(f"{cfg.target_host}/publicapply/identity/list",headers=headers, params=params)
  426. # 解析响应内容为JSON
  427. response_json = response.json()
  428. # 从JSON响应中提取token
  429. self.token = response_json['data'][n]['token']
  430. return response
  431. def Identity_switch(self):
  432. headers = GSTORE["headers"]
  433. s = GSTORE["s"]
  434. params = {
  435. "token":self.token
  436. }
  437. response =s.post(f"{cfg.target_host}/publicapply/identity/switch", headers=self.headers,params=params)
  438. return response
  439. def User_info(self):
  440. headers = {
  441. 'content-Type': 'application/json',
  442. 'appId': '10000',
  443. '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'
  444. }
  445. s = GSTORE["s"]
  446. params = {}
  447. response =s.post(f"{cfg.target_host}/userCenter/ent/userInfo",headers=headers,params=params)
  448. return response
  449. def Whether_buy(self):
  450. headers = GSTORE["headers"]
  451. s = GSTORE["s"]
  452. response =s.get(f"{cfg.target_host}/entnicheNew/buy/whetherbuy",headers=headers)
  453. return response
  454. def Commonly_List(self):
  455. headers = {
  456. 'content-Type': 'application/json',
  457. 'appId': '10000',
  458. 'userid': '63a41aa5cd7ea10389b2a8f3'
  459. }
  460. s = GSTORE['s']
  461. response =s.post(f"{cfg.target_host}/userCenter/workDesktop/renew/commonlyList",headers=headers)
  462. return response
  463. def Authorised_info(self):
  464. headers = {
  465. "Content-Type":"application/json",
  466. "functionCode":"znsj_kf_use"
  467. }
  468. s = GSTORE['s']
  469. response =s.post(f"{cfg.target_host}/resourceCenter/waitEmpowerDetail",headers=headers)
  470. return response
  471. """大会员推送记录列表"""
  472. def bigmember_push(self):
  473. headers = GSTORE['headers']
  474. s = GSTORE['s']
  475. response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/mType/list", headers=headers, json=
  476. {
  477. "pageNum": 1,
  478. "pageSize": 50,
  479. "format": "table",
  480. "area": "",
  481. "selectTime": "all",
  482. "city": "",
  483. "buyerClass": "",
  484. "subtype": "",
  485. "industry": "",
  486. "keyWords": "",
  487. "fileExists": "",
  488. "price": "",
  489. "source": "",
  490. "exportNum": "",
  491. "district": "",
  492. "isRead": "",
  493. "vt": "m"
  494. })
  495. return response
  496. """商机管理推送记录列表"""
  497. def entniche_push(self):
  498. headers = GSTORE['headers']
  499. s = GSTORE['s']
  500. response = self.s.post(f"{cfg.target_host}/jyapi/jybx/subscribe/eType/list", headers=headers, json=
  501. {
  502. "pageNum": 1,
  503. "pageSize": 50,
  504. "format": "table",
  505. "area": "",
  506. "selectTime": "all",
  507. "city": "",
  508. "buyerClass": "",
  509. "subtype": "",
  510. "industry": "",
  511. "keyWords": "",
  512. "fileExists": "",
  513. "price": "",
  514. "source": "",
  515. "exportNum": "",
  516. "district": "",
  517. "isRead": "",
  518. "vt": "s"
  519. })
  520. return response
  521. apimgr = APIMgr()