更新 WX_Applet/Applet_WLJi.py
This commit is contained in:
@@ -18,7 +18,7 @@ import random
|
||||
import hashlib
|
||||
import requests
|
||||
import logging
|
||||
from typing import Optional, List, Dict
|
||||
from typing import Optional, List, Dict, Any
|
||||
from urllib.parse import urlencode
|
||||
|
||||
# ==================== 养鸡场配置 ====================
|
||||
@@ -508,6 +508,87 @@ class WangLaoJiAutomation:
|
||||
return None, is_proxy
|
||||
return None, False
|
||||
|
||||
# ==================== 领取奖励完整流程 ====================
|
||||
def claim_reward_flow(self, final_s3_token, reward_id, reward_value, current_proxy):
|
||||
"""执行步骤6和步骤7,领取并确认奖励"""
|
||||
claim_data, is_claim_err = self.step6_receive_reward(final_s3_token, reward_id, current_proxy)
|
||||
if not claim_data and self.use_proxy and is_claim_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
claim_data, _ = self.step6_receive_reward(final_s3_token, reward_id, current_proxy)
|
||||
if claim_data:
|
||||
_, is_receive_err = self.step7_claim_reward(final_s3_token, reward_id, current_proxy)
|
||||
if _:
|
||||
logger.info(f"💰 到账 {reward_value/100:.2f}元")
|
||||
return reward_value / 100.0, current_proxy
|
||||
return 0.0, current_proxy
|
||||
|
||||
# ==================== 单次完整扫码抽奖流程 ====================
|
||||
def do_single_scan_and_lottery(self, final_s3_token, mask_code, scan_lat, scan_lon, current_proxy, seen_reward_ids, hits_count):
|
||||
"""
|
||||
执行一次完整的扫码+抽奖流程,返回:
|
||||
(lottery_result, new_hits, amount_added, prizes_list, current_proxy)
|
||||
"""
|
||||
# 步骤4 扫码核销
|
||||
scan_result, is_proxy_err, is_daily_limit = self.step4_scan_mask_code(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
|
||||
if is_daily_limit:
|
||||
logger.warning("⚠️ 每日上限")
|
||||
return "daily_limit", hits_count, 0.0, [], current_proxy
|
||||
|
||||
if not scan_result:
|
||||
if self.use_proxy and is_proxy_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
return None, hits_count, 0.0, [], current_proxy
|
||||
|
||||
# 步骤5 抽奖
|
||||
lottery_result, is_lottery_proxy_err = self.step5_mask_code_lottery(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
if not lottery_result:
|
||||
if self.use_proxy and is_lottery_proxy_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
lottery_result, _ = self.step5_mask_code_lottery(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
|
||||
if not lottery_result:
|
||||
return None, hits_count, 0.0, [], current_proxy
|
||||
|
||||
amount_added = 0.0
|
||||
new_prizes = []
|
||||
|
||||
lucky_list = lottery_result.get("luckyRewardList", [])
|
||||
if lucky_list:
|
||||
hits_count += 1
|
||||
for prize in lucky_list:
|
||||
reward_id = prize.get("userRewardId")
|
||||
# 去重
|
||||
if reward_id and reward_id in seen_reward_ids:
|
||||
continue
|
||||
if reward_id:
|
||||
seen_reward_ids.add(reward_id)
|
||||
|
||||
name = prize.get("rewardName", "未知")
|
||||
value = prize.get("rewardValue", 0)
|
||||
reward_type = prize.get("rewardType", "")
|
||||
new_prizes.append(name)
|
||||
logger.info(f"🎁 获得 {name},价值 {value/100:.2f}元")
|
||||
|
||||
custom = prize.get("customData", {})
|
||||
if reward_id and reward_type == "redpacket" and custom.get("incentive"):
|
||||
logger.info("💰 红包已激活,领取中...")
|
||||
earned, current_proxy = self.claim_reward_flow(final_s3_token, reward_id, value, current_proxy)
|
||||
amount_added += earned
|
||||
else:
|
||||
logger.info(f"🎟️ 未中奖")
|
||||
|
||||
return lottery_result, hits_count, amount_added, new_prizes, current_proxy
|
||||
|
||||
# ==================== 账号处理 ====================
|
||||
def process_account(self, account):
|
||||
result = {
|
||||
@@ -549,8 +630,63 @@ class WangLaoJiAutomation:
|
||||
logger.info(f"📍 扫码位置: {scan_lat},{scan_lon}")
|
||||
|
||||
seen_reward_ids = set() # 用于奖品去重
|
||||
pending_activation = None # 待激活的奖品信息: {"reward_id": str, "value": int}
|
||||
|
||||
while hits < self.daily_lottery_limit and attempts < MAX_CODE_ATTEMPTS:
|
||||
# ===== 如果存在待激活的奖品,优先进行激活 =====
|
||||
if pending_activation:
|
||||
logger.info(f"🔔 有待激活红包,优先激活...")
|
||||
activation_code = self.get_scan_code()
|
||||
if not activation_code:
|
||||
logger.error("❌ 无可用码字进行激活")
|
||||
break
|
||||
|
||||
# 用新码走一遍步骤2-5进行激活
|
||||
s3_token = self.step2_get_s3_token(wlj_token, activation_code, login_result["userCode"],
|
||||
scan_lat, scan_lon, current_proxy)
|
||||
if not s3_token:
|
||||
self.set_pending_code(activation_code)
|
||||
break
|
||||
|
||||
final_s3_token, is_ssl = self.step3_s3_third_login(s3_token, current_proxy)
|
||||
if not final_s3_token:
|
||||
self.set_pending_code(activation_code)
|
||||
break
|
||||
|
||||
# 扫码+抽奖(用于激活)
|
||||
attempts += 1
|
||||
scan_result, new_hits, amount_added, new_prizes, current_proxy = self.do_single_scan_and_lottery(
|
||||
final_s3_token, activation_code, scan_lat, scan_lon, current_proxy, seen_reward_ids, hits)
|
||||
|
||||
# 提交激活码
|
||||
self.commit_scan_code(activation_code)
|
||||
|
||||
if scan_result == "daily_limit":
|
||||
break
|
||||
|
||||
# 检查这次激活的结果
|
||||
if amount_added > 0:
|
||||
# 激活成功,领取到钱
|
||||
result["total_amount"] += amount_added
|
||||
# 将奖品名称加入列表(去重已在 do_single_scan_and_lottery 中处理)
|
||||
result["prizes"].extend(new_prizes)
|
||||
pending_activation = None # 激活完成
|
||||
logger.info(f"✅ 红包激活成功")
|
||||
elif new_hits > hits:
|
||||
# 又中奖了但未激活(incentive=false),更新hits但保持待激活状态
|
||||
hits = new_hits
|
||||
result["prizes"].extend(new_prizes)
|
||||
# 待激活信息可能已更新,继续激活流程
|
||||
logger.info(f"🎁 再次中奖,仍待激活")
|
||||
else:
|
||||
# 未中奖,待激活奖品仍在,继续尝试
|
||||
logger.info(f"🎟️ 激活未成功(未中奖),继续尝试激活")
|
||||
|
||||
if hits < self.daily_lottery_limit:
|
||||
time.sleep(random.uniform(self.lottery_interval_min, self.lottery_interval_max))
|
||||
continue
|
||||
|
||||
# ===== 正常抽奖流程 =====
|
||||
logger.info(f"🎯 第 {hits+1}/{self.daily_lottery_limit} 次中奖 (已用码 {attempts})")
|
||||
|
||||
mask_code = self.get_scan_code()
|
||||
@@ -585,74 +721,54 @@ class WangLaoJiAutomation:
|
||||
time.sleep(random.uniform(self.lottery_interval_min, self.lottery_interval_max))
|
||||
continue
|
||||
|
||||
# 步骤4
|
||||
scan_result, is_proxy_err, is_daily_limit = self.step4_scan_mask_code(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
if is_daily_limit:
|
||||
logger.warning("⚠️ 每日上限,停止本账号")
|
||||
# 使用码字
|
||||
attempts += 1
|
||||
|
||||
# 执行扫码+抽奖
|
||||
lottery_result, new_hits, amount_added, new_prizes, current_proxy = self.do_single_scan_and_lottery(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy, seen_reward_ids, hits)
|
||||
|
||||
# 提交码字
|
||||
self.commit_scan_code(mask_code)
|
||||
|
||||
if lottery_result == "daily_limit":
|
||||
break
|
||||
if not scan_result:
|
||||
if self.use_proxy and is_proxy_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
self.set_pending_code(mask_code)
|
||||
|
||||
if lottery_result is None:
|
||||
time.sleep(random.uniform(self.lottery_interval_min, self.lottery_interval_max))
|
||||
continue
|
||||
|
||||
# 扫码成功,使用码字
|
||||
attempts += 1
|
||||
# 更新结果
|
||||
if amount_added > 0:
|
||||
result["total_amount"] += amount_added
|
||||
# 如果金额是在 do_single_scan_and_lottery 中通过激活获得的,
|
||||
# 说明之前有一个待激活的奖品已成功激活
|
||||
pending_activation = None
|
||||
logger.info(f"✅ 红包已激活并到账")
|
||||
|
||||
# 步骤5
|
||||
lottery_result, is_lottery_proxy_err = self.step5_mask_code_lottery(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
if not lottery_result:
|
||||
if self.use_proxy and is_lottery_proxy_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
lottery_result, _ = self.step5_mask_code_lottery(
|
||||
final_s3_token, mask_code, scan_lat, scan_lon, current_proxy)
|
||||
|
||||
if lottery_result:
|
||||
lucky_list = lottery_result.get("luckyRewardList", [])
|
||||
# 检查是否有待激活的奖品
|
||||
lucky_list = lottery_result.get("luckyRewardList", []) if lottery_result and lottery_result != "daily_limit" else []
|
||||
has_unactivated = False
|
||||
if lucky_list:
|
||||
hits += 1
|
||||
for prize in lucky_list:
|
||||
reward_id = prize.get("userRewardId")
|
||||
# 去重:同一个红包只记录一次
|
||||
if reward_id and reward_id in seen_reward_ids:
|
||||
continue
|
||||
if reward_id:
|
||||
seen_reward_ids.add(reward_id)
|
||||
|
||||
name = prize.get("rewardName", "未知")
|
||||
value = prize.get("rewardValue", 0)
|
||||
reward_type = prize.get("rewardType", "")
|
||||
result["prizes"].append(name)
|
||||
logger.info(f"🎁 获得 {name},价值 {value/100:.2f}元")
|
||||
|
||||
custom = prize.get("customData", {})
|
||||
if reward_id and reward_type == "redpacket" and custom.get("incentive"):
|
||||
logger.info("💰 红包已激活,领取中...")
|
||||
claim_data, is_claim_err = self.step6_receive_reward(final_s3_token, reward_id, current_proxy)
|
||||
if not claim_data and self.use_proxy and is_claim_err:
|
||||
new_proxy = self.get_proxy()
|
||||
if new_proxy:
|
||||
current_proxy = new_proxy
|
||||
claim_data, _ = self.step6_receive_reward(final_s3_token, reward_id, current_proxy)
|
||||
if claim_data:
|
||||
_, is_receive_err = self.step7_claim_reward(final_s3_token, reward_id, current_proxy)
|
||||
if _:
|
||||
result["total_amount"] += value / 100.0
|
||||
logger.info(f"💰 到账 {value/100:.2f}元")
|
||||
else:
|
||||
logger.info(f"🎟️ 未中奖")
|
||||
reward_type = prize.get("rewardType", "")
|
||||
if reward_id and reward_type == "redpacket" and not custom.get("incentive"):
|
||||
# 有未激活的红包
|
||||
pending_activation = {
|
||||
"reward_id": reward_id,
|
||||
"value": prize.get("rewardValue", 0)
|
||||
}
|
||||
has_unactivated = True
|
||||
logger.info(f"🔔 红包待激活: {prize.get('rewardName', '未知')}")
|
||||
break
|
||||
|
||||
# 提交码字使用
|
||||
self.commit_scan_code(mask_code)
|
||||
if new_hits > hits:
|
||||
hits = new_hits
|
||||
result["prizes"].extend(new_prizes)
|
||||
|
||||
if hits < self.daily_lottery_limit:
|
||||
if hits < self.daily_lottery_limit and not has_unactivated:
|
||||
time.sleep(random.uniform(self.lottery_interval_min, self.lottery_interval_max))
|
||||
|
||||
result["attempts"] = attempts
|
||||
|
||||
Reference in New Issue
Block a user