forked from baskbuddy/zhangshun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.3 KiB
33 lines
1.3 KiB
import os, requests, time, pymysql
|
|
BASE = 'http://127.0.0.1:8080/api/v1'
|
|
conn = pymysql.connect(host=os.environ.get('DB_HOST', '127.0.0.1'),
|
|
port=int(os.environ.get('DB_PORT', '3307')),
|
|
user=os.environ.get('DB_USERNAME', 'mydreamjob'),
|
|
password=os.environ['DB_PASSWORD'],
|
|
database=os.environ.get('DB_NAME', 'mydreamjob'))
|
|
|
|
# Send SMS
|
|
r = requests.post(f'{BASE}/auth/sms/send', params={'phone': '13886593964', 'purpose': 'login'})
|
|
print(f'SMS send: {r.status_code}')
|
|
time.sleep(2)
|
|
|
|
# Get code
|
|
with conn.cursor() as c:
|
|
c.execute('SELECT code, created_at FROM sms_verification_codes WHERE phone=%s AND purpose=%s AND used=0 ORDER BY id DESC LIMIT 1', ('13886593964', 'login'))
|
|
row = c.fetchone()
|
|
code = row[0]
|
|
print(f'Code: {code}, created: {row[1]}')
|
|
|
|
# Login
|
|
r = requests.post(f'{BASE}/auth/login', json={'phone': '13886593964', 'code': code, 'purpose': 'login'})
|
|
print(f'Login: {r.status_code}')
|
|
if r.status_code == 200:
|
|
resp = r.json()
|
|
token = resp.get('data', {}).get('accessToken', '')
|
|
print(f'Role: {resp.get("data", {}).get("role", "N/A")}')
|
|
r = requests.get(f'{BASE}/companies/me', headers={'Authorization': f'Bearer {token}'})
|
|
print(f'Companies/me: {r.status_code} {r.text[:200]}')
|
|
else:
|
|
print(f'Error: {r.text[:200]}')
|
|
|
|
conn.close()
|
|
|