实现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. jquery+jquery.pagination+php+ajax 无刷新分页

    <!DOCTYPE html> <html ><head><meta http-equiv="Content-Type" content= ...

  2. SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    今天启动用eureka的服务消费者时,一直出现问题. SpringCloud报错: Caused by: org.springframework.context.ApplicationContextE ...

  3. Javascript重点汇总

    LazyMan 实现LazyMan(什么是LazyMan?请自行google) function _LazyMan(_name) { var _this = this; _this.tasks = [ ...

  4. mysql定时删除6个月前的表

    查看定时是否开启: 查看event是否开启 : SHOW VARIABLES LIKE '%event_sche%'; 将事件计划开启 : ; 将事件计划关闭 : ; 代码: BEGIN -- 保存表 ...

  5. linux查看目录下所有文件内容中是否包含某个字符串

    转发自:http://blog.csdn.net/yimingsilence/article/details/76071949 查找目录下的所有文件中是否含有某个字符串 find .|xargs gr ...

  6. how2j网站前端项目——天猫前端(第一次)学习笔记3

    开始学习分类页面! 站长介绍说,这个项目一共有17个分类页面,每个分类页面的风格都是相似的:由分类图片. 查询.各种排序方式,产品列表.内容很多,拆成3部分学习:1.排序和价格 2.产品列表 3.交互 ...

  7. ES5/6/7

    ECMAScript(js语言规范) ###ES5 1.   严格模式 运行模式: 正常(混杂)模式与严格模式 应用上严格模式: ‘strict mode’ 2.JSON对象 * JSON.strin ...

  8. vm参数配置的理解

    -denv=dev表示将服务器的级别 设置为开发环境 所有错误的内容都会打印在控制台上 //The-Denv = dev statement creates a system property nam ...

  9. go语言中的反射reflect

    package main; import ( "fmt" "reflect" ) //反射refection //反射使用TypeOf和ValueOf函数从接口 ...

  10. python 大量使用json 存储数据时,格式化输出的方式

    import json, pprint dic = {'name': 234, 'user_name': 'yan xia ting yu ', 'list': ['ds', 'a', 2], '你好 ...