Commit 4e060829 by haojie

Initial commit

parent 07b88604
......@@ -3,4 +3,5 @@
/test.py
/callback.py
/.idea
/__pycache__
\ No newline at end of file
/__pycache__
/config/env.py
\ No newline at end of file
......@@ -7,8 +7,9 @@ from fake_useragent import UserAgent
from aredis import StrictRedis, ConnectionPool
from web3 import Web3
from web3.eth import AsyncEth
from config.env import redis_password, redis_host
uni256Max = 2**256
uni256Max = 2 ** 256
class RedisConnSingleton(object):
......@@ -22,7 +23,8 @@ class RedisConnSingleton(object):
:param kwargs:
"""
if cls._instance is None:
cls._instance = redis.ConnectionPool(max_connections=1000, host='127.0.0.1', port=6379, db=0, password='12345678')
cls._instance = redis.ConnectionPool(max_connections=1000, host=redis_host, port=6379, db=0,
password=redis_password)
return cls._instance
......@@ -37,7 +39,8 @@ class RedisConnectionPoolSingleton(object):
:param kwargs:
"""
if cls._instance is None:
cls._instance = ConnectionPool(max_connections=1000, host='127.0.0.1', port=6379, db=0, password='12345678')
cls._instance = ConnectionPool(max_connections=1000, host=redis_host, port=6379, db=0,
password=redis_password)
return cls._instance
......@@ -181,13 +184,15 @@ class RedisCon:
class Helper:
"""公共基础类"""
@staticmethod
def getProxyLst():
"""获取代理列表"""
proxy_lst = list()
for i in range(5):
try:
response = requests.get("https://proxy.webshare.io/api/v2/proxy/list/download/pgewrawzvvqtzwdzjfdfswvkwcjasmofoucnfyyq/-/any/username/direct/-/").text
response = requests.get(
"https://proxy.webshare.io/api/v2/proxy/list/download/pgewrawzvvqtzwdzjfdfswvkwcjasmofoucnfyyq/-/any/username/direct/-/").text
a = response.split('\r\n')
proxy_lst = a[:-1]
proxy_lst = list(map(lambda x: x.split(":"), proxy_lst))
......@@ -309,10 +314,10 @@ class Helper:
@staticmethod
def getWeb3Eth():
eth_list = ["https://eth-mainnet.g.alchemy.com/v2/fH-3go199OKvbKSovc84gAC6xa5Givlb",
"https://eth-mainnet.g.alchemy.com/v2/V3-I2bBqYoA_DfOZrhaWx-t4-6LTZawj",
"https://eth-mainnet.g.alchemy.com/v2/D2l8IHN-2UUYcZpzXDY5FvZlcDF7eb0Q",
"https://eth-mainnet.g.alchemy.com/v2/tvHBgnSsj41XjKC9Rqv_Hl-rQJ-VupbD",
"https://eth-mainnet.g.alchemy.com/v2/6nk8lAti4uVJ6WnqadrrPsx2mUxYM8rW"]
"https://eth-mainnet.g.alchemy.com/v2/V3-I2bBqYoA_DfOZrhaWx-t4-6LTZawj",
"https://eth-mainnet.g.alchemy.com/v2/D2l8IHN-2UUYcZpzXDY5FvZlcDF7eb0Q",
"https://eth-mainnet.g.alchemy.com/v2/tvHBgnSsj41XjKC9Rqv_Hl-rQJ-VupbD",
"https://eth-mainnet.g.alchemy.com/v2/6nk8lAti4uVJ6WnqadrrPsx2mUxYM8rW"]
eth = eth_list[0]
# proxy = Helper.aiohttp_proxy_pool()
# request_kwargs={"proxy": proxy}
......
# 登录接口
login_api = ''
# 用户名密码
login_params = ''
# 获取任务接口
task_api = ''
# redis
redis_host = '127.0.0.1'
redis_password = ''
......@@ -68,7 +68,7 @@ async def rechargeList(web3, data):
# json转list
result = json.loads(result)
# 检测5次
for i in range(0, 5):
for i in range(5):
for item in result:
# 判断是否存在
if item['transaction_hash'] == inscription_hash:
......
import asyncio
import json
import time
import traceback
import requests
from Helper import RedisCon, Helper
import logging
from config.env import login_params, login_api, task_api
logging.basicConfig(level=logging.ERROR, filename='recharge_error.log', datefmt='%Y/%m/%d %H:%M:%S',
format='%(asctime)s - %(name)s - %(levelname)s - %(lineno)d - %(module)s - %(message)s')
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.DEBUG)
# 登录的token
login_token = ''
def login():
res = requests.post(login_api, data=login_params).text
res = json.loads(res)
if res['code'] == 0:
login_token = res['data']['access_token']
return True
# 获取任务
def get_admin_task():
res = requests.get(task_api, headers={
'authorization': 'Bearer ' + login_token,
}).text
res = json.loads(res)
if res['code'] == 0:
return res['data']
def pay_order_status(status, url, data):
header = {
'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
'authorization': 'Bearer ' + login_token,
}
data['status'] = status
print('准备回调', data)
result = requests.post(url, headers=header, data=data)
print(result)
# if result.text == 'success':
# print("请求成功!")
# else:
# print("请求失败!")
logger.debug(f">>>>tx_hash:{data['hash']} status:{status} url:{url}"
f" 请求状态码:{result.status_code}")
async def rechargeList(web3, data):
url = data['notify_url']
to_address = data['to']
from_address = data['from']
# 交易类型
tran_type = data['type']
status = 3 # 默认转账失败
print(data)
try:
if tran_type == 1:
# 铭文转移
pass
elif tran_type == 2:
# 转账
pass
pay_order_status(status, url, data)
except Exception as e:
print(e)
def main():
while True:
tasks = list()
loop = asyncio.get_event_loop()
for i in range(5):
# 获取任务
task = get_admin_task()
if task:
web3 = Helper.getWeb3Eth()
task = json.loads(task)
# task
tasks.append(rechargeList(web3, task))
loop.run_until_complete((asyncio.wait(tasks, timeout=30)))
if __name__ == '__main__':
if not login_token:
login_status = login()
print(login_status)
if login_status:
# 可以执行
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment