webapi.py 16 KB

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