🐛🐛 修复收获失败的问题

This commit is contained in:
liulong 2024-09-29 15:57:08 +08:00
parent 4287ab3124
commit c0567007df

54
hykb.py
View File

@ -4,12 +4,14 @@
# @author Echo # @author Echo
# @EditTime 2024/9/20 # @EditTime 2024/9/20
import os import os
import random
import re import re
import threading import threading
import urllib.parse
from datetime import datetime from datetime import datetime
import requests import httpx
import random
from sendNotify import send_notification_message from sendNotify import send_notification_message
if 'Hykb_cookie' in os.environ: if 'Hykb_cookie' in os.environ:
@ -24,14 +26,16 @@ class HaoYouKuaiBao():
""" """
def __init__(self, cookie): def __init__(self, cookie):
self.client = httpx.Client(
verify=False,
headers={
"Origin": "https://huodong3.i3839.com",
"Referer": "https://huodong3.3839.com/n/hykb/cornfarm/index.php?imm=0",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
)
self.cookie = cookie self.cookie = cookie
self.url = "https://huodong3.3839.com/n/hykb/{}/ajax{}.php" self.url = "https://huodong3.3839.com/n/hykb/{}/ajax{}.php"
self.data = "ac={}&r=0.{}&scookie={}"
self.headers = {
"Origin": "https://huodong3.i3839.com",
"Referer": "https://huodong3.3839.com/n/hykb/cornfarm/index.php?imm=0",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
self.user_name = self.user_info()["user"] self.user_name = self.user_info()["user"]
def user_info(self): def user_info(self):
@ -40,14 +44,9 @@ class HaoYouKuaiBao():
:return: :return:
""" """
url = self.url.format("qdjh", "") url = self.url.format("qdjh", "")
data = { payload = f"ac=login&r=0.{random.randint(100000000000000000, 899999999999999999)}&scookie={urllib.parse.quote(self.cookie)}&device=kbA25014349F11473F467DC6FF5C89E9D6"
"ac": "login",
"r": f"0.{random.randint(1000000000000000, 8999999999999999)}",
"scookie": self.cookie,
"device": "kbA25014349F11473F467DC6FF5C89E9D6"
}
try: try:
response = requests.post(url, headers=self.headers, data=data).json() response = self.client.post(url, content=payload).json()
if response['key'] == 'ok': if response['key'] == 'ok':
return { return {
"user": response["config"]["name"], "user": response["config"]["name"],
@ -60,9 +59,9 @@ class HaoYouKuaiBao():
"""播种 """播种
""" """
url = self.url.format("cornfarm", "_plant") url = self.url.format("cornfarm", "_plant")
data = self.data.format("Plant", random.randint(1000000000000000, 8999999999999999), self.cookie) payload = f"ac=Plant&r=0.{random.randint(100000000000000000, 899999999999999999)}&scookie={urllib.parse.quote(self.cookie)}&device=kbA25014349F11473F467DC6FF5C89E9D6"
try: try:
response = requests.post(url, headers=self.headers, data=data).json() response = self.client.post(url, content=payload).json()
if response['key'] == 'ok': if response['key'] == 'ok':
print(f"好游快爆-用户【{self.user_name}】播种成功") print(f"好游快爆-用户【{self.user_name}】播种成功")
send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"), send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"),
@ -87,14 +86,17 @@ class HaoYouKuaiBao():
"""收获 """收获
""" """
url = self.url.format("cornfarm", "_plant") url = self.url.format("cornfarm", "_plant")
data = self.data.format("Harvest", random.randint(1000000000000000, 8999999999999999), self.cookie) payload = f"ac=Harvest&r=0.{random.randint(100000000000000000, 899999999999999999)}&scookie={urllib.parse.quote(self.cookie)}&device=kbA25014349F11473F467DC6FF5C89E9D6"
try: try:
response = requests.post(url, headers=self.headers, data=data).json() response = self.client.post(url, content=payload).json()
if response['key'] == 'ok': if response['key'] == 'ok':
print(f"好游快爆-用户【{self.user_name}】收获成功") print(f"好游快爆-用户【{self.user_name}】收获成功")
send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"), send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"),
f"好游快爆-用户【{self.user_name}】收获成功") f"好游快爆-用户【{self.user_name}】收获成功")
return True elif response['key'] == '503':
print(f"好游快爆-用户【{self.user_name}{response['info']}")
send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"),
f"好游快爆-用户【{self.user_name}{response['info']}")
else: else:
print(f"好游快爆-用户【{self.user_name}】收获失败") print(f"好游快爆-用户【{self.user_name}】收获失败")
send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"), send_notification_message("好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"),
@ -108,24 +110,22 @@ class HaoYouKuaiBao():
"""登录 """登录
""" """
url = self.url.format("cornfarm", "") url = self.url.format("cornfarm", "")
data = self.data.format("login", random.randint(100000000000000, 8999999999999999), self.cookie) payload = f"ac=login&r=0.{random.randint(100000000000000000, 899999999999999999)}&scookie={urllib.parse.quote(self.cookie)}&device=kbA25014349F11473F467DC6FF5C89E9D6"
response = requests.post(url, headers=self.headers, data=data) response = self.client.post(url, content=payload)
try: try:
response = response.json() response = response.json()
return response return response
except Exception as e: except Exception as e:
print("好游快爆-登录出现错误:{}".format(e)) print("好游快爆-登录出现错误:{}".format(e))
# response = response.text
# return response
def watering(self): def watering(self):
"""浇水 """浇水
""" """
url = self.url.format("cornfarm", "_sign") url = self.url.format("cornfarm", "_sign")
data = self.data.format("Sign&verison=1.5.7.005&OpenAutoSign=", payload = f"ac=Sign&verison=1.5.7.005&OpenAutoSign=&r=0.{random.randint(100000000000000000, 899999999999999999)}&scookie={urllib.parse.quote(self.cookie)}&device=kbA25014349F11473F467DC6FF5C89E9D6"
random.randint(100000000000000, 8999999999999999), self.cookie)
try: try:
response = requests.post(url, headers=self.headers, data=data).json() response = self.client.post(url, content=payload).json()
if response['key'] == 'ok': if response['key'] == 'ok':
print(f"好游快爆-用户【{self.user_name}】浇水成功") print(f"好游快爆-用户【{self.user_name}】浇水成功")
send_notification_message(title="好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"), send_notification_message(title="好游快爆签到通知 - " + datetime.now().strftime("%Y/%m/%d"),