MCPcopy Create free account
hub / github.com/VitoHowe/glm-coding / build_click_answer

Method build_click_answer

app/services/captcha_service.py:76–102  ·  view source on GitHub ↗
(self, points: list[CaptchaPoint | dict[str, Any]])

Source from the content-addressed store, hash-verified

74 return ticket, randstr
75
76 def build_click_answer(self, points: list[CaptchaPoint | dict[str, Any]]) -> list[dict[str, Any]]:
77 if not points:
78 raise BadRequestError("缺少点击点位,没法组装腾讯 verify 的 ans")
79
80 normalized: list[tuple[int, int, int]] = []
81 for index, item in enumerate(points, start=1):
82 point = item if isinstance(item, CaptchaPoint) else CaptchaPoint.model_validate(item)
83 order = int(point.order or index)
84 normalized.append(
85 (
86 order,
87 self._js_round(point.x),
88 self._js_round(point.y),
89 )
90 )
91
92 normalized.sort(key=lambda item: (item[0], item[1], item[2]))
93 answer: list[dict[str, Any]] = []
94 for elem_id, (_, x, y) in enumerate(normalized, start=1):
95 answer.append(
96 {
97 "elem_id": elem_id,
98 "type": "DynAnswerType_POS",
99 "data": f"{x},{y}",
100 }
101 )
102 return answer
103
104 def extract_points_from_ocr(self, ocr_payload: dict[str, Any]) -> list[CaptchaPoint]:
105 raw_points = ocr_payload.get("points")

Callers 1

build_verify_payloadMethod · 0.95

Calls 2

_js_roundMethod · 0.95
BadRequestErrorClass · 0.90

Tested by

no test coverage detected