Skip to content

Instantly share code, notes, and snippets.

@wengxt
Forked from kanrourou/bh3_spring_festival_buy.py
Last active April 30, 2018 19:15
Show Gist options
  • Save wengxt/6596aafe9b272cc5e1403a2698484af4 to your computer and use it in GitHub Desktop.
Save wengxt/6596aafe9b272cc5e1403a2698484af4 to your computer and use it in GitHub Desktop.
# coding: utf-8
import requests
import json
import time
import sys
import random
from threading import Thread
#输入你对应的authkey和sign
auth_key = ''
sign = ''
def send_request(product, price):
url = 'https://event.bh3.com/bh3_2018spring_festival/trade.php?auth_key={}&sign={}&action=1&type={}&price={}&quantity=1'.format(auth_key,sign,product, price)
payload = {
":authority":"event.bh3.com",
":method":"POST",
":path":"/bh3_2018spring_festival/trade.php",
":scheme":"https",
"accept":"application/json, text/plain, */*",
"accept-encoding":"gzip, deflate, br",
"accept-language":"en-US,en;q=0.9,ja;q=0.8,zh-CN;q=0.7,zh;q=0.6,zh-TW;q=0.5",
"content-length":"331",
"content-type":"application/x-www-form-urlencoded;charset=UTF-8",
"cookie":"SERVERID=bfa9a576a9b19ad83868f88df69b6b84|1518345457|1518343892",
"origin":"https://event.bh3.com",
"referer":"https://event.bh3.com/bh3_2018spring_festival/index.html?sign={}&auth_key={}".format(sign, auth_key),
"user-agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36"
}
headers = {}
response = requests.post(url, data=json.dumps(payload), headers=headers)
ret = response.json();
if ret['retcode'] == 0:
print('Congratulation!{} bought at price {}'.format(product,price))
elif ret['retcode'] == 1 and ret['msg'] == u'抱歉,在售商品数量不足':
return
elif ret['msg'] == u'抱歉,您的代币不足':
print('Having trouble to purchase {} at price {}, will try it again, error message: '.format(product, price) + ret['msg']);
else:
print('Failed to purchase {} at price {}, current thread will be terminated, error message: '.format(product,price) + ret['msg'])
sys.exit();
def buy(product, price):
while True:
send_request(product, price)
#设置你的delay
n = random.randint(1,3)
print('No available {} to buy at price {}, will try again in {} seconds...'.format(product,price,n))
time.sleep(n)
#在这里配置你要买的物品和价格
products = {'cake':[100], 'firecracker':[100,200,300,400,500,600], 'chipao':[100,200,300], 'couplets':[100], 'papercut':[100,200,300,400,500,600]}
for key in products:
for price in products[key]:
thread = Thread(target = buy, args = (key,price,))
thread.start()
@Mingz6
Copy link

Mingz6 commented Apr 30, 2018

漂亮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment