1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
| import requests import re import execjs import json import time from loguru import logger import numpy as np import cv2 import random import math debug=True headers = { 'authority': 'www.ishumei.com', 'accept': '*/*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8', 'cache-control': 'no-cache', 'pragma': 'no-cache', 'referer': 'https://www.ishumei.com/trial/captcha.html', 'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', 'sec-fetch-dest': 'script', 'sec-fetch-mode': 'no-cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', } Jsfile = open('main.js', 'r', encoding='utf-8') JsData = Jsfile.read() def getUUID(): return execjs.compile(JsData).call('getUUID')
def getParams(k,l,distance,move_lis,use_time): return execjs.compile(JsData).call('getParams', k, l, distance,move_lis,use_time)
def get_trace_and_times(distance): x = [0, 0] y = [0, 0, 0] z = [0] count = np.linspace(-math.pi / 2, math.pi / 2, random.randrange(10, 20)) func = list(map(math.sin, count)) nx = [i + 1 for i in func] add = random.randrange(10, 15) sadd = distance + add x.extend(list(map(lambda x: x * (sadd / 2), nx))) x.extend(np.linspace(sadd, distance, 3 if add > 12 else 2)) x = [math.floor(i) for i in x] for i in range(len(x) - 2): if y[-1] < 30: y.append(y[-1] + random.choice([0, 0, 1, 1, 2, 2, 1, 2, 0, 0, 3, 3])) else: y.append(y[-1] + random.choice([0, 0, -1, -1, -2, -2, -1, -2, 0, 0, -3, -3])) for i in range(len(x) - 1): z.append((z[-1] // 100 * 100) + 100 + random.choice([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2])) trace = list(map(list, zip(x, y, z))) times = trace[-1][-1] + random.randint(1, 5) return trace, times class ShuMei: def __init__(self) -> None: self.UUID = getUUID() logger.success(f'获取到UUID: {self.UUID}') def get_organization(self): url = 'https://www.ishumei.com/static/js/trial/captcha_7867b6f.js' resp = requests.get(url, headers=headers) organization = re.findall('organization:"(.*?)",', resp.text)[0] self.organization = organization logger.success(f'获取到organization: {organization}') def get_distance(self, slice_content, bg_content): if debug: with open('slice.png', 'wb') as f: f.write(slice_content) f.close() with open('bg.png', 'wb') as f: f.write(bg_content) f.close()
""" :param bg_url: 背景图地址 :param slice_url: 滑块图地址 :return: distance :rtype: Integer """ slice_image = np.asarray(bytearray(slice_content), dtype=np.uint8) slice_image = cv2.imdecode(slice_image, 1) slice_image = cv2.Canny(slice_image, 22, 22)
bg_image = np.asarray(bytearray(bg_content), dtype=np.uint8) bg_image = cv2.imdecode(bg_image, 1) bg_image = cv2.pyrMeanShiftFiltering(bg_image, 20, 11) bg_image = cv2.Canny(bg_image, 20, 20)
bg_image = cv2.cvtColor(bg_image, cv2.COLOR_GRAY2RGB) slice_image = cv2.cvtColor(slice_image, cv2.COLOR_GRAY2RGB)
result = cv2.matchTemplate(bg_image, slice_image, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) if debug: th, tw = slice_image.shape[:2] tl = max_loc br = (tl[0] + tw, tl[1] + th) cv2.rectangle(bg_image, tl, br, (0, 0, 255), 2) cv2.imwrite('out.jpg', bg_image)
return [max_loc[0]]
def getContentOfImg(self, url): resp = requests.get(url, headers=headers) return resp.content def Register(self): params = { 'rversion': '1.0.4', 'model': 'slide', 'appId': 'default', 'data': '{}', 'captchaUuid': self.UUID, 'organization': self.organization, 'sdkver': '1.1.3', 'lang': 'zh-cn', 'channel': 'DEFAULT', 'callback': f'sm_{int(time.time())}', }
response = requests.get('https://captcha1.fengkongcloud.cn/ca/v1/register', params=params, headers=headers,impersonate="chrome101") Jstext = response.text.split('(')[1].split(')')[0] Jstext = json.loads(Jstext) self.img_bg = 'https://castatic.fengkongcloud.cn'+Jstext['detail']['bg'] self.img_fg = 'https://castatic.fengkongcloud.cn'+Jstext['detail']['fg'] self.k = Jstext['detail']['k'] self.l = Jstext['detail']['l'] self.rid = Jstext['detail']['rid'] logger.success(f'获取到背景图片地址: {self.img_bg}') logger.success(f'获取到滑块图片地址: {self.img_fg}') logger.success(f'获取到k: {self.k}') logger.success(f'获取到l: {self.l}') logger.success(f'获取到rid: {self.rid}') def getDistance(self): slice_content = self.getContentOfImg(self.img_fg) bg_content = self.getContentOfImg(self.img_bg) distance = int(self.get_distance(slice_content, bg_content)[0]/2)+3 logger.success(f'获取到distance: {distance}') return distance def getVerifyParams(self): distance = self.getDistance() move_lis,use_time = get_trace_and_times(distance) params = getParams(self.k, self.l, distance,move_lis,use_time) params = {**params, ** { 'sdkver': '1.1.3', 'callback': f'sm_{int(time.time()*1000)}', 'act.os': 'web_pc', 'organization': self.organization, 'rversion': '1.0.4', 'ostype': 'web', 'rid': self.rid, 'captchaUuid': self.UUID, 'protocol': '179', }} logger.debug(f'获取到params: {params}') return params def verify(self,params): headers = { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Origin': 'https://www.ishumei.com', 'Pragma': 'no-cache', 'Referer': 'https://www.ishumei.com/trial/captcha.html', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', 'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', }
response = requests.get('https://captcha1.fengkongcloud.cn/ca/v2/fverify', params=params, headers=headers,impersonate="chrome101") if 'REJECT' in response.text: logger.error(f'获取到response: {response.text}') else: logger.success(f'获取到response: {response.text}')
for i in range(100): shumei = ShuMei() shumei.get_organization() shumei.Register() params = shumei.getVerifyParams() shumei.verify(params) break
|