eebff9f786
Replace the Phase-0 placeholder password encryption with real RSA
(PKCS#1 v1.5). encrypt_password now builds an RSA public key from the
getSecureKey modulus/exponent (RSAPublicNumbers, e=int(hex,16),
n=int(hex,16)), encrypts the UTF-8 password, and returns hex (documented
assumption -- base64 is the one-line fallback noted in the docstring).
get_secure_key now returns the inner data dict to match the new contract;
pc_login keeps {account, password} with a comment on the username/password
and account/pwd fallbacks if pcLogin rejects.
Extend normalize_wechat_type with the Phase-0 confirmed codes:
2 -> image, 3 -> image_legacy, 4 -> video, 10 -> system (1 -> text and
-2 -> divider unchanged; 6/9/13/15/21/22 stay unknown until confirmed).
Tests:
- encrypt_password round-trip: generate an RSA keypair, build secure_key
from its public numbers, encrypt, then decrypt with the private key and
assert the original password comes back. Pins 512-hex output for a
2048-bit key. No network.
- Parser parametrize table extended for the new codes (and a downstream
message-fixture assertion updated from unknown -> image_legacy).
Suite: 87 -> 97 passing. ruff check clean.
Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
861 B
Python
30 lines
861 B
Python
"""会话层 (session layer) for the yunke CRM API.
|
|
|
|
Public surface:
|
|
|
|
* :class:`app.session.login.LoginResult` — parsed login outcome (userid,
|
|
company, cookies snapshot, raw payload).
|
|
* :func:`app.session.login.get_secure_key` — ``GET /newuc/login/getSecureKey``.
|
|
* :func:`app.session.login.pc_login` — ``POST /usercenter/login/pcLogin``.
|
|
* :func:`app.session.login.encrypt_password` — RSA (PKCS#1 v1.5) password
|
|
encryption using the ``getSecureKey`` modulus/exponent.
|
|
* :class:`app.session.yunke_client.YunkeClient` — the authenticated HTTP
|
|
client every scraper uses.
|
|
"""
|
|
|
|
from app.session.login import (
|
|
LoginResult,
|
|
encrypt_password,
|
|
get_secure_key,
|
|
pc_login,
|
|
)
|
|
from app.session.yunke_client import YunkeClient
|
|
|
|
__all__ = [
|
|
"LoginResult",
|
|
"YunkeClient",
|
|
"encrypt_password",
|
|
"get_secure_key",
|
|
"pc_login",
|
|
]
|