简体   繁体   English

远程服务器返回错误:(401) 未经授权。 在 Visa 开发支付网关

[英]The remote server returned an error: (401) Unauthorized. In Visa develope payment Gateway

I am getting an error while implementing visa cyber source using c# code and I have downloaded source code for that after creating a project but getting error may be x-pay-token was not generating correctly.我在使用 c# 代码实现签证网络源时遇到错误,我在创建项目后下载了源代码,但得到错误可能是 x-pay-token 没有正确生成。 Is there any way so I can verify my token or generate it with any API by passing parameter.有什么方法可以验证我的令牌或通过传递参数使用任何 API 生成它。 Below code, I am using下面的代码,我正在使用

string baseUri = "cybersource/";
string resourcePath = "v2/payments";

string xPayToken = GetXPayToken(resourcePath, "apikey=" + apikey, requestBodyString);static string GetXPayToken(string apiNameURI, string queryString, string requestBody)
{
    string timestamp = GetTimestamp();
    string sourceString = timestamp + apiNameURI + queryString + requestBody;
    string hash = GetHash(sourceString);
    string token = "xv2:" + timestamp + ":" + hash;
    return token;
} 

private static string GetHash(string data)
{
    string sharedSecret = ConfigurationManager.AppSettings["VisaPaySharedSecret"];
    var hashString = new HMACSHA256(Encoding.ASCII.GetBytes(sharedSecret));
    var hashbytes = hashString.ComputeHash(Encoding.ASCII.GetBytes(data));
    string digest = String.Empty;

    foreach (byte b in hashbytes)
    {

    }

    return digest;
}

This Iis the official Visa way to do it: https://developer.visa.com/pages/working-with-visa-apis/x-pay-token#sample_code_for_api_key__shared_secret_xpaytoken这是签证的官方方式: https : //developer.visa.com/pages/working-with-visa-apis/x-pay-token#sample_code_for_api_key__shared_secret_xpaytoken

private static string getTimestamp() {     
    long timeStamp = ((long) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds) / 1000;     
    return timeStamp.ToString(); 
}

private static string getHash(string data) {     
    var hashString = new HMACSHA256(Encoding.ASCII.GetBytes(SHARED_SECRET));     
    var hashbytes = hashString.ComputeHash(Encoding.ASCII.GetBytes(data));     
    string digest = String.Empty;    
    foreach (byte b in hashbytes) {         
         digest += b.ToString("x2");     
    }     
    return digest;
} 

private static string getXPayToken(string resourcePath, string queryString, string requestBody) {    
    string timestamp = getTimestamp();     
    string sourceString = timestamp + resourcePath + queryString  + requestBody;     
    string hash = getHash(sourceString);     
    string token = "xv2:" + timestamp + ":" + hash;     return token; 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(401) Unauthorized。 Twitter oAuth - The remote server returned an error: (401) Unauthorized. Twitter oAuth 远程服务器返回错误:(401)未经授权。 wcf httpbinding基本 - The remote server returned an error: (401) Unauthorized. wcf httpbinding basic C#JIRA工作日志更新错误“远程服务器返回错误:(401)未经授权。” - C# JIRA work-log update error “The remote server returned an error: (401) Unauthorized.” System.Net.WebException:远程服务器返回错误:(401)未经授权。 在System.Net.HttpWebRequest.GetResponse() - System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() SharePoint 仅应用程序身份验证抛出“远程服务器返回错误:(401)未经授权。” - SharePoint App-Only Authentication throwing “The remote server returned an error: (401) Unauthorized.” 为什么我收到“远程服务器返回错误:(401) 未经授权”。 从这个代码片段? - Why am I getting 'The remote server returned an error: (401) Unauthorized.' from this code snippet? 出现错误:远程服务器返回错误:(401)未经授权。 ,同时将我的网站评论发布到Twitter。 使用C# - Getting error : The remote server returned an error: (401) Unauthorized. , while posting my website comments to twitter. Using C# 错误远程服务器返回错误:(401)未经授权 - Error The remote server returned an error: (401) Unauthorized EWS:“远程服务器返回错误(401)未经授权” - EWS: “The remote server returned error (401) Unauthorized” 远程服务器返回错误:(401)未经授权 - The remote server returned an error: (401) Unauthorized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM