加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 5.29 KB
一键复制 编辑 原始数据 按行查看 历史
"""
主程序类
@author : lcry
@time : 2022/9/15 12:00
"""
import json
import random
import sys
import time
import requests
import config
map_api = "https://cat-match.easygame2021.com/sheep/v1/game/map_info?map_id=%s"
# 完成羊群接口
finish_sheep_api = "https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=1&rank_time=%s&rank_role=1&skin=%s"
# 完成话题接口
finish_topic_api = "https://cat-match.easygame2021.com/sheep/v1/game/topic_game_over?rank_score=1&rank_state=1&rank_time=%s&rank_role=2&skin=%s"
header_t = config.get("header_t")
header_user_agent = config.get("header_user_agent")
cost_time = config.get("cost_time")
cycle_count = config.get("cycle_count")
sheep_type = config.get("sheep_type")
topic_type = config.get("topic_type")
"""
调用完成闯关羊群
Parameters:
cost_time - 耗时
"""
def finish_game_sheep(skin, rank_time):
s = requests.session()
s.keep_alive = False
res = requests.get(finish_sheep_api % (rank_time, skin), headers=request_header, timeout=10, verify=True)
# err_code为0则成功
if res.json()["err_code"] == 0:
print("\033[1;36m恭喜你! 本次闯关羊群状态成功\033[0m")
else:
print(res.json())
print("请检查t的值是否获取正确!")
"""
调用完成闯关话题
Parameters:
cost_time - 耗时
"""
def finish_game_topic(skin, rank_time):
s = requests.session()
s.keep_alive = False
res = requests.get(finish_topic_api % (rank_time, skin), headers=request_header, timeout=10, verify=True)
# err_code为0则成功
if res.json()["err_code"] == 0:
print("\033[1;36m恭喜你! 本次闯关话题状态成功\033[0m")
else:
print(res.json())
print("请检查t的值是否获取正确!")
"""
获取token
"""
def get_token():
get_wx_open_id_url = f"https://cat-match.easygame2021.com/sheep/v1/game/user_info?uid={uid}"
get_token_url = "https://cat-match.easygame2021.com/sheep/v1/user/login_oppo"
request_header = {
"Host": "cat-match.easygame2021.com",
"User-Agent": header_user_agent,
"t": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTAwMjA0MDIsIm5iZiI6MTY1ODkxODIwMiwiaWF0IjoxNjU4OTE2NDAyLCJqdGkiOiJDTTpjYXRfbWF0Y2g6bHQxMjM0NTYiLCJvcGVuX2lkIjoiIiwidWlkIjoxMDAwMDEsImRlYnVnIjoiIiwibGFuZyI6IiJ9.NQZAWBLYtq6hBff9YjNcaI2Soa6Z5vwbIU7YnjP1KBQ",
"Referer": "https://servicewechat.com/wx141bfb9b73c970a9/17/page-frame.html",
"Accept-Encoding": "gzip,compress,br,deflate",
"Connection": "close"
}
res = requests.get(get_wx_open_id_url, headers=request_header, timeout=10, verify=False)
if res.status_code == 200:
res_json = res.json()
wx_open_id = res_json['data']['wx_open_id']
nick_name = res_json['data']['nick_name']
avatar = res_json['data']['avatar']
if wx_open_id:
print("获取 wx_open_id 成功")
data = {
"uid": wx_open_id,
"nick_name": nick_name,
"avatar": avatar,
"sex": 1
}
token_res = requests.post(get_token_url, data=data, verify=False, timeout=10)
if token_res.status_code == 200:
token_res_json = token_res.json()
token = token_res_json['data']['token']
return token
else:
print(token_res.content)
else:
print(res.content)
return
if __name__ == '__main__':
# 1. 判断次数
print("【羊了个羊一键闯关启动】")
# 前置判断,程序员何必为难程序员呢,针对恶意刷次数对服务器造成压力的进行拦截
if cycle_count > 10:
print("程序员何必为难程序员,请勿恶意刷次数对服务器造成压力,请设定cycle_count的值小于10以下的值,本次程序运行结束")
print("【羊了个羊一键闯关开始结束】")
sys.exit(0)
# 2. 根据小羊id获取token
uid = ''
token = get_token()
request_header = {
"Host": "cat-match.easygame2021.com",
"User-Agent": header_user_agent,
"t": token,
"Referer": "https://servicewechat.com/wx141bfb9b73c970a9/17/page-frame.html",
"Accept-Encoding": "gzip,compress,br,deflate",
"Connection": "close"
}
i = 1
success = 0
while True:
print(f"...第{i}次尝试完成闯关...")
interval_time = random.randint(2, 6)
print(f"生成随机时间间隔,防止游戏服务器接口限流导致失败 : {interval_time} s")
if cost_time == -1:
cost_time = random.randint(1, 3600)
print(f"生成随机闯关完成耗时: {cost_time} s")
try:
if sheep_type == 1:
finish_game_sheep(1, cost_time)
success += 1
time.sleep(interval_time)
if topic_type == 1:
finish_game_topic(1, cost_time)
success += 1
except Exception as e:
print(f"游戏服务器响应超时或崩溃中未及时响应,缓缓吧,等待服务器恢复后再试!本次失败请忽略,错误日志: {e}")
if success == cycle_count:
print("【羊了个羊一键闯关结束】")
sys.exit(0)
print(f"\033[4;32m已成功完成{success}\033[0m")
i += 1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化