92 lines
4.0 KiB
Python
92 lines
4.0 KiB
Python
import uuid
|
|
import random
|
|
from curl_cffi import requests # 用于模拟指纹
|
|
|
|
from config import STRIPE_PK, get_proxy
|
|
from identity import random_address, random_name
|
|
|
|
|
|
class StripeTokenizer:
|
|
def __init__(self, user_agent):
|
|
self.user_agent = user_agent
|
|
self.guid = f"{uuid.uuid4()}0a75cf"
|
|
self.muid = f"{uuid.uuid4()}1d4c1f"
|
|
self.sid = f"{uuid.uuid4()}eb67c4"
|
|
self.client_session_id = str(uuid.uuid4())
|
|
self.elements_session_config_id = str(uuid.uuid4())
|
|
|
|
def get_token(self, cc_num, exp_m, exp_y, cvc):
|
|
"""与 Stripe 交互获取 pm_id"""
|
|
url = "https://api.stripe.com/v1/payment_methods"
|
|
|
|
headers = {
|
|
"Host": "api.stripe.com",
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
"Sec-Ch-Ua-Platform": '"Linux"',
|
|
"User-Agent": self.user_agent,
|
|
"Accept": "application/json",
|
|
"Sec-Ch-Ua": '"Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
"Sec-Ch-Ua-Mobile": "?0",
|
|
"Origin": "https://js.stripe.com",
|
|
"Sec-Fetch-Site": "same-site",
|
|
"Sec-Fetch-Mode": "cors",
|
|
"Sec-Fetch-Dest": "empty",
|
|
"Referer": "https://js.stripe.com/",
|
|
"Accept-Encoding": "gzip, deflate, br",
|
|
"Accept-Language": "zh-CN,zh;q=0.9",
|
|
"Priority": "u=1, i"
|
|
}
|
|
|
|
# 构造完整的 form-data
|
|
time_on_page = random.randint(30000, 500000)
|
|
addr = random_address()
|
|
name = random_name()
|
|
|
|
data = {
|
|
"type": "card",
|
|
"card[number]": cc_num,
|
|
"card[cvc]": cvc,
|
|
"card[exp_year]": exp_y[-2:] if len(exp_y) == 4 else exp_y,
|
|
"card[exp_month]": exp_m,
|
|
"allow_redisplay": "unspecified",
|
|
"billing_details[address][postal_code]": addr["postal_code"],
|
|
"billing_details[address][country]": addr["country"],
|
|
"billing_details[address][line1]": addr["line1"],
|
|
"billing_details[address][city]": addr["city"],
|
|
"billing_details[address][state]": addr["state"],
|
|
"billing_details[name]": name,
|
|
"billing_details[phone]": "",
|
|
"payment_user_agent": "stripe.js/5766238eed; stripe-js-v3/5766238eed; payment-element; deferred-intent; autopm",
|
|
"referrer": "https://claude.ai",
|
|
"time_on_page": str(time_on_page),
|
|
"client_attribution_metadata[client_session_id]": self.client_session_id,
|
|
"client_attribution_metadata[merchant_integration_source]": "elements",
|
|
"client_attribution_metadata[merchant_integration_subtype]": "payment-element",
|
|
"client_attribution_metadata[merchant_integration_version]": "2021",
|
|
"client_attribution_metadata[payment_intent_creation_flow]": "deferred",
|
|
"client_attribution_metadata[payment_method_selection_flow]": "automatic",
|
|
"client_attribution_metadata[elements_session_config_id]": self.elements_session_config_id,
|
|
"client_attribution_metadata[merchant_integration_additional_elements][0]": "payment",
|
|
"client_attribution_metadata[merchant_integration_additional_elements][1]": "address",
|
|
"guid": self.guid,
|
|
"muid": self.muid,
|
|
"sid": self.sid,
|
|
"key": STRIPE_PK,
|
|
"_stripe_version": "2025-03-31.basil"
|
|
}
|
|
|
|
try:
|
|
print(f"[*] 正在向 Stripe 请求 Token: {cc_num[:4]}******{cc_num[-4:]}")
|
|
resp = requests.post(url, data=data, headers=headers, impersonate="chrome124", proxies=get_proxy())
|
|
|
|
if resp.status_code == 200:
|
|
pm_id = resp.json().get("id")
|
|
print(f"[+] Stripe Token 获取成功: {pm_id}")
|
|
return pm_id
|
|
else:
|
|
print(f"[-] Stripe 拒绝: {resp.text}")
|
|
return None
|
|
except Exception as e:
|
|
print(f"[-] Stripe 连接错误: {e}")
|
|
return None
|