webapi.py 15 KB

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