二开V免签(支持赞赏码)
微信Hook
赞赏码监控代码
import hashlib
import requests
import time
import threading
import re
import logging
import json
from wxhook import Bot
from wxhook import events
from wxhook.model import Event
# 配置日志
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# 加载配置
try:
with open('config.json', 'r') as f:
config = json.load(f)
except FileNotFoundError:
logger.error("配置文件 'config.json' 未找到")
raise
class WeChatPayMonitor:
def __init__(self, host, key):
self.host = host
self.key = key
def md5(self, string):
return hashlib.md5(string.encode('utf-8')).hexdigest()
def app_push(self, amount):
t = str(int(time.time() * 1000))
sign = self.md5(f"1{amount}{t}{self.key}")
url = f"http://{self.host}/appPush?t={t}&type=1&price={amount}&sign={sign}"
try:
response = requests.get(url)
logger.info(f"Push response: {response.text}")
response_json = response.json()
if response_json.get('code') == 0:
print(f"回调成功: 金额 {amount} 元")
return True
else:
print(f"回调失败: {response_json.get('msg', '未知错误')}")
return False
except Exception as e:
logger.error(f"Push failed: {e}")
print(f"回调异常: {str(e)}")
return False
def send_heartbeat(self):
while True:
t = str(int(time.time() * 1000))
sign = self.md5(f"{t}{self.key}")
url = f"http://{self.host}/appHeart?t={t}&sign={sign}"
try:
response = requests.get(url)
logger.info(f"Heartbeat response: {response.text}")
except Exception as e:
logger.error(f"Heartbeat failed: {e}")
time.sleep(60)
@staticmethod
def extract_money_from_des(des):
# 分割字符串并查找包含"收款金额"的行
lines = des.split('\\n')
for line in lines:
if "收款金额" in line:
match = re.search("¥(\\d+\\.\\d{2})", line)
if match:
return match.group(1)
logger.warning(f"Failed to extract money from des: {des}")
return None
def handle_message(self, event):
"""
处理所有微信消息,检查支付通知
"""
try:
# 提取消息的内容
content = event.content
msg = content.get('msg', {})
appmsg = msg.get('appmsg', {})
title = appmsg.get('title', '')
des = appmsg.get('des', '')
logger.info(f"Extracted title: '{title}'")
logger.info(f"Extracted des: '{des}'")
# 判断是否是二维码赞赏到账通知
is_payment = "二维码赞赏到账" in title
logger.info(f"Is this a payment message? {'Yes' if is_payment else 'No'}")
if is_payment:
money = self.extract_money_from_des(des)
if money:
logger.info(f"WeChat payment received: {money} CNY")
callback_success = self.app_push(float(money))
if not callback_success:
print(f"回调失败,请检查网络或服务器状态")
else:
logger.warning("Failed to extract money from WeChat notification")
print("提取支付金额失败,请检查消息格式")
else:
logger.debug("This is not a payment notification.")
except Exception as e:
logger.exception(f"Error processing message: {e}")
print(f"处理消息时发生错误: {str(e)}")
# 在每条消息处理后输出判断结果
print(f"Is this a payment message? {'Yes' if is_payment else 'No'}")
# 初始化监控器,设置服务器地址和密钥
monitor = WeChatPayMonitor(host=config['host'], key=config['key'])
# 启动心跳线程
heartbeat_thread = threading.Thread(target=monitor.send_heartbeat)
heartbeat_thread.daemon = True
heartbeat_thread.start()
# 创建微信机器人实例
bot = Bot(faked_version="3.9.10.19")
@bot.handle(events.ALL_MESSAGE) # 捕获所有类型的消息
def on_message(bot: Bot, event: Event):
"""
处理所有微信消息事件。
"""
monitor.handle_message(event)
if __name__ == "__main__":
# 启动微信机器人
bot.run()
config.json
{
"host": "V免签域名地址",
"key": "V免签回调key"
}
具体操作
- 搭建二开V免签,易支付,此处不提供方法。
- 安装wxhook仓库内的微信,并关闭自动更新。
3.找一个windows电脑运行上方的python代码。
V免签心跳正常即可对接。