如何通過 POST 請求將用戶重定向到外部站點,使用 backend-asp.net core web api 或 frontend-angular 哪個更好?
我正在使用支付網關。為了確認 3D 安全,我需要將用戶重定向到一個新的 url。
檔案說像這樣使用表單,
<form
id="pa-form"
method="post"
action="https://test.sagepay.com/mpitools/accesscontroler?action=pareq"
>
<input
type="hidden"
name="PaReq"
value="eJxVUstugzAQvPcrEB AHwTiRBtHaXMIqlrRJlJ7tYzVoIIhBgL5 9oJNK1PM PV7HrWsB7Kwjsr0 SVXvkkwP6aP8DhaJTa7pXsjOLwoppGfCkvz1Y xSQO53GIWcgYwTHDM59DunlXJw6jD7c2AQE0UWtg5FHoloOQp8fklc8WdIExoJFCqUyy5SSibL5geDyAbjJoUSqe7g5GnFXRir4yRXasijwTgK53IKtOt bCGY0BTQQ6U/C 7wM3fC0ugayC7huQkwHdZ0o7hxprM QZT98SfaBVHX0878PPbBeJ4YI2eggZXgFyFZCJVnGKKSGEhh4mSzpfEgboqoMoXX8eR/Z5Nwi167C563852IyN0nIafmKghrrSylZQQL8YMtVIvnfbSMXFe0kT29ZJgO7PeNq5oGXrInUZX5Hzy20qNMQ3Q0cAuVo0rg Ni7bo3wf4AWyps7I="
/>
<input
type="hidden"
name="TermUrl"
value="http://localhost:4200/payment"
/>
<input type="hidden" name="MD" value="FAD0DBBA-FC72-2D9A-F09F-D4D6FFFCB2CD" />
</form>
// in index.html
<script>document.addEventListener("DOMContentLoaded",function(){var b=document.getElementById("pa-form");b&&b.submit()})</script>
但是我在角度上嘗試了這種形式。我得到了Cannot POST / 回應。
所以我搜索了這個,有人說angular is not able to handle third-party responses.那么我該怎么做?如何使用 asp .net core 或 angular 執行上述表單。
我不清楚我該怎么辦?
請指導我。如何使用 asp .net core 和 angular
uj5u.com熱心網友回復:
簡要概述:對于單頁的應用程式(Angular),你應該不會,如果你將用戶重定向處理客戶端上的第三方回應。因為每次應用程式重定向到第三方時,所有背景關系都會丟失,并且在回傳時,Angular 應用程式將再次引導。
解決方案: 在架構方面,可以采用如下方式:
當用戶單擊您網站上的立即付款按鈕時
PaReq,獲取所有與網關相關的密鑰,例如TermUrl等(HttpClient請求可以呼叫您的后端 API 以獲取網關配置)。例子:{ keys: [ { name: "PaReq", value: "eJxVUstugzAQvPcrEB AHwTiRBtHaXMIqlrRJ", }, //... Rest of the keys ], };獲取網關配置后創建動態表單
let f = document.createElement("form"); f.setAttribute("method", "post"); f.setAttribute( "action", "https://test.sagepay.com/mpitools/accesscontroler?action=pareq" ); //Your action URL //create hidden input elements config.keys.forEach((item) => { let i = document.createElement("input"); i.type = "hidden"; i.name = item.name; i.value = item.value; f.appendChild(i); //Add it to the form }); document.body.appendChild(f);//Add the form to the body f.submit(); //Submit it immediately現在用戶將被重定向到支付網關。支付網關要求
callback URL他們用來將支付結果傳遞給您的后端。創建一個 API(假設api/callback)來處理來自網關的支付回應。最后,
api/callback您可以將回應存盤在資料庫中,并根據付款成功/失敗,將用戶重定向回您的Angular應用程式,并將付款 ID 作為引數。https://youapp.com/payment/123456/success
在這里,我們在 Angular 應用程式中定義了一個路由,它帶有payment2 個路由引數
path: 'payment/:paymentId/:result'
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/364459.html
標籤:有角的 重定向 asp.net-web-api 支付网关 欧巴约
