123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import json
- import requests
- from hytest.common import *
- from cfg import cfg
- from bs4 import BeautifulSoup
- from requests.packages import urllib3
- #存放公用方法
- # 存储 全局共享 数据
- GSTORE = {}
- class APIMgr():
- #打印https请求与消息
- def __init__(self):
- self.ui = None
- self.token = None
- def printRequest(self,req):
- if req.body==None:
- msgBody=''
- else:
- msgBody=req.body
- self.ui.outputWindow.append(
- '{}\n{}\n{}\n\n{}'.format(
- '\n\n-------发送请求--------',
- req.method+''+req.url,
- '\n'.join('{}:{}'.format(k,v) for k,v in req.headers.items()),
- msgBody,
- ))
- # 打印http相应消息的函数
- def printResponse(self, response):
- print('\n\n----- https response begin -----')
- print(response.status_code)
- # print(response.headers)
- for k, v in response.headers.items():
- print(f'{k}:{v}')
- print(response.content.decode('utf8'))
- print('----- https response end-----\n\n')
- headers = {
- 'Accept-Charset':'utf-8',
- 'Accept':'*/*',
- 'Accept-Encoding':'gzip, deflate, br',
- 'User-Agent':'Apifox/1.0.0 (https://apifox.com)',
- 'Content-Type':'application/json',
- 'MiniprogramCode':'wy_zbxm'
- }
- #headers设置为全局变量
- GSTORE['headers'] = headers
- # session对象设置为全局变量
- s = requests.Session()
- GSTORE['s'] = s
- # 小程序登录接口
- def mgr_login_wxapi(self, useproxies=False):
- headers=GSTORE['headers']
- s = GSTORE['s']
- if useproxies:
- self.s.proxies.update({'http':'127.0.0.1:8888'})
- response = self.s.post(f"{cfg.target_host_wxapi}/debrisproduct/free/autologin",headers=headers,json=
- {
- 'phone':'15037870765',
- 'token':'8817684142977367381'
- })
- self.printResponse(response)
- # 把response对象返回出去
- return response
- """退出登录小程序"""
- def mgr_logout_wxapi(self):
- url = f"{cfg.target_host_wxapi}/debrisproduct/logout"
- headers = GSTORE['headers']
- s = GSTORE['s']
- s.post(url=url, headers=headers)
- """我的用户信息"""
- def myuser_information(self):
- hearders = GSTORE['headers']
- s = GSTORE['s']
- response = s.post(f"{cfg.target_host_wxapi}/debrisproduct/myinfo", headers=hearders)
- return response
- apimgr = APIMgr()
|