import json
import random
import string
import time
import pymysql
import requests
order_num = time.strftime("%Y%m%d%H%M%S", time.gmtime())
def GetToken(which_token):
url = 'http://api/user/login'
if which_token == 'tokenQiao':
date = {
"mobile": "1",
"pwd": "123456",
"type": "1"
}
elif which_token == 'token':
date = {
"mobile": "18",
"pwd": "123456",
"type": "1"
}
else:
date = {
"mobile": "133",
"pwd": "123456",
"type": "2"
}
token = requests.post(url, data=date).json()["data"]["token"]
print(token)
return token
def returnSku():
ran_sku = ['D0164911', 'D10000013', 'D01674208', 'D01674205', 'D01674202', 'D01674199', 'D01674200']
sku = random.choice(ran_sku)
return sku
def sqlSelect(needwhat):
global result_sku
db = pymysql.Connect(
host='234567',
port=3306,
user='yun',
password='yun123456',
db='test',
charset='utf8'
)
cur = db.cursor()
if needwhat == 'goods_sn':
result_sku = ()
while not result_sku:
sql = 'SELECT a.goods_sn,a.goods_name FROM goods a inner join bgoods b on a.goodsn = b.goodsn where a.class_code IS NOT NULL'
cur.execute(sql)
result_sku = cur.fetchall()
elif needwhat == 'order':
sql = "select orderid from order where order=%s"
cur.execute(sql, order_num)
result_sku = cur.fetchall()
elif needwhat == 'invoice':
sql = "select id from voice where ordersn=%s"
cur.execute(sql, order_num)
result_sku = cur.fetchall()
cur.close()
db.close()
print(result_sku)
return result_sku[0][0]
def ImportOrder():
ran_string = "".join(random.choice(string.ascii_uppercase) for _ in range(6))
ordertime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(ran_string + order_num)
token = GetToken('tokeniao')
session = requests.session()
headers = {"Content-Type": "application/json;charset=UTF-8", "token": token}
url = 'http://mn/importOrder'
attr = []
number = 0
productset = set()
while number < random.randint(3, 5):
productset.add(sqlSelect('goods_sn'))
number += 1
for goods in productset:
price = round(random.uniform(1, 10), 2)
Num = random.randint(1, 10)
attr.append({
"下单时间*": ordertime,
"订单号*": ran_string + order_num,
"订单号*": order_num,
"供应商sku*": goods,
"sku编码": ran_string,
"商品单价*": price,
"购买数量*": Num,
"商品总金额*": round(price * Num, 2),
})
print(attr)
date = json.dumps({"attr": attr})
response = session.post(url, data=date, headers=headers)
session.close()
print(response.json())
def Dan():
ImportOrder()
tokenao = GetToken('token')
session = requests.session()
headers = {"Content-Type": "application/json;charset=UTF-8", "token": tokenao}
url = 'http://patchOrder'
data = {"orderId": sqlSelect('orderId'), "Id": 1010232, "type": 1}
print(data)
response = session.post(url, data=json.dumps(data), headers=headers)
session.close()
print(response.json())
def GetGoodsInfo():
token = GetToken('ertoken')
session = requests.session()
headers = {"Content-Type": "application/json;charset=UTF-8", "token": token}
url = 'http://getGoodsInfo'
data = {"invoiceId": sqlSelect('invoiceId')}
print(data)
response = session.post(url, data=json.dumps(data), headers=headers).json()["data"]["not_invoiced_data"]
session.close()
return response
def KaiPiaoFenPi():
global productids
ProductCheckPass()
tokendw = GetToken('token')
session = requests.session()
headers = {"Content-Type": "application/json;charset=UTF-8", "token": token}
url = 'http://abc'
for productids in GetGoodsInfo():
print(productids['id'])
data = {"type": "0", "isMore": "2", "goods": productids['id']}
print(data)
response = session.post(url, data=json.dumps(data), headers=headers)
print(response.json())
session.close()
ProductCheckPass()
|