[Java] 歐付寶金流串接教學
时间:2015-12-11 06:47:24
收藏:0
阅读:818
前言:
很多接案的人,都會碰到需要接金流的時候。而歐付寶是個台灣的金流平台。
這邊記錄下,串接的心得。我用的語言是Java, 採liferay這個portal平台,不過這份教學當然適合servlet.
不過官方技術文件,太規格導向了。應該要方便developer快速開發才是 很多資訊還是要向官方問才知道。
流程 :
- 假設有一個網購網站,有使用者下了單之後,採用信用卡付款。此時照官方使用範例
會把所有資訊弄成html的語法(html hidden fields),再加密送出去。
eg.<input type="hidden" name="Language" value="English">
-
如果不懂,覺得太抽象可以用 http://dev.lovewed.tw/allpay/ 這個網站來測試整個流程(歐付寶有提供測試平台,測試信用卡)。
了解整個流程後,我們可以確定歐付寶正常無誤就可以開始串寫程式了。 - payment.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="AllPay.Payment.Integration.*" %> <%@ page import="java.util.Hashtable" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.TreeSet" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>AllPay</title> </head> <body> <% List<String> enErrors = new ArrayList<String>(); try { AllInOne oPayment = new AllInOne(); /* 服務參數 */ oPayment.ServiceMethod = HttpMethod.HttpPOST; oPayment.ServiceURL = ""; oPayment.HashKey = ""; oPayment.HashIV = ""; oPayment.MerchantID = ""; /* 基本參數 */ oPayment.Send.ReturnURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp"; oPayment.Send.ClientBackURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp"; oPayment.Send.OrderResultURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp"; oPayment.Send.MerchantTradeNo = String.valueOf((new Date()).getTime()); oPayment.Send.MerchantTradeDate = new Date(); oPayment.Send.TotalAmount = new Decimal("300"); oPayment.Send.TradeDesc = AllPayFunction.genString("測試"); oPayment.Send.ChoosePayment = PaymentMethod.ALL; oPayment.Send.Remark = AllPayFunction.genString("測試Pay"); oPayment.Send.ChooseSubPayment = PaymentMethodItem.ATM_TAISHIN; oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes; oPayment.Send.DeviceSource = DeviceType.PC; oPayment.SendExtend.ExpireDate = 1; oPayment.SendExtend.PaymentInfoURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp"; //oPayment.SendExtend.ClientRedirectURL = "http://172.16.30.41:8080/"; // 加入選購商品資料。 Item a1 = new Item(); a1.Name = "一棟房子"; a1.Price = new Decimal("300"); a1.Currency = "元"; a1.Quantity = 2; a1.URL = "<<產品說明位址>>"; oPayment.Send.Items.add(a1); Item a2 = new Item(); a2.Name = "iPhone 6S"; a2.Price = new Decimal("400"); a2.Currency = "元"; a2.Quantity = 8; a2.URL = "<<產品說明位址>>"; oPayment.Send.Items.add(a2); enErrors.addAll(oPayment.CheckOut(response.getWriter())); } catch (Exception e) { enErrors.add(e.getMessage()); } finally { if (enErrors.size() > 0) out.print(enErrors); } %> </body> </html>
結尾:
基本上,只要欄位照著規格書填對。就沒有太大的問題,而看到官方有其他的問題則是參數中有 / - 等字串
所以過程中,我是已經避免此問題了。
若有問題,可以留言討論。
原文:http://www.cnblogs.com/bittorrent/p/5037864.html
评论(0)