|
@@ -70,6 +70,21 @@ class ShopifyMultipass:
|
|
|
# 返回响应的JSON数据
|
|
|
return response.json()
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def get_timezone_by_country(iso2):
|
|
|
+ timezone_map = {
|
|
|
+ "us": "America/New_York", # 美国时区(例如:纽约)
|
|
|
+ "jp": "Asia/Tokyo", # 日本时区
|
|
|
+ "de": "Europe/Berlin", # 德国时区
|
|
|
+ "uk": "Europe/London", # 英国时区
|
|
|
+ "eu": "Europe/Paris", # 欧盟时区(默认设为法国巴黎)
|
|
|
+ }
|
|
|
+ # 获取当前时间并格式化时间戳
|
|
|
+ now = datetime.now(pytz.timezone(timezone_map[iso2]))
|
|
|
+ timestamp = now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
|
|
+ timestamp = timestamp[:-2] + ':' + timestamp[-2:]
|
|
|
+ return timestamp
|
|
|
+
|
|
|
|
|
|
class ShopifyView(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
@@ -129,55 +144,82 @@ class ShopifyView(View):
|
|
|
if not check_password(password, users['password']):
|
|
|
return response.json(111)
|
|
|
|
|
|
- # 获取当前时间并格式化时间戳
|
|
|
- now = datetime.now(pytz.timezone('America/New_York'))
|
|
|
- timestamp = now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
|
|
- timestamp = timestamp[:-2] + ':' + timestamp[-2:]
|
|
|
-
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
-
|
|
|
# 根据条件选择配置键
|
|
|
- if shopify_country and shopify_country != "us":
|
|
|
+ if shopify_country:
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country(shopify_country)
|
|
|
secret_key = f"{shopify_country}_multipass_secret"
|
|
|
- store_name_key = f"{shopify_country}_store_name"
|
|
|
- elif shopify_country == "us":
|
|
|
- secret_key = "us_multipass_secret"
|
|
|
multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ if shopify_country == "eu":
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
+ return response.json(0, redirect_url)
|
|
|
+ elif shopify_country == "uk":
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
+ return response.json(0, redirect_url)
|
|
|
+ else:
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.{shopify_country}/account/login/multipass/{token}"
|
|
|
+ return response.json(0, redirect_url)
|
|
|
+ elif account_iso2 in ["de", "jp"]:
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country(account_iso2)
|
|
|
+ secret_key = f"{shopify_country}_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
+ redirect_url = f"https://www.zositech.{shopify_country}/account/login/multipass/{token}"
|
|
|
return response.json(0, redirect_url)
|
|
|
- elif account_iso2 == "jp":
|
|
|
- secret_key = "jp_multipass_secret"
|
|
|
- store_name_key = "jp_store_name"
|
|
|
- elif account_iso2 == "de":
|
|
|
- secret_key = "de_multipass_secret"
|
|
|
- store_name_key = "de_store_name"
|
|
|
elif account_iso2 == "uk":
|
|
|
- secret_key = "uk_multipass_secret"
|
|
|
- store_name_key = "uk_store_name"
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country(account_iso2)
|
|
|
+ secret_key = f"{shopify_country}_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
+ return response.json(0, redirect_url)
|
|
|
elif CONFIG_INFO == CONFIG_EUR:
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country("eu")
|
|
|
secret_key = "eu_multipass_secret"
|
|
|
- store_name_key = "eu_store_name"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
+ return response.json(0, redirect_url)
|
|
|
elif CONFIG_INFO == CONFIG_US:
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country("us")
|
|
|
secret_key = "us_multipass_secret"
|
|
|
multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
return response.json(0, redirect_url)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
- # 获取配置并生成重定向URL
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- store_name = SHOPIFY_CONFIG[store_name_key]
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://{store_name}.zositech.com/account/login/multipass/{token}"
|
|
|
-
|
|
|
- return response.json(0, redirect_url)
|
|
|
-
|
|
|
@staticmethod
|
|
|
def shopify_register(request_dict, response):
|
|
|
email = request_dict.get("email", None)
|