# -*- coding: utf-8 -*-
import MySQLdb
import random,re,requests
import Login.postlogin
from Login.postlogin import login
# def add_friend():
''' 注册200个账号加两百个好友'''
for i in range(200):
print i
''' 生成手机号'''
# 第二位数字
second = [3, 5, 8][random.randint(0, 2)]
# 第三位数字
third = {
3: random.randint(0, 9),
# 4: [5, 7, 9][random.randint(0, 2)],
5: [i for i in range(10) if i != 4][random.randint(0, 8)],
# 7: [i for i in range(10) if i not in [4, 9]][random.randint(0, 7)],
8: random.randint(0, 9),
}[second]
# 最后八位数字
suffix = "".join(random.choice("0123456789") for i in range(8))
# 拼接手机号
phone = "1{}{}{}".format(second, third, suffix)
print(phone)
''' 获取手机验证码'''
body= {
'phone':"",
'app_type': "android",
'version_name': "1.2.0"
}
body['phone'] = phone
print bady
headers = {
'content-type': "application/x-www-form-urlencoded",
'Authorization': "Bearer cZtOCr1kehUkMdS6ZTpiEe88a4amEfsCkujejBXPTknfSEJx3WvS."
}
r = requests.request('POST', url=Login.postlogin.urls + "/sec/send-sms", data=body, headers=headers)
# assert 200 == r.status_code
print r.text.decode('unicode-escape')
print r.status_code
print u'获取验证码'
''' 查询手机号验证码'''
db = MySQLdb.connect('250.250.250.251', 'dlm_test', 'abcabc', 'dataname')
cursor = db.cursor()
cursor.execute("select sms_code FROM fb_sms_code WHERE mobile = '"+phone+"' ORDER BY id DESC LIMIT 1;")
data = cursor.fetchone()
p_code = '%s' % data
print p_code
''' 登录账号'''
body1= {
'phone': "",
'code': ""
}
body1['phone'] = phone
body1['code'] = p_code
r = requests.request('POST', url=Login.postlogin.urls + '/sec/log', data=body1, headers=headers)
assert 200 == r.status_code
print r.status_code
print r.text.decode('unicode-escape')
''' 查询用户id用户添加好友'''
db = MySQLdb.connect('250.250.250.251', 'dlm_test', 'abcabc', 'dataname')
cursor = db.cursor()
cursor.execute("select id from dataname_user where mobile = '"+phone+"'")
data1 = cursor.fetchone()
userid = '%s' % data1
print type(userid)
''' 增加好友'''
db = MySQLdb.connect('250.250.250.251', 'dlm_test', 'abcabc', 'dataname')
cursor = db.cursor()
cursor.execute("INSERT INTO dataname_user_follow(user_id, fans_id, is_eachother, addtime)VALUES("+userid+",'6539', '1','1541669152')")
db.commit()
python 接口测试查询数据库
于 2018-11-12 22:28:56 首次发布