无法将用户重定向到支付网关的付款页面? [英] Unable to redirect user to payment page of the payment gateway?
问题描述
c# - 在MVC中使用PayUMoney集成并使用ajax调用 - Stack Overflow [ ^ ]
i面临同样的问题以上链接。
如此受尊敬的会员提供您的建议和帮助。
感谢您提前的帮助
我尝试过:
网关提供的代码在asp.net中提供,我想在mvc中使用它
当我在mvc中使用此代码时
Page.Controls.Add(new LiteralControl(strForm)); //此行给出错误。
公共字符串Generatehash512(字符串文本)
{
byte [ ] message = Encoding.UTF8.GetBytes(text);
UnicodeEncoding UE = new UnicodeEncoding();
byte [] hashValue;
SHA512Managed hashString = new SHA512Managed();
string hex =;
hashValue = hashString.ComputeHash(message);
foreach(hashValue中的字节x)
{
hex + = String.Format({0:x2},x);
}
返回十六进制;
}
public string Generatetxnid()
{
随机rnd = new Random();
string strHash = Generatehash512(rnd.ToString()+ DateTime。现在);
返回strHash.ToString()。子串(0,20);
}
[HttpPost]
public void demo(string amt,string name,string emaill,string phno,string prod)
{
string firstName = name;
string amount = amt;
string productInfo = prod;
string email = emaill;
string phone = phno;
string key =;
string salt =;
string txnid = Generatetxnid();
string hashString = key +| + txnid +| +金额+| + productInfo +| + firstName +| +电子邮件+||||||||||| + salt;
string hash = Generatehash512(hashString).ToLower();
System.Collections.Hashtable data = new System.Collections.Hashtable(); //在gash表中为数据post添加值
data.Add(hash,hash);
data.Add(txnid,txnid);
data.Add(key,key);
data.Add(amount,amount);
data.Add(firstname ,名称);
data.Add(email,email);
data.Add(phone,phone);
data.Add(productinfo,productInfo);
data.Add(surl,http:// localhost:61818 / Default / Sucess);
data.Add(furl,http:// localhost:61818 /默认/失败);
data.Add(service_provider,payu_paisa);
action1 =https://sandboxsecure.payu.in/_payment;
string strForm = PreparePOSTForm(action1,data);
// Page.Controls .Add(new LiteralControl(strForm)); //给出错误
}
私有字符串PreparePOSTForm(字符串url,Sy stem.Collections.Hashtable data)//发表表格
{
//设置表格的名称
string formID =PostForm ;
//使用要发布的指定数据构建表单。
StringBuilder strForm = new StringBuilder();
strForm.Append( );
foreach(数据中的System.Collections.DictionaryEntry键)
{
strForm.Append();
}
strForm.Append();
// Build将执行发布操作的JavaScript。
StringBuilder strScript = new StringBuilder();
strScript.Append();
strScript .Append(var v+ formID += document。+
formID +;);
strScript.Append(v+ formID + 。提交() ;);
strScript.Append();
//返回表格和连接的脚本。
//(顺序很重要,Form然后JavaScript)
返回strForm.ToString()+ strScript.ToString();
}
}
MVC不使用控制树;你只需要将原始HTML返回给用户:
[HttpPost]
public ActionResult演示(字符串 amt,字符串名称,字符串 emaill, string phno, string prod)
{
...
string strForm = PreparePOSTForm(action1,data);
return 内容(strForm,System.Net.Mime.MediaTypeNames.Text.Html);
}
dear sir/madam
c# - PayUMoney Integration in MVC and calling using ajax - Stack Overflow[^]
i am facing the same problem mentioned in the above link.
so respected members provider your advice and help.
thanks for your help in advance
What I have tried:
the gateway provide have provide the code in asp.net and i wanted to use it in mvc
when i use this code in mvc
Page.Controls.Add(new LiteralControl(strForm));//this line give me error.
public string Generatehash512(string text)
{
byte[] message = Encoding.UTF8.GetBytes(text);
UnicodeEncoding UE = new UnicodeEncoding();
byte[] hashValue;
SHA512Managed hashString = new SHA512Managed();
string hex = "";
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex;
}
public string Generatetxnid()
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
return strHash.ToString().Substring(0, 20);
}
[HttpPost]
public void demo(string amt, string name, string emaill, string phno, string prod)
{
string firstName = name;
string amount = amt;
string productInfo = prod;
string email = emaill;
string phone = phno;
string key = "";
string salt = "";
string txnid = Generatetxnid();
string hashString = key + "|" + txnid + "|" + amount + "|" + productInfo + "|" + firstName + "|" + email + "|||||||||||" + salt;
string hash = Generatehash512(hashString).ToLower();
System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
data.Add("hash", hash);
data.Add("txnid", txnid);
data.Add("key", key);
data.Add("amount", amount);
data.Add("firstname", name);
data.Add("email", email);
data.Add("phone", phone);
data.Add("productinfo", productInfo);
data.Add("surl", "http://localhost:61818/Default/Sucess");
data.Add("furl", "http://localhost:61818/Default/Failure");
data.Add("service_provider", "payu_paisa");
action1 = "https://sandboxsecure.payu.in/_payment";
string strForm = PreparePOSTForm(action1, data);
// Page.Controls.Add(new LiteralControl(strForm));//Giving Error
}
private string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form
{
// Set a name for the form
string formID = "PostForm";
// Build the form using the specified data to be posted.
StringBuilder strForm = new StringBuilder();
strForm.Append("");
foreach (System.Collections.DictionaryEntry key in data)
{
strForm.Append("");
}
strForm.Append("");
// Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("");
// Return the form and the script concatenated.
// (The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
}
MVC doesn't use a control tree; you just need to return the raw HTML to the user:
[HttpPost] public ActionResult demo(string amt, string name, string emaill, string phno, string prod) { ... string strForm = PreparePOSTForm(action1, data); return Content(strForm, System.Net.Mime.MediaTypeNames.Text.Html); }
这篇关于无法将用户重定向到支付网关的付款页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!