From a4fe8208d9085ecbf03c1f1c7a12d26fde9128ea Mon Sep 17 00:00:00 2001
From: 91c0e59d-6161-45ab-8aa4-2371574db28f
 <91c0e59d-6161-45ab-8aa4-2371574db28f@bankofchina.com>
Date: Sat, 25 Jan 2025 10:40:43 +0800
Subject: [PATCH] use httpx instead of requests

---
 requirements.txt |  2 +-
 sdga/authv1.py   | 16 ++++++----------
 sdga/sdgb.py     | 21 ++++++++++-----------
 sdgb/sdgb.py     |  5 ++---
 4 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index e1f0834..a2e161f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-requests
+httpx
 pycryptodome
 pytz
\ No newline at end of file
diff --git a/sdga/authv1.py b/sdga/authv1.py
index 09057bd..ea198f4 100644
--- a/sdga/authv1.py
+++ b/sdga/authv1.py
@@ -1,24 +1,22 @@
 import base64
-import urllib3
 import zlib
 import re
+import httpx
 
 def DownloadOrder():
     ua = 'Windows/3.0'
     content = b'game_id=SDGA&ver=1.50&serial=A63E01E0048&encode=UTF-8'
     body = base64.b64encode(zlib.compress(content))
-    http = urllib3.PoolManager()
-    r = http.request(
-        'POST',
+    r = httpx.post(
         'http://naominet.jp/sys/servlet/DownloadOrder',
-        body = body,
+        data = body,
         headers = {
             'Pragma': 'DFI',
             'User-Agent': ua,
             'Content-Type': 'application/x-www-form-urlencoded',
         }
     )
-    resp_data = r.data
+    resp_data = r.content
     response = zlib.decompress(base64.b64decode(resp_data)).decode()
     return response
 
@@ -26,15 +24,13 @@ def uri():
     data = DownloadOrder()
     pattern = r"https://[^\s]+"
     endpoint = re.search(pattern, data).group()
-    http = urllib3.PoolManager()
-    r = http.request(
-        'GET',
+    r = httpx.get(
         endpoint,
         headers = {
             'User-Agent': 'A63E01E0000',
         }
     )
-    resp_data = r.data
+    resp_data = r.content
     response = resp_data.decode()
     return response
 
diff --git a/sdga/sdgb.py b/sdga/sdgb.py
index c21d73a..3fdf0d1 100644
--- a/sdga/sdgb.py
+++ b/sdga/sdgb.py
@@ -2,7 +2,7 @@ import json
 import zlib
 import pytz
 import hashlib
-import requests
+import httpx
 
 from binascii import unhexlify, hexlify
 import socket
@@ -57,16 +57,15 @@ def sdgb_api(data, useApi, userId):
     data_def = zlib.compress(data)
     data_enc = aes.encrypt(data_def)
     endpoint = "https://mai2exp.sic-rd1.jp:42081/Maimai2Servlet/"
-    requests.packages.urllib3.disable_warnings()
-    r = requests.post(
+    r = httpx.post(
         endpoint + get_hash_api(useApi),
         headers = {
-            "User-Agent": "%s#%d"%(get_hash_api(useApi), userId), 
+            "User-Agent": "%s#%d"%(get_hash_api(useApi), userId),
             "Content-Type": "application/json",
             "Mai-Encoding": "1.51",
             "Accept-Encoding": "",
-            "Charset": "UTF-8", 
-            "Content-Encoding": "deflate", 
+            "Charset": "UTF-8",
+            "Content-Encoding": "deflate",
             "Expect": "100-continue"
         },
         data = data_enc
@@ -86,8 +85,8 @@ def felica(IDm):
     command_id = "0100" # ID = 1
     length = "3000" # 48
     gameId = "534447410000" # SDGA
-    storeId = "bc310000"
-    keychip_ID = "413633453031453032363400" # A63E01E0264
+    storeId = "aa1e0000"
+    keychip_ID = "413633453031453031383200" # A63E01E0264
     header = magic + version + command_id + length + "0000" + gameId + storeId + keychip_ID
 
     IDm = str(IDm)
@@ -113,7 +112,7 @@ def felica(IDm):
 
         decrypted_hex_stream = hexlify(decrypted_response).decode('utf-8')
 
-    return decrypted_hex_stream
+    return decrypted_hex_stream[-24:-4]
 
 def aimedb_api(accessCode):
     key = b'Copyright(C)SEGA'
@@ -123,8 +122,8 @@ def aimedb_api(accessCode):
     command_id = "0f00" # ID = 15
     length = "3000" # 48
     gameId = "534447410000" # SDGA
-    storeId = "bc310000"
-    keychip_ID = "413633453031453032363400" # A63E01E0264
+    storeId = "aa1e0000"
+    keychip_ID = "413633453031453031383200" # A63E01E0264
     header = magic + version + command_id + length + "0000" + gameId + storeId + keychip_ID
 
     access_code = str(accessCode)
diff --git a/sdgb/sdgb.py b/sdgb/sdgb.py
index 7242329..087aeae 100644
--- a/sdgb/sdgb.py
+++ b/sdgb/sdgb.py
@@ -3,7 +3,7 @@ import zlib
 import pytz
 import base64
 import hashlib
-import requests
+import httpx
 
 from datetime import datetime
 from Crypto.Cipher import AES
@@ -56,9 +56,8 @@ def sdgb_api(data, useApi, userId):
     data = data
     data_enc = aes.encrypt(data)
     data_def = zlib.compress(data_enc)
-    requests.packages.urllib3.disable_warnings()
     endpoint = "https://maimai-gm.wahlap.com:42081/Maimai2Servlet/"
-    r = requests.post(
+    r = httpx.post(
         endpoint + get_hash_api(useApi),
         headers = {
             "User-Agent": "%s#%d"%(get_hash_api(useApi), userId),