实现WireCard支付,暂未完成

WireCardController.cs

 using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc; namespace Payment
{
public class WireCardController : Controller
{
/// <summary>
/// 创建表单支付
/// 使用 WireCard 的HPP(Host Payment Page)支付方式
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
var reqFormData = new NameValueCollection();
//表单数据
reqFormData.Add("request_time_stamp", DateTime.UtcNow.ToString("yyyyMMddHHmmss")); //支付时间:人家指定要UtcNow
reqFormData.Add("request_id", Guid.NewGuid().ToString()); //请求编号
reqFormData.Add("merchant_account_id", "your_account_id"); //商户编号:WireCard帐号,等同支付宝帐号,用来打款
reqFormData.Add("transaction_type", "authorization");
reqFormData.Add("requested_amount", "100.00"); //付款金额
reqFormData.Add("requested_amount_currency", "CNY");
reqFormData.Add("redirect_url", "http://localhost/Payment/WireCard/Result"); //支付结果
reqFormData.Add("ip_address", "127.0.0.1"); // 本机外网IP:
reqFormData.Add("secret_key", "secret_key");
//数字签名,防止传输过程中数据被篡改
reqFormData.Add("request_signature",
getSHA256(
reqFormData["request_time_stamp"] +
reqFormData["request_id"] +
reqFormData["merchant_account_id"] +
reqFormData["transaction_type"] +
reqFormData["requested_amount"] +
reqFormData["requested_amount_currency"] +
reqFormData["redirect_url"] +
reqFormData["ip_address"] +
reqFormData["secret_key"]
)
);
reqFormData.Add("attempt_three_d", "true"); // With the 3D Secure
reqFormData.Add("card_type", "mastercard");
reqFormData.Add("notification_url_1", "http://127.0.0.1/Payment/WireCard/Notification"); //付款事务通知
reqFormData.Add("notification_transaction_state_1", "success"); //生成支付表单,自动并提交到付款平台入口
Response.Write(generalForm(reqFormData, "UTF-8", "https://testapi.ep2-global.com/engine/hpp/")); return null;
} /// <summary>
/// 收到支付事务通知
/// </summary>
/// <returns></returns>
public ActionResult Notification()
{
/*
* 服务端Java做的:
*
* 支付平台会包含三个事务步骤,
* 走完三个步骤才算完成支付,
* 期间会有三次 Notification
* 注:返回的状态在Header中,参考三次Headers[request_id]的值的变化,Form里没数据的
*
*/
return View();
} /// <summary>
/// 最终返回支付结果
/// </summary>
/// <returns></returns>
public ActionResult Result()
{
/*
* 最终返回的付款结果,相关支付详细信息都在Form里
*/ return View();
} /// <summary>
/// 加密
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private string getSHA256(string text)
{
byte[] hasValue;
byte[] message = Encoding.UTF8.GetBytes(text); var hashString = new SHA256Managed();
string hex = ""; hasValue = hashString.ComputeHash(message);
foreach (byte x in hasValue)
{
hex += String.Format("{0:x2}", x);
} return hex.Trim();
} /// <summary>
/// 生成Form表单
/// </summary>
/// <param name="collections">Form数据,NameValueCollection</param>
/// <param name="charset">字符类型</param>
/// <param name="PostUrl">付款平台的入口</param>
/// <returns></returns>
private string generalForm(NameValueCollection collections, string charset, string PostUrl)
{
var values = collections;
var html = new StringBuilder();
html.AppendLine("<html>").AppendLine("<head>");
html.AppendFormat("<meta http-equiv=\"Content-Type\" content=\"application/x-www-form-urlencoded; charset={0}\" />", charset).AppendLine();
html.AppendLine("<style type=\"text/css\">#pay_form { margin: 30px auto 0 auto; width: 700px; text-align: left; } label{ width:250px;} input{ width: 220px;}</style>");
html.AppendLine("</head>");
html.AppendLine("<body onload=\"\">"); //javascript:document.pay_form.submit();
//html.AppendLine("<div id=\"search_flight_loading\"><img src=\"/Content/img/oval.svg\" /></div>");
html.AppendFormat("<form id=\"pay_form\" name=\"pay_form\" action=\"{0}\" method=\"POST\">", PostUrl).AppendLine();
foreach (string k in values.AllKeys)
{
html.AppendFormat("<label for=\"{0}\">{0}</label>: <input type=\"text\" name=\"{0}\" id=\"{0}\" value=\"{1}\" readOnly=\"true\" /> <br/>", k, values[k]).AppendLine();
}
html.AppendLine("<input type=\"submit\" style=\"display:block;\" value=\"提交\" />");
html.AppendLine("</form>").AppendLine("</body>").AppendLine("</html>");
return html.ToString();
} }
}

最新文章

  1. .NET中Redis安装部署及使用方法简介附-&gt;开源Redis操作辅助类
  2. golang实现随机数
  3. JAVA Socket 编程学习笔记(一)
  4. maven安装配置
  5. Android 应用按两下返回键退出应用程序
  6. 查看表空间信息SQL集合
  7. 24种设计模式--代理模式【Proxy Pattern】
  8. Combinations 解答
  9. HTTP生命周期
  10. javascritpt 原型链
  11. FastDFS的安装步骤
  12. geoserver矢量瓦片发服务前端展示偏移问题解决
  13. php 计算两点地理坐标的距离
  14. Deep Convolution Auto-encoder
  15. 如何在Framework中读取bundle中的Res
  16. python中网络编程基础
  17. [LeetCode]138复制带随机指针的链表
  18. C# 发送HTTP请求超时解决办法
  19. Hulu面试题
  20. Eclipse默认快捷键指南

热门文章

  1. nutch笔记
  2. js 事件阻止冒泡
  3. CSS float清除浮动
  4. 有人说,即使没有JavaScript,你也可以做网页。在纯HTML
  5. rancher2 接NFS存储
  6. 第十章&#160;优先级队列 (xa3)左式堆:插入与删除
  7. verilog之inout
  8. 解决IDEA查看源码时提示:Library source does not match the bytecode for class的问题分析
  9. mysql中插入序列表
  10. 【模型】Toon Dragon