AllPay,http://www.allpay.com.tw/,欧付宝是台湾知名的第三方支付公司,拥有丰富的支付模式(支持和支付宝、财付通),只需要一次对接,各种支付模式均可使用。

接口编写SDK:http://www.allpay.com.tw/Service/API_Help?Anchor=AnchorDoc

官方提供了比较完整的SDK,里面有丰富的代码,这里只讲需要注意的地方:

1.欧付宝提供若干支付模式,可以再接口中指定(不给用户选择的机会);也可以在接口中设置ALL,等到付款的时候让用户选择

2.确定支付模式后,便可以生成订单,然后等待支付

3.支付结果的确认是Server静默方式通知的,非URL跳转的方式,这点类似PayPal的Classic模式

4.提供沙箱模式http://vendor-stage.allpay.com.tw,用户名StageTest,密码Test1234,在沙箱中可以任意下订单,模拟支付等等

5.正式模式的后台http://vendor.allpay.com.tw同样支持模拟付款的方式

6.支付结果接收service,注意需要验证来源,也就是CheckMacValue,验证方法后面给出

7.如果接口中不指定支付模式,oPayment.Send.ChoosePayment = PaymentMethod.ALL; 即使客户不选择支付宝支付,那么也需要将支付宝的支付选项填入

oPayment.SendExtend.PhoneNo = "";
oPayment.SendExtend.Email = "";
oPayment.SendExtend.UserName = "";

因为这三项是必填字段,注意是SendExtend。

8.ReturnURL 為Server 端的回應,歐付寶Server會直接將付款結果送到您指定的ReturnURL

OrderResultURL 則為 Client 端的回應,我們會將使用者的畫面轉導到您指定的OrderResultURL

ClientBackURL 主要的功能,是在交易完成的頁面中,若廠商端有設定網址,則在該頁面上會出現「返回商店」的按鈕,當消費者點選後,會導到所設定的網址。

9.MerchantTradeNo测试的时候如果两笔都是一样的,会导致第二次创建订单失败,这个要注意,每次最好用随机数

下面是支付界面,传入订单编号,通过调用AllPay接口,会默认跳转到AllPay去支付
        public ActionResult PaymentByAllPay(Guid BillCode)
{
List<string> enErrors = new List<string>();
string szHtml = String.Empty;
try
{
using (AllInOne oPayment = new AllInOne())
{
/* 服務參數 */
oPayment.ServiceMethod = AllPay.Payment.Integration.HttpMethod.HttpPOST;
//oPayment.ServiceURL = "http://payment-stage.allpay.com.tw/Cashier/AioCheckOut";
oPayment.ServiceURL = "https://payment.allpay.com.tw/Cashier/AioCheckOut";
oPayment.HashKey = System.Configuration.ConfigurationManager.AppSettings["APHashKey"];
oPayment.HashIV = System.Configuration.ConfigurationManager.AppSettings["APHashIV"];
oPayment.MerchantID = System.Configuration.ConfigurationManager.AppSettings["MerchantID"]; IList<COM_Bill> list = WMSFactory.COM_Bill.FindByCondition("");
if (list == null || list.Count() != )
{
throw new Exception("Error:BillCode Is Wrong!");
}
COM_Bill bill = list.First();
IList<COM_BillSub> billSub = WMSFactory.COM_BillSub.FindByCondition("BillCode='" + BillCode.ToString() + "'"); /* 基本參數 */
string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Order/";
//以后台服务通知的形式发送到该URL
oPayment.Send.ReturnURL = baseURI + "AllPayResult/"+BillCode.ToString().Replace("-","_");//完成付款,注意这里有严格的url限制,不能传递-
oPayment.Send.ClientBackURL = baseURI; oPayment.Send.MerchantTradeNo = bill.Id.ToString()+DateTime.Parse(bill.CreateTime).ToString("yyyyMMddHHmmss") + new Random().Next(, ).ToString();
oPayment.Send.MerchantTradeDate = DateTime.Now;
oPayment.Send.TotalAmount = (int)(bill.TotalAmount + bill.ShippingFee - bill.VoucherMoney);
oPayment.Send.TradeDesc = "物流费:" + bill.ShippingFee.ToString();
oPayment.Send.ChoosePayment = PaymentMethod.ALL;
oPayment.Send.ChooseSubPayment = PaymentMethodItem.None;
oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.No;
oPayment.Send.DeviceSource = DeviceType.PC;
//例(排除支付寶與財富通): Alipay#Tenpay
oPayment.Send.IgnorePayment = ""; // 加入選購商品資料。
foreach (COM_BillSub sb in billSub)
{
AllPay.Payment.Integration.Item item = new AllPay.Payment.Integration.Item();
item.Name = sb.SkcName + ":" + sb.Skc.ToString() + "," + sb.ColorName + "," + sb.SizeName;
item.Currency = "新台幣";
item.Price = sb.Price;
item.Quantity = sb.Num;
item.URL = "";
oPayment.Send.Items.Add(item); //oPayment.SendExtend.AlipayItemCounts += sb.Num.ToString() + "#";
//oPayment.SendExtend.AlipayItemName += sb.SkcName + "#";
//oPayment.SendExtend.AlipayItemPrice += sb.Price.ToString() + "#";
}//物流费用
AllPay.Payment.Integration.Item shippingfeeitm = new AllPay.Payment.Integration.Item();
shippingfeeitm.Name = "Shipping";
shippingfeeitm.Currency = "新台幣";
shippingfeeitm.Price = bill.ShippingFee;
shippingfeeitm.Quantity = ;
oPayment.Send.Items.Add(shippingfeeitm); //oPayment.SendExtend.AlipayItemCounts += "1";
//oPayment.SendExtend.AlipayItemName += "Shipping";
//oPayment.SendExtend.AlipayItemPrice += bill.ShippingFee.ToString(); //获取物流信息
COM_Address address = WMSFactory.COM_Address.FindById(bill.ShippingId.ToString());
oPayment.SendExtend.PhoneNo = address.TelPhone;
oPayment.SendExtend.Email = member.Email;
oPayment.SendExtend.UserName = address.LastName + address.FirstName; /* 產生訂單 */
enErrors.AddRange(oPayment.CheckOut());
/* 產生產生訂單 Html Code 的方法 */
enErrors.AddRange(oPayment.CheckOutString(ref szHtml)); Session.Add(BillCode.ToString(), oPayment.Send.MerchantTradeNo);
}
}
catch (Exception ex)
{
// 例外錯誤處理。
enErrors.Add(ex.Message);
}
finally
{
if (enErrors.Count() > )
throw new Exception(String.Join("<br />", enErrors));
}
//扣库存
DataTable dt = WMSFactory.COM_BillSub.UpdateStore(BillCode, );
if (dt != null && dt.Rows.Count > && dt.Rows[][].ToString() != "")
{
return RedirectToAction("PayResult", new { id = , msg = dt.Rows[][].ToString() });
}
ViewBag.AllPayRedirect = szHtml;
return View();
}

支付确认接口实现:

public void AllPayResult(string id)
{
List<string> enErrors = new List<string>();
Hashtable htFeedback = null;
id = id.Replace("_", "-");
log.Debug("进入allpayresult,id=" + id);
try
{
string szHashKey = System.Configuration.ConfigurationManager.AppSettings["APHashKey"];
string szHashIV = System.Configuration.ConfigurationManager.AppSettings["APHashIV"]; // 取回所有資料
if (enErrors.Count() == )
{ /* 支付後的回傳的基本參數 */
string szMerchantID = Request.Form["MerchantID"];
string szMerchantTradeNo = Request.Form["MerchantTradeNo"];
string szPaymentDate =Request.Form["PaymentDate"];
string szPaymentType = Request.Form["PaymentType"];
string szPaymentTypeChargeFee = Request.Form["PaymentTypeChargeFee"];
string szRtnCode = Request.Form["RtnCode"];
string szRtnMsg = Request.Form["RtnMsg"];
string szSimulatePaid = Request.Form["SimulatePaid"];
string szTradeAmt =Request.Form["TradeAmt"];
string szTradeDate =Request.Form["TradeDate"];
string szTradeNo = Request.Form["TradeNo"];
string szCheckMacValue = Request.Form["CheckMacValue"]; //一般回傳參數CMV(若需要其他檢查請自行增加)
Dictionary<string, string> Parameters = new Dictionary<string, string>();
Parameters.Add("MerchantID", szMerchantID);
Parameters.Add("MerchantTradeNo", szMerchantTradeNo);
Parameters.Add("RtnCode", szRtnCode);
Parameters.Add("RtnMsg", szRtnMsg);
Parameters.Add("TradeNo", szTradeNo);
Parameters.Add("TradeAmt", szTradeAmt);
Parameters.Add("PaymentDate", szPaymentDate);
Parameters.Add("PaymentType", szPaymentType);
Parameters.Add("PaymentTypeChargeFee", szPaymentTypeChargeFee);
Parameters.Add("TradeDate", szTradeDate);
Parameters.Add("SimulatePaid", szSimulatePaid); string ParameterString = string.Join("&", Parameters.OrderBy(d => d.Key).Select(p => p.Key + "=" + p.Value)); string str = "HashKey=" + szHashKey + "&" + ParameterString + "&HashIV=" + szHashIV; log.Debug("接收到AllPay返回值=" + str); string urlEncodeStrPost = HttpUtility.UrlEncode(str);
//url大寫轉小寫
string lowerUrlEncodeStrPost = urlEncodeStrPost.ToLower();
//檢查碼要使用MD5加密
MD5 md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(lowerUrlEncodeStrPost));
StringBuilder sBuilder = new StringBuilder();
for (int i = ; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("X2"));
}
string sCheckMacValue = sBuilder.ToString();
log.Debug("mine:" + sCheckMacValue + ";param:" + szCheckMacValue);
if (szRtnCode == "" && szSimulatePaid == "" && sCheckMacValue == szCheckMacValue)
{
//更新订单状态
}
}
}
catch (Exception ex)
{ // 例外錯誤處理。
enErrors.Add(ex.Message);
}
finally
{
this.Response.Clear(); // 回覆成功訊息。
if (enErrors.Count() == )
this.Response.Write("1|OK"); // 回覆錯誤訊息。
else
this.Response.Write(String.Format("0|{0}", String.Join("\\r\\n", enErrors)));
this.Response.Flush();
this.Response.End();
}
}

AllPay(欧付宝)支付接口集成的更多相关文章

  1. ecshop 国付宝支付接口

    function get_code($order, $payment){ $version = '2.2'; $charset = '1'; $language = '1'; $signType = ...

  2. 【Java EE 学习 21 下】【 使用易宝支付接口实现java网上支付功能】

    一.网上支付分为两种情况,一种方法是使用直接和银行的支付接口,另外一种方法是使用第三方支付平台和银行对接完成支付. 1.直接和银行对接. 2.使用第三方支付平台 3.常见的第三方支付平台 二.使用易宝 ...

  3. python-支付宝支付示例

      项目演示: 1.输入金额 2.扫码支付: 3.支付完成: 4.跳转回商户 一.注册账号 https://openhome.alipay.com/platform/appDaily.htm?tab= ...

  4. django-支付宝支付

    安装python-alipay-sdk pip install python-alipay-sdk --upgrade 配置 视图函数orders/views.py # 订单支付 # /order/p ...

  5. vue--支付宝支付

    1.支付宝支付:前端发起一个请求,后台返回一个页面,直接将返回的页面(一个表单),再执行表单提交 okFryOtherPayHandler(){ let reqBody = {}; reqBody.o ...

  6. PHP----------支付宝支付的一些注意事项。该博客只适用于20180209之后,的app支付宝支付。

    1.签名方式: 2.设置应用公钥.也就是开发者公钥.

  7. php与国付宝对接过程吐槽

    最近.我们在打造全国第一家互联网+风险管理平台(避险谷)时.须要与第三方支付平台"国付宝"进行在线交易对接. 之前对接过支付宝 .感觉还非常easy,拿到国付宝的接口文档.我晕啊. ...

  8. Python支付接口汇总大全(包含微信、支付宝等)

    微信接口 wzhifuSDK- 由微信支付SDK 官方PHP Demo移植而来,v3.37下载地址 weixin_pay- 是一个简单的微信支付的接口 weixin_pay- 微信支付接口(V3.3. ...

  9. 国付宝ecshop,shopex,shopnc在线支付接口,php版本支付接口开发

    最近应一个客户的要求,给他的一个ecshop商城开发国付宝在线支付接口.国付宝估计大家比较陌生,但是他集成了很多银行的一些网银接口,所以比较方便.号称国家级的第三方支付平台.最近有增加了域名验证,就是 ...

随机推荐

  1. Leaf:美团分布式ID生成服务开源

    Leaf是美团基础研发平台推出的一个分布式ID生成服务,名字取自德国哲学家.数学家莱布尼茨的一句话:“There are no two identical leaves in the world.”L ...

  2. 【nodeJS爬虫】前端爬虫系列

    写这篇 blog 其实一开始我是拒绝的,因为爬虫爬的就是cnblog博客园.搞不好编辑看到了就把我的账号给封了:). 言归正传,前端同学可能向来对爬虫不是很感冒,觉得爬虫需要用偏后端的语言,诸如 ph ...

  3. C# try catch finally简单介绍和应用

    今天看代码书的时候,有用到try--catch--finally,然后就查了下具体的注意事项和应用. 简单来说就是: try { //有可能出错误的代码或者代码片段       } catch{ // ...

  4. Windows10系统重置网络设置

    使用Windows10系统户很可能会遇到网络异常,连接不上网的情况? 如此,简易方法可以尝试下.重置网络,教程如下: 1.//按下WIN+X(或右键点击开始按钮),然后选择“命令提示符(管理员)”; ...

  5. Xcode 清理存储空间

    Xcode版本:8.3.3 iOS版本:10.3.2 移除 Xcode 运行安装 APP 产生的缓存文件(DerivedData) 只要重新运行Xcode就一定会重新生成,而且会随着运行程序的增多,占 ...

  6. epoll惊群原因分析

    考虑如下情况(实际一般不会做,这里只是举个例子): 在主线程中创建一个socket.绑定到本地端口并监听 在主线程中创建一个epoll实例(epoll_create(2)) 将监听socket添加到e ...

  7. Mac 安装配置nexus2.6 搭建Maven的中央仓库

    今天配置java 环境,安装nexus 百度了好久才安装好,所以特别写下来 分享给同样遇到问题的你.废话不多说,直接上步骤 前置条件 :已经安装了JDK 下载nexus(http://www.sona ...

  8. 哪个中年IT男不是一边面对危机,一边咬牙硬抗

    本文转自:https://www.cnblogs.com/gossip/p/8297294.html 对于 2017 年年末那则令人哀伤的消息,相信很多同龄人都会触目伤怀.面对公司的强制性劝退,深圳中 ...

  9. DateTables的服务器分页

    function InitTable() { var table = $('#tbl_users').DataTable(); if ($.fn.dataTable.isDataTable('#tbl ...

  10. vs2013修改书签(vs书签文件位置)

    visual studio 2013 的书签功能很好用,可以记录一些代码的位置:方便查阅: 不过当项目被他人修改过后,svn update 更新过后,书签的文件行号不变,但是已经不再是原来记录的哪一行 ...