webapi.py 19 KB

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