本節將進行完整的虛擬訂單請求發送
def get_order(shop_no, need_pay, return_url, backend_url, hash_a1, hash_a2, hash_b1, hash_b2):
url = 'https://sandbox.sinopac.com/QPay.WebAPI/api/Order'
origin_message = {
'ShopNo': shop_no,
'OrderNo': get_order_no(need_pay),
'Amount': 500 * 100,
'CurrencyID': 'TWD',
'PayType': 'A',
'ATMParam': {
'ExpireDate': '20210929'
},
'CardParam': {},
'PrdtName': '虛擬帳號訂單',
'ReturnURL': return_url,
'BackendURL': backend_url
}
origin_json_message = json.dumps(origin_message, ensure_ascii=False, separators=(',', ':'))
print(origin_json_message)
hash_id = get_hash_id(hash_a1, hash_a2, hash_b1, hash_b2)
nonce = get_nonce(shop_no)
sign = get_sign(origin_json_message, nonce, hash_id)
messge = get_message(hash_id, origin_json_message, get_iv(nonce))
print(messge)
reqest_body = {
'Version': '1.0.0',
'ShopNo': shop_no,
'APIService': 'OrderCreate',
'Sign': sign,
'Nonce': nonce,
'Message': messge
}
r = requests.post(url=url, json=reqest_body)
return r.json()
shop_no = 'NA0249_001'
hash_a1 = '86D50DEF3EB7400E'
hash_a2 = '01FD27C09E5549E5'
hash_b1 = '9E004965F4244953'
hash_b2 = '7FB3385F414E4F91'
need_pay = True
order_url = 'https://sandbox.sinopac.com/QPay.WebAPI/api/Order'
return_url = 'http://10.11.22.113:8803/QPay.ApiClient/Store/Return'
backend_url = 'http://10.11.22.113:8803/QPay.ApiClient/AutoPush/PushSuccess'
將收到的response print出來
print(get_order(shop_no, need_pay, return_url, backend_url, hash_a1, hash_a2, hash_b1, hash_b2))
結果如下
E3501 – 訊息內容錯誤
繼續盤查是什麼問題