1

我知道Cyber​​source在这里不是很熟悉,但我真的遇到了一些问题,也许有人可以帮助我。

我试过Cyber​​source 支持中心,但显然他们不支持测试帐户。

我有以下代码,我试图在其中执行对 Cyber​​source 的发布请求:

private async void Confirm_Payment(object sender, EventArgs e)
{
    var randomGuid = Guid.NewGuid().ToString();
    var currentDateTime = GetUTCDateTime();
    var referenceNumber = "1594706148080";

    using (var client = new HttpClient())
    {
        using (var content = new MultipartFormDataContent())
        {
            var values = new Dictionary<string, string>
            {
                {"access_key", "ACCESS_KEY"},
                {"profile_id", "PROFILE_ID"},
                {"transaction_uuid", randomGuid},
                {"signed_field_names", "access_key,profile_id,transaction_uuid,signed_field_names,unsigned_field_names,signed_date_time,locale,transaction_type,reference_number,amount,currency"},
                {"unsigned_field_names", ""},
                {"signed_date_time", currentDateTime},
                {"locale", "en"},
                {"transaction_type", "authorization"},
                {"reference_number", referenceNumber},
                {"amount", "100.00"},
                {"currency", "USD"},
                {"submit", "Submit"}
            };
            var signature = Security.Sign(values);
            foreach (var keyValuePair in values)
            {
                content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
            }

            content.Add(new StringContent(signature), "signature");
            var requestUri = "https://testsecureacceptance.cybersource.com/pay";
            var result = await client.PostAsync(requestUri, content);
            if (result.IsSuccessStatusCode)
            {
                var resp = await result.Content.ReadAsStringAsync();
                await Navigation.PushAsync(new WebScreen(requestUri));
            }
        }
    }
}

result.IsSuccessStatusCode200 OK,但每当我await result.Content.ReadAsStringAsync();得到一个会话超时页面

请注意,.NET 中的相同代码运行良好:

<form id="payment_confirmation" action="https://testsecureacceptance.cybersource.com/pay" method="post">
    <fieldset id="confirmation">
        <legend>Review Payment Details</legend>
        <div>
            <%
                foreach (var key in Request.Form.AllKeys)
                {
                    Response.Write("<div>");
                    Response.Write("<span class=\"fieldName\">" + key + ":</span><span class=\"fieldValue\">" + Request.Params[key] + "</span>");
                    Response.Write("</div>");
                }
    %>
        </div>
    </fieldset>
    <%
        IDictionary<string, string> parameters = new Dictionary<string, string>();
        foreach (var key in Request.Form.AllKeys)
        {
            Response.Write("<input type=\"hidden\" id=\"" + key + "\" name=\"" + key + "\" value=\"" + Request.Params[key] + "\"/>\n");
            parameters.Add(key, Request.Params[key]);
        }
        Response.Write("<input type=\"hidden\" id=\"signature\" name=\"signature\" value=\"" + secureacceptance.Security.Sign(parameters) + "\"/>\n");
%>
    <input type="submit" id="submit" value="Confirm" />
</form>

我试图采用相同的代码并执行它,Xamarin Forms但它没有用。

我认为问题在于我们应该添加特定的标头以让Cyber​​source 网关不会出现会话超时问题。有谁知道可能是什么问题?

4

1 回答 1

2

我不知道是否有人会遇到这个问题,但我通过向Webview

即使在 中导航Webview也会引发相同的错误(Session Timeout)。但是这个问题是通过添加以下代码来解决的:

var domain = new Uri(webSource.BaseUrl).Host;
var cookie = new Cookie
{
    Secure = true,
    Expired = false,
    HttpOnly = false,
    Name = "cookie",
    Expires = DateTime.Now.AddDays(10),
    Domain = domain,
    Path = "/"
};
cookies.Add(cookie);
paymentWebView.Cookies = cookies;
于 2020-07-16T11:22:50.843 回答