实现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();
} }
}

实现WireCard支付的更多相关文章

  1. 【原创分享·支付宝支付】HBuilder打包APP调用支付宝客户端支付

    前言 最近有点空余时间,所以,就研究了一下APP支付.前面很早就搞完APP的微信支付了,但是由于时间上和应用上的情况,支付宝一直没空去研究.然后等我空了的时候,发现支付宝居然升级了支付逻辑,虽然目前还 ...

  2. Android调用微信登陆、分享、支付

    前言:用了微信sdk各种痛苦,感觉比qq sdk调用麻烦多了,回调过于麻烦,还必须要在指定包名下的actvity进行回调,所以我在这里写一篇博客,有这个需求的朋友可以借鉴一下,以后自己别的项目有用到也 ...

  3. 基于ASP.NET/C#开发国外支付平台(Paypal)学习心得。

        最近一直在研究Paypal的支付平台,因为本人之前没有接触过接口这一块,新来一家公司比较不清楚流程就要求开发两个支付平台一个是支付宝(这边就不再这篇文章里面赘述了),但还是花了2-3天的时间通 ...

  4. 【原创分享·微信支付】C# MVC 微信支付教程系列之现金红包

            微信支付教程系列之现金红包           最近最弄这个微信支付的功能,然后扫码.公众号支付,这些都做了,闲着无聊,就看了看微信支付的其他功能,发现还有一个叫“现金红包”的玩意,想 ...

  5. 【原创分享·微信支付】 C# MVC 微信支付教程系列之扫码支付

    微信支付教程系列之扫码支付                  今天,我们来一起探讨一下这个微信扫码支付.何为扫码支付呢?这里面,扫的码就是二维码了,就是我们经常扫一扫的那种二维码图片,例如,我们自己添 ...

  6. 【原创分享·微信支付】 C# MVC 微信支付教程系列之公众号支付

    微信支付教程系列之公众号支付         今天,我们接着讲微信支付的系列教程,前面,我们讲了这个微信红包和扫码支付.现在,我们讲讲这个公众号支付.公众号支付的应用环境常见的用户通过公众号,然后再通 ...

  7. 【原创分享·微信支付】C# MVC 微信支付之微信模板消息推送

    微信支付之微信模板消息推送                    今天我要跟大家分享的是“模板消息”的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信生存的呀,所以他能不 ...

  8. 工行ICBC_WAPB_B2C支付接口

    一. 前期准备 手机银行(WAP)B2C在线支付接口说明V1.0.0.6.doc 手机银行移动生活商户及门户网站js接口API.doc 支付组件ICBCEBankUtil.dll和infosecapi ...

  9. NodeJs支付宝移动支付签名及验签

    非常感谢 :http://www.jianshu.com/p/8513e995ff3a?utm_campaign=hugo&utm_medium=reader_share&utm_co ...

随机推荐

  1. Excel图表编辑---表格移动,样式修改

    一.移动位置和调整大小 先鼠标选中如下面这个图片,之后点击上方的设计按钮,随后选择右边的, 再选择,就可以实现图片的表格之间的移动. 其中移动图表里面的,选中这个之后,图表的大小会根据窗口的大小自动调 ...

  2. centos7.2 +cloudstack 4.11 +KVM +ceph 安装配置(网卡带聚合)

    系统安装,注意:管理节点版本是有要求的,配置为centos 7.2 最小安装版本(非最小化安装). 系统分区要求 /boot/efi 200MB / 100G /var 100G swap 0 其它给 ...

  3. lower_bound和upper_bound的实现和基本用法

    最近一直在学dp,但是感觉进度明显慢了很多,希望自己可以加一把劲,不要总是拖延了... 在LIS的优化中我遇到了二分查找的问题,之前也知道lower_bound和upper_bound两个函数,但是没 ...

  4. Django的具体操作(二)

    今日内容:用户登录以及分页的实现 views.py # 登录动作 def login_action(request): # 必须继承request if request.method == 'POST ...

  5. AngularJS——第2章 模块化

    第2章 模块化 使用AngularJS构建应用时是以模块化的方式组织的,即将整个应用划分成多个小模块,各个模块有各自的职责,最终实现完整的应用. 2.1 定义应用 通过为任一HTML标签添加ng-ap ...

  6. ret和retf

    ret指令用栈中的数据,修改IP的内容,从而实现近转移; retf指令用栈中的数据,修改CS和IP的内容,从而实现远转移. CPU执行ret指令时,进行下面两步操作: (IP) = ((ss)*16+ ...

  7. PHP统计网站pv(访问量)

    //首先判断有没有统计的文件 if(is_file("pv.txt")){//有 //取文件里面的值 $count=file_get_contents("pv.txt&q ...

  8. delete,truncate 和 delete之间的区别

    1.首先看下语法定义: drop table_name truncate table_name delete table_name [where column_name = value] 2.各个删除 ...

  9. sqlserver使用SQL语句创建数据库登录对象、数据库用户以及对为该用户赋予操作权限

    --创建登录名USE masterGO--PbMaster,密码123456CREATE LOGIN PbMaster with PASSWORD='1234GO --创建数据库用户USE E_Mar ...

  10. js 横屏 竖屏 相关代码 与知识点

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...