[day10]串接API实测-订单建置API

订单建置API设定

  • 建立预计导入API的参数清单
class ApiSource(BaseModel):
    householder:str 
    Amount:int #配合规格,自动补上小数点後两位00
    OrderNo:str
    PayType:str
  • 订单建置API

    • 程序
    @app.post("/sinopacApi_Order", summary="永丰建置订单API" )# , response_model=ApiResultGet
    async def sinopacApi_Order(apiparams: ApiSource):
        start = time.time()
        # ShopNo 由主办单位提供,此处示例以 xxx 取代
        Shop_No = {'ShopNo':"NAxxx_001"}
        NonceValue=getNonce(Shop_No)
    
        SHAValue ,IVValue= getSHAValue(NonceValue)
    
        hashID = getAESKey()
    
        lastDate= datetime.date.today() + datetime.timedelta(days=1)
        print("lastDate",str(lastDate).replace("-",""))
        print("apiparams.PayType => ",apiparams.PayType)
        OrderNo_total=apiparams.PayType+"_"+apiparams.OrderNo+"_"+str(datetime.datetime.now().timestamp())
        if apiparams.PayType=="A":
            send_message_ori = {
            "ShopNo": Shop_No["ShopNo"],
            "OrderNo": OrderNo_total,
            "Amount": apiparams.Amount*100,
            "CurrencyID": "TWD",
            "PayType": apiparams.PayType, #管理费仅用汇款,无信用卡缴费模式
            "ATMParam": {"ExpireDate":str(lastDate).replace("-","")},
            "CardParam": {},
            "ConvStoreParam": {},
            "PrdtName": "order",
            "Param1": apiparams.householder,  
            "Param2": apiparams.OrderNo,     
            "ReturnURL": "http://10.11.22.113:8803/QPay.ApiClient/Store/Return",
            "BackendURL": "http://10.11.22.113:8803/QPay.ApiClient/AutoPush/PushSuccess",
        }
    
    
        elif apiparams.PayType=="C":
            send_message_ori = {
            "ShopNo": Shop_No["ShopNo"],
            "OrderNo": OrderNo_total,
            "Amount": apiparams.Amount*100,
            "CurrencyID": "TWD",
            "PayType": apiparams.PayType, #管理费仅用汇款,无信用卡缴费模式
            "ATMParam": {},
            "CardParam": {"AutoBilling":"Y"},
            "ConvStoreParam": {},
            "PrdtName": "order",
            "Param1": apiparams.householder,  
            "Param2": apiparams.OrderNo,     
            "ReturnURL": "http://10.11.22.113:8803/QPay.ApiClient/Store/Return",
            "BackendURL": "http://10.11.22.113:8803/QPay.ApiClient/AutoPush/PushSuccess",
            }
    
        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)
    
        send_POST_message={
          "Version": "1.0.0",
          "ShopNo": Shop_No["ShopNo"],
          "APIService": "OrderCreate",
          "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_json => ',r.json())
        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测试。
      1. ATM汇款
        • 设定
          https://ithelp.ithome.com.tw/upload/images/20210924/20140924J7AedjgSYJ.png

        • 执行结果
          以下为执行结果,主要得到的资讯为查询完成("Description": "S0000 – 处理成功"),同时也可以得到汇款帐,提供客户直接使用ATM汇入费用。
          https://ithelp.ithome.com.tw/upload/images/20210924/20140924wB2tQb696Q.png

      2. 信用卡汇款
        • 设定
          https://ithelp.ithome.com.tw/upload/images/20210924/20140924xoFL7Z9VPw.png
        • 执行结果
          从得到的资讯中,可以得到信用卡缴费网址
          https://ithelp.ithome.com.tw/upload/images/20210924/20140924bxUkUXH1YK.png
          测试输入规格书提供的卡号跟相关资讯资讯,即可线上刷卡
          https://ithelp.ithome.com.tw/upload/images/20210924/20140924Ezm3s3AcBC.png

订单建立之後,就是要来查看缴费纪录罗~明天见


<<:  Day 22.5 | Livewire 实作 购物网站: 建立资料表

>>:  【Day10】模组化及引用模组

22 - Commitizen - 产生合法的 Commit 讯息

针对 commit 讯息的规范,最为人熟知的是 Angular 的 Commit Message F...

番外篇(2)一起来做 To Do List!- 实作篇(2)

大家新年快乐!上一篇完成後还剩下这些功能: 可以一次删除全部的代办事项 能删除所有已完成的代办事项的...

Visual studio 2019 使用AddressSanitizer检查程序码

AddressSanitizer (ASan) 是一种编译器和执行时间技术,会以 零 误报来公开许多...

Day8:原来机器学习这个词跟我想的不太一样

  这几天研究下来,发现有三个词汇很让人搞不懂,也就是人工智慧(Artifical Intellig...

远端系列-5:如何拉回远端数据库的档案?

角色情境 小明同时学会输入指令操作着终端机、 以及透过滑鼠操作着图像化介面的 Sourcetree ...