wxapi.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. 'Accept-Charset':'utf-8',
  38. 'Accept':'*/*',
  39. 'Accept-Encoding':'gzip, deflate, br',
  40. 'User-Agent':'Apifox/1.0.0 (https://apifox.com)',
  41. 'Content-Type':'application/json',
  42. 'MiniprogramCode':'wy_zbxm'
  43. }
  44. #headers设置为全局变量
  45. GSTORE['headers'] = headers
  46. # session对象设置为全局变量
  47. s = requests.Session()
  48. GSTORE['s'] = s
  49. # 小程序登录接口
  50. def mgr_login_wxapi(self, useproxies=False):
  51. headers=GSTORE['headers']
  52. s = GSTORE['s']
  53. if useproxies:
  54. self.s.proxies.update({'http':'127.0.0.1:8888'})
  55. response = self.s.post(f"{cfg.target_host_wxapi}/debrisproduct/free/autologin",headers=headers,json=
  56. {
  57. 'phone':'15037870765',
  58. 'token':'8817684142977367381'
  59. })
  60. self.printResponse(response)
  61. # 把response对象返回出去
  62. return response
  63. """退出登录小程序"""
  64. def mgr_logout_wxapi(self):
  65. url = f"{cfg.target_host_wxapi}/debrisproduct/logout"
  66. headers = GSTORE['headers']
  67. s = GSTORE['s']
  68. s.post(url=url, headers=headers)
  69. """我的用户信息"""
  70. def myuser_information(self):
  71. hearders = GSTORE['headers']
  72. s = GSTORE['s']
  73. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/myinfo", headers=hearders)
  74. return response
  75. """招标项目搜索-搜索入口"""
  76. def bidding_project_search(self):
  77. hearders = GSTORE['headers']
  78. s = GSTORE['s']
  79. json={
  80. "area": "河南",
  81. "propertyForm": "医院",
  82. "OwnerType": "医疗单位",
  83. "Page": 1,
  84. "PageSize": 1,
  85. "KeyWords": "物业"
  86. }
  87. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/bidList", headers=hearders, json=json)
  88. return response
  89. """采购意向搜索-搜索入口"""
  90. def purchase_intention_search(self):
  91. hearders = GSTORE['headers']
  92. s = GSTORE['s']
  93. json={
  94. "area": "安徽",
  95. "propertyForm": "学校",
  96. "OwnerType": "教育单位",
  97. "Page": 1,
  98. "PageSize": 1,
  99. "KeyWords": "数据"
  100. }
  101. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/buyPurposeList", headers=hearders, json=json)
  102. return response
  103. """招标项目搜索-订阅入口"""
  104. def tender_subscription(self):
  105. hearders = GSTORE['headers']
  106. s = GSTORE['s']
  107. json={
  108. "area": "河南",
  109. "propertyForm": "医院",
  110. "OwnerType": "医疗单位",
  111. "Page": 1,
  112. "PageSize": 1,
  113. "KeyWords": "物业"
  114. }
  115. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/bidSubscribeList", headers=hearders, json=json)
  116. return response
  117. """采购意向搜索-订阅入口"""
  118. def purchase_intention_subscription(self):
  119. hearders = GSTORE['headers']
  120. s = GSTORE['s']
  121. json={
  122. "area": "安徽",
  123. "propertyForm": "学校",
  124. "OwnerType": "教育单位",
  125. "Page": 1,
  126. "PageSize": 1,
  127. "KeyWords": "数据"
  128. }
  129. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/search/buyPurposeSubscribeList", headers=hearders, json=json)
  130. return response
  131. """情报热词"""
  132. def information_buzzword(self):
  133. hearders = GSTORE['headers']
  134. s = GSTORE['s']
  135. response = s.get(f"{cfg.target_host_wxapi}/debrisproduct/info/getHotInfo", headers=hearders)
  136. return response
  137. """情报列表/搜索-搜索"""
  138. def information_search(self):
  139. hearders = GSTORE['headers']
  140. s = GSTORE['s']
  141. json={
  142. "page_size": 1,
  143. "page_num": 1,
  144. "keyWords": "科技"
  145. }
  146. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/info/getInfoList", headers=hearders, json=json)
  147. return response
  148. """情报列表/搜索-订阅"""
  149. def information_subscription(self):
  150. hearders = GSTORE['headers']
  151. s = GSTORE['s']
  152. json={
  153. "page_size": 1,
  154. "page_num": 1,
  155. "keyWords": "科技"
  156. }
  157. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/info/subscribeList", headers=hearders, json=json)
  158. return response
  159. """监控列表"""
  160. def monitor_list(self):
  161. hearders = GSTORE['headers']
  162. s = GSTORE['s']
  163. json={
  164. "Size": 1,
  165. "Page": 1
  166. }
  167. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/monitorList", headers=hearders, json=json)
  168. return response
  169. """监控操作"""
  170. def monitor_operate(self):
  171. hearders = GSTORE['headers']
  172. s = GSTORE['s']
  173. json={
  174. "CompanyName":"东莞市中医院",
  175. "OperateType":1
  176. }
  177. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/monitorOperate", headers=hearders, json=json)
  178. return response
  179. """详情页信息"""
  180. def detailed_information(self):
  181. hearders = GSTORE['headers']
  182. s = GSTORE['s']
  183. json = {
  184. "_id": "ABCY1xZcDIvJyssAlV1cHU8CicoEjRjYWR1Pw4jIy4wc3xzfTNUCec%3D"
  185. }
  186. response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/getBiddingDetail", headers=hearders, json=json)
  187. return response
  188. #获取订单详情
  189. def debrisproduct_orderDetail(self, orderCode):
  190. headers = GSTORE['headers']
  191. s = GSTORE['s'] # 从全局变量中获取 cookie
  192. INFO(f"使用的 cookies: {s}") # 打印 cookie,确保它正确
  193. response = s.post(
  194. f"{cfg.target_host_wxapi}/debrisproduct/orderDetail",
  195. headers=headers,
  196. data={"orderCode": orderCode}
  197. )
  198. return response
  199. #获取订单列表
  200. def debrisproduct_orderList(self, orderCode):
  201. headers = GSTORE['headers']
  202. s = GSTORE['s'] # 从全局变量中获取 cookie
  203. INFO(f"使用的 cookies: {s}") # 打印 cookie,确保它正确
  204. response = s.post(
  205. f"{cfg.target_host_wxapi}/debrisproduct/orderList",
  206. headers=headers,
  207. data={"orderCode": orderCode}
  208. )
  209. apimgr = APIMgr()