iT邦幫忙

2021 iThome 鐵人賽

DAY 2
1
永豐金融APIs

永豐Vue一下-從生活尋找靈感系列 第 11

[day11]串接API實測-訂單單筆查詢API

訂單單筆查詢API設定

使用者於費用繳交申請後,匯款或刷卡後,查詢費用繳交之相關紀錄。

  • 訂單建置API
    • 程式
    
    @app.post("/sinopacApi_OrderQuery_order", summary="永豐訂單查詢API(訂單編號查詢)" )# , response_model=ApiResultGet
    async def sinopacApi_Order(orderNo: str = "A_20210924_1632450255.946536"):
        start = time.time()
        # ShopNo 由主辦單位提供,此處示例以 xxx 取代
        Shop_No = {'ShopNo':"NAXXX_001"}
        NonceValue=getNonce(Shop_No)
        SHAValue ,IVValue= getSHAValue(NonceValue)
    
        hashID = getAESKey()
    
        send_message_ori = {
        "ShopNo": Shop_No["ShopNo"],
        "OrderNo": orderNo,
        "PayDateTimeS":"",
        "PayDateTimeE":"",
        "PayFlag": ""
        }
    
        print('send_message_ori => ',send_message_ori)
    
        send_message_TextHash=getMessageTextHash(send_message_ori,NonceValue,hashID)
    
        SignValue = getSignValue(send_message_TextHash)
    
        jsonText=json.dumps(send_message_ori, ensure_ascii=False).replace(' ', "")
        print(jsonText)
        aes_encrypt_str = AES_CBC_Encrpt(hashID, IVValue, jsonText)
        print(f'加密結果為: {aes_encrypt_str}')
    
        send_POST_message={
        "Version": "1.0.0",
        "ShopNo": Shop_No["ShopNo"],
        "APIService": "OrderQuery",
        "Sign": SignValue,
        "Nonce": NonceValue,
        "Message": aes_encrypt_str
        }
    
        print('send_POST_message => ',send_POST_message)
        requests_link = 'https://apisbx.sinopac.com/funBIZ/QPay.WebAPI/api/Order'    
        r = requests.post(url = requests_link, json = send_POST_message )
        print('status_code => ',r.status_code)
        print('status_Nonce => ',r.json()["Nonce"])
    
        NonceValue=r.json()["Nonce"]
        SHAValue ,IVValue= getSHAValue(NonceValue)
        hashID = getAESKey()
        aes_decrypt_str = AES_CBC_Decrypt(hashID, iv=IVValue, data=r.json()["Message"])
    
        print(f'解密結果為: {aes_decrypt_str}')
        decrypt_dist=json.loads(aes_decrypt_str)
        r.close()
    
        return {"message": "success", 'time': time.time() - start ,"decrypt_dist" : decrypt_dist}
    
    
    • 執行
    uvicorn app.main:app --host 0.0.0.0 --port 80
    
    • 測試
      直接使用fastapi自建的swagger測試。
      • 設定
        以訂單A_20210924_1632450255.946536為例,參數為A_20210924_1632450255.946536,設定如下
        https://ithelp.ithome.com.tw/upload/images/20210925/20140924rJd5JUqHOX.png

      • 執行結果
        以下為執行結果,主要得到的資訊為建立訂單程序為處理成功,訂單狀態為1A400,表示已經匯款完成了。
        https://ithelp.ithome.com.tw/upload/images/20210925/201409241fRVUgLYW8.png

今天做完訂單狀態的查詢,明天要做整批的訂單查詢,固定每日從永豐服務抓回歷史訂單資訊。


上一篇
[day10]串接API實測-訂單建置API
下一篇
[day12]串接API實測-永豐訂單查詢API(日期查詢)
系列文
永豐Vue一下-從生活尋找靈感30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言