实现WireCard支付
实现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支付的更多相关文章
- 【原创分享·支付宝支付】HBuilder打包APP调用支付宝客户端支付
前言 最近有点空余时间,所以,就研究了一下APP支付.前面很早就搞完APP的微信支付了,但是由于时间上和应用上的情况,支付宝一直没空去研究.然后等我空了的时候,发现支付宝居然升级了支付逻辑,虽然目前还 ...
- Android调用微信登陆、分享、支付
前言:用了微信sdk各种痛苦,感觉比qq sdk调用麻烦多了,回调过于麻烦,还必须要在指定包名下的actvity进行回调,所以我在这里写一篇博客,有这个需求的朋友可以借鉴一下,以后自己别的项目有用到也 ...
- 基于ASP.NET/C#开发国外支付平台(Paypal)学习心得。
最近一直在研究Paypal的支付平台,因为本人之前没有接触过接口这一块,新来一家公司比较不清楚流程就要求开发两个支付平台一个是支付宝(这边就不再这篇文章里面赘述了),但还是花了2-3天的时间通 ...
- 【原创分享·微信支付】C# MVC 微信支付教程系列之现金红包
微信支付教程系列之现金红包 最近最弄这个微信支付的功能,然后扫码.公众号支付,这些都做了,闲着无聊,就看了看微信支付的其他功能,发现还有一个叫“现金红包”的玩意,想 ...
- 【原创分享·微信支付】 C# MVC 微信支付教程系列之扫码支付
微信支付教程系列之扫码支付 今天,我们来一起探讨一下这个微信扫码支付.何为扫码支付呢?这里面,扫的码就是二维码了,就是我们经常扫一扫的那种二维码图片,例如,我们自己添 ...
- 【原创分享·微信支付】 C# MVC 微信支付教程系列之公众号支付
微信支付教程系列之公众号支付 今天,我们接着讲微信支付的系列教程,前面,我们讲了这个微信红包和扫码支付.现在,我们讲讲这个公众号支付.公众号支付的应用环境常见的用户通过公众号,然后再通 ...
- 【原创分享·微信支付】C# MVC 微信支付之微信模板消息推送
微信支付之微信模板消息推送 今天我要跟大家分享的是“模板消息”的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信生存的呀,所以他能不 ...
- 工行ICBC_WAPB_B2C支付接口
一. 前期准备 手机银行(WAP)B2C在线支付接口说明V1.0.0.6.doc 手机银行移动生活商户及门户网站js接口API.doc 支付组件ICBCEBankUtil.dll和infosecapi ...
- NodeJs支付宝移动支付签名及验签
非常感谢 :http://www.jianshu.com/p/8513e995ff3a?utm_campaign=hugo&utm_medium=reader_share&utm_co ...
随机推荐
- I/O复用之select
作用: 实现I/O的多路复用 该函数允许进程指示内核等待多个事件中的任何一个发生,并只有在一个或多个事件发生时或经历一段指定的时间后才唤醒它.进程将于select处阻塞,直到被检测的描述符有一个或多个 ...
- 六 json&pickle模块
之前我们学习过用eval内置方法可以将一个字符串转成python对象,不过,eval方法是有局限性的,对于普通的数据类型,json.loads和eval都能用,但遇到特殊类型的时候,eval就不管用了 ...
- zabbix监控常见系统报错
CPU触发器:1)Processor load is too high on {HOST.NAME} {HOST.NAME}上处理器负载太高触发器表达式:{Zabbix server:system.c ...
- 2019年华南理工大学程序设计竞赛(春季赛)-C-六学家的困惑
题目链接:https://ac.nowcoder.com/acm/contest/625/C 题意:给定两个字符串,每次只能从两个字符串的两端取字符,求依次取字符后所构成的数字最大为多少. 思路:思路 ...
- Codeforces Beta Round #25 (Div. 2 Only)
Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...
- 【c++】c++ 11之lamba表达式
C++ lambda表达式与函数对象 lambda表达式是C++11中引入的一项新技术,利用lambda表达式可以编写内嵌的匿名函数,用以替换独立函数或者函数对象,并且使代码更可读.但是从本质上来讲, ...
- java 基础之--java动态代理
1.抽象角色:声明真实对象与代理对象的共同接口: 2.代理角色:相当于中介的作用,bridge,内部包含对真实角色的reference,在执行真实操作对象时,附加其他操作,相当于对真实角色的封装: 3 ...
- Java通过遍历sessionId获取服务器所有会话session
Servlet2.1之后不支持SessionContext里面getSession(String id)方法,也不存在遍历所有会话Session的方法.但是,我们可以通过HttpSessionList ...
- blockchain good article
https://medium.com/programmers-blockchain/create-simple-blockchain-java-tutorial-from-scratch-6eeed3 ...
- python 虚拟环境操作 virtualenv +virtualenvwrapper
Window 下创建python的虚拟环境 下载工具 pip install virtualenv 创建虚拟环境目录 # 注意此命令创建的虚拟环境目录是在当前目录下 virtualenv testen ...