跳至主要內容
iRoamly Shop

購買兌換碼(Python)

購買兌換碼 的完整 Python 請求,包含 AuthKey 與 Certification 標頭。請將預留的 AuthKey 與 AuthSecret 替換為您 API 金鑰頁面上的值。

程式碼參考

購買兌換碼(Python)

python
import requests
import json
import hashlib

# URL for the request
url = "https://api.iroamly.shop/openapi/purchaseCode"

# Provided AuthKey and AuthSecret, remember to replace them with real values
auth_key = "YOUR_AUTH_KEY_HERE"
auth_secret = "YOUR_AUTH_SECRET_HERE" 


# Calculating Certification
combined = auth_key + auth_secret
certification = hashlib.sha256(combined.encode()).hexdigest()

# Header parameters for the request
headers = {
    "Content-Type": "application/json",
    "AuthKey": auth_key,
    "Certification": certification
}

# Example data for the request body
data = {
    "email": "2m827n32d@gmail.com",
    "productList": [
        {
            "productCode": "m8hed7h2fed2398dsnh",
            "quantity": 2
        },
        {
            "productCode": "cn88beg9edjdfj2sj0a",
            "quantity": 1
        }
    ]
}

# Sending POST request
response = requests.post(url, headers=headers, data=json.dumps(data))

# Printing the response content
print(response.text)

# Example of response
{
    "code":1,
    "msg":"success",
    "orderId":"xxx-xxxx-sd9hn8df333"
}
API 端點

購買兌換碼

請求 URL:https://api.iroamly.shop/openapi/purchaseCode
請求方法:POST

請求參數:

參數說明類型
email電子郵件String
productList產品集合Object[]

productList 欄位:

欄位說明類型
plan方案名稱。請提供 plan 或 productCode 其中之一。String
productCode方案 ID(取自「取得區域方案清單」的 productCode)。請提供 productCode 或 plan 其中之一。String
quantity數量Int
測試方案:iRoamly-Test-10GB
參數範例
{
  "email": "2m827n32d@gmail.com",
  "productList": [
    {
      "plan": "United States-eSIM-10GB-10 Days-Total",
      "quantity": 2
    },
    {
      "plan": "Albania-10GB-15 Days-Total",
      "quantity": 1
    }
  ]
}
回傳範例
{
  "code": 1,
  "msg": "success",
  "orderId": "xxx-xxxx-sd9hn8df333" // Order number, can be used to query redeem code
}
程式碼參考

更多 Python 範例