请使用python环境进行测试修改编译
改源码进攻学习参考使用,切勿用于非法操作,后果自行承担,与博主无关!!!!!
接口代码1
import hashlib
import json
import re
import time
import ddddocr
import requests
import execjs
import base64
from io import BytesIO
from urllib.parse import urlencode
import os
from PIL import Image
def post_api(img):
with open(img, "rb") as f:
bin_contents = f.read()
heads={
"content-type":"image/png"
}
result = requests.post("http://111.224.107.217:710/ocr", data=bin_contents,headers=heads)
return result.text
def get_img(img1,img2):
new_image = Image.new('RGB', (672, 620), 'white')
new_image.paste(img1, (0, 0))
new_image.paste(img2, (200, 200))
slide = ddddocr.DdddOcr(det=False, ocr=False, show_ad=False)
yuming = "https://t.captcha.qq.com"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
}
def get_slide_data(aid):
#r = requests.get(url, headers=headers).text
#sid = re.findall(".*?'(.*?)'",r)
#print(sid[6])
r = requests.get(url, headers=headers).text[11: -1]
data = json.loads(r)
#print(data)
_data ={}
_data["powCfg"]={}
_data["sid"] = data["sid"]
_data["sess"] = data["sess"]
_data["y"] = data["data"]['dyn_show_info']['fg_elem_list'][1]['init_pos'][1]
#print(_data["y"],"我是y坐标")
_data["powCfg"]["md5"] = data["data"]['comm_captcha_cfg']['pow_cfg']["md5"]
_data["powCfg"]["prefix"] = data["data"]['comm_captcha_cfg']['pow_cfg']["prefix"]
_data["dcFileName"] = data["data"]['comm_captcha_cfg']['tdc_path']
_data["cdnPic1"] = data["data"]['dyn_show_info']['bg_elem_cfg']['img_url']
_data["cdnPic2"] = data["data"]['dyn_show_info']['sprite_url']
print("_data->",_data)
#_data["sid"] = data["sid"]
return _data
def find_slide_notch(url):
css_dict = {
"background-image": url,
"background-position": "-70.8333px -247.917px",
"background-size": "345.06px 313.69px",
"width": "60.7143px",
"height": "60.7143px",
"left": "25.2976px",
"top": "123.958px",
"z-index": "1",
"cursor": "pointer",
"opacity": "1",
}
获取图片并加载为Pillow Image对象
response = requests.get(css_dict["background-image"])
img = Image.open(BytesIO(response.content))
解析CSS中的background-position和background-size属性
bg_position = [float(pos.strip("px")) for pos in css_dict["background-position"].split()]
bg_size = [float(size.strip("px")) for size in css_dict["background-size"].split()]
计算切割区域
x = -bg_position[0] * img.width / bg_size[0]
y = -bg_position[1] * img.height / bg_size[1]
w = float(css_dict["width"].strip("px")) * img.width / bg_size[0]
h = float(css_dict["height"].strip("px")) * img.height / bg_size[1]
切割图片
crop_img = img.crop((x, y, x + w, y + h))
可以将切割后的图片保存到本地
crop_img.save("crop_img.png")
with open("crop_img.png", "rb") as fp:
target_bytes = fp.read()
return target_bytes
def get_slide_distance(tar_img, back_img):
#图片处理 ddddorc处理,怎么处理啊,那种新版本的滑块,返回的阴影是整个
target_bytes = requests.get(tar_img).content
target_bytes = find_slide_notch(tar_img)
background_bytes = requests.get(back_img).content
res = slide.slide_match(target_bytes, background_bytes, simple_target=True)
return res["target"][0]-2, res["target"][1]
def post_data(collect, eks, sess, notch_data, prefix, nonce, sid,ip):
url = "https://t.captcha.qq.com/cap_union_new_verify"
headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
}
ans = "{},{}".format(notch_data[0], notch_data[1])
data = {
"collect":collect,
"tlg":len(collect),
"eks":eks,
"sess":sess,
"pow_answer":prefix,
"pow_calc_time":28,
"ans":[{"elem_id":1,"type":"DynAnswerType_POS","data":ans}]
}
#print(data)
#print(ip)
try:
r = requests.post(url, headers=headers, data=urlencode(data), proxies=ip, timeout=(3))
print(r.text)
return json.loads(r.text)
except:
print("代理ip有问题")
return {}
def sign_md5(params):
"""
对拼接好的字符串进行md5签名
"""
hl = hashlib.md5()
hl.update(params.encode(encoding='utf-8'))
return hl.hexdigest()
def get_ans(prefix, md5_code):
u = 0
while sign_md5(str(prefix) + str(u)) != md5_code:
u += 1
return str(u)
def get_data():
with open("./main.js", "r", encoding="utf-8") as fp:
exec_js = execjs.compile(fp.read())
data = exec_js.call("sign")
return data
def check(ticket, randstr):
print(ticket,randstr)
headers = {
"accept": "application/json, text/plain, */*",
"accept-encoding": "gzip, deflate",
"accept-language": "zh-CN,zh;q=0.9",
"referer": url,
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309071d) XWEB/8461 Flue"
}
jieguo = requests.get(url=url,headers=headers).text
print(jieguo,"----->我是提交结果")
def tx_start(aid, ip):
_t = time.time()
slide_data = get_slide_data(aid)
#tdc_js = "https://turing.captcha.qcloud.com/" + slide_data["dcFileName"]
slide_js = requests.get("https://t.captcha.qq.com" + slide_data["dcFileName"], headers=headers).text
img1 = "https://t.captcha.qq.com" + slide_data["cdnPic1"]
img2 = "https://t.captcha.qq.com" + slide_data["cdnPic2"]
print(img1,img2)
#find_slide_notch(img2)
#acc = get_slide_distance(img1,img2)
#print(acc[0],acc[1])
#notch_data = get_slide_distance(img2, img1)
background_bytes = requests.get(img1).content
res = slide.slide_match(background_bytes, find_slide_notch(img2), simple_target=True)
#res["target"][0] - 2, res["target"][1]
print(res)
#heads = {
"content-type": "image/png"
#}
#result = requests.post("http://111.224.107.217:710/ocr", data=background_bytes, headers=heads).text
notch_data =[]
notch_data.append(res["target"][0] - 2)
notch_data.append(res["target"][1])
print("坐标->",notch_data)
md5_code = slide_data["powCfg"]["md5"]
prefix = slide_data["powCfg"]["prefix"]
ans = get_ans(prefix, md5_code)
with open("./JsCode/start.js", "w", encoding="utf-8") as fp:#我好像没这个东西
fp.write(slide_js)
fp.flush()
print("tx------->执行结果")
data = get_data()
collect = data
eks = re_x_url(slide_js, "='", "'")
result = post_data(collect, eks, slide_data["sess"], notch_data, prefix + ans, "", slide_data["sid"],ip)
#print("耗费时间:{}ms".format((time.time() - _t)* 1000))
#判断是否通过滑块
if result["errorCode"] == 0:
ticket = result["ticket"]
randstr = result["randstr"]
check(ticket,randstr)
return result
else:
ipurl = "";
ip = requests.get(ipurl, headers=headers).text;
proxies = {
"http": ip,
"https": ip
}
print(proxies)
重试多次退出 需要判断次数 自己补充,等等,ddddocr那个拼接,你复制给我一份
return tx_start(aid, proxies)
def re_x_url(url, start, end, is_raise=True):
id = re.findall(r"{}(.*?){}".format(start, end), url)
if id:
id = id[0]
if is_raise and not id:
print("正则处理数据为空!")
raise IndexError("正则处理数据为空!")
return id
if name == 'main':
for i in range(10):
ipurl = "";#这里传代理
ip = requests.get(ipurl,headers=headers).text;
proxies = {
"http": ip,
"https": ip
}
print(proxies)
tx_start("2000000038",proxies)
api接口代码
import uvicorn
from fastapi import FastAPI
from QQ邮箱 import tx_start
app = FastAPI()
@app.post("/silde/tx")
def tx_pass(aid: str, proxy: str):
#调用tx滑块的方法
result = tx_start(aid, proxy)
return result
if name == 'main':
uvicorn.run(app="tx_api:app", host='127.0.0.1', port=5000, reload=True, workers=4)
仅供参考学习