06_在线支付_编写将数据提交给易宝支付的JSP页面
--------------------------------------------------------------
1./payment/WebRoot/WEB-INF/page/connection.jsp
<%@ page language="java" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>发起支付请求</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body onload="javascript:document.forms[0].submit()">
<!-- http://tech.yeepay.com:8080/robot/debug.action -->
<!--
http://tech.yeepay.com:8080/robot/debug.action
这个是易宝支付的调试路径.在做好之前最好用调试网关.
--><form name="yeepay" action="https://www.yeepay.com/app-merchant-proxy/node" method='post'>
<input type='hidden' name='p0_Cmd' value="${messageType}"> <!-- 请求命令,在线支付固定为Buy -->
<input type='hidden' name='p1_MerId' value="${merchantID}"> <!-- 商家ID -->
<input type="hidden" name="p2_Order" value="${orderId}"> <!-- 商家的交易定单号 -->
<input type='hidden' name='p3_Amt' value="${amount}"> <!-- 订单金额 -->
<input type='hidden' name='p4_Cur' value="${currency}"> <!-- 货币单位 -->
<input type='hidden' name='p5_Pid' value="${productId}"> <!-- 商品ID -->
<input type='hidden' name='p6_Pcat' value="${productCat}"> <!-- 商品种类 -->
<input type='hidden' name='p7_Pdesc' value="${productDesc}"> <!-- 商品描述 -->
<input type='hidden' name='p8_Url' value="${merchantCallbackURL}"> <!-- 交易结果通知地址 -->
<input type='hidden' name='p9_SAF' value="${addressFlag}"> <!-- 需要填写送货信息 0:不需要 1:需要 -->
<input type='hidden' name='pa_MP' value="${sMctProperties}"> <!-- 商家扩展信息 -->
<input type='hidden' name='pd_FrpId' value="${frpId}"> <!-- 银行ID -->
<!-- 应答机制 为“1”: 需要应答机制;为“0”: 不需要应答机制 -->
<input type="hidden" name="pr_NeedResponse" value="0">
<!--MD5-hmac验证码-->
<input type='hidden' name='hmac' value="${hmac}"><!-- MD5-hmac验证码 -->
</form>
</body>
</html>
---------------------------------------------------------------------------
2.package com.credream.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.credream.utils.ConfigInfo;
import com.credream.utils.PanymentUtil;
/**
* 发起支付请求
* @author 传智播客
*
*/
public class PaymentRequest extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
* p1_MerId=10000326625// 商家的id
keyValue=0acqgug6x57m0wrsiod6clpn1ezh47r2ot5h1zkq5dztiic8y5xkm5g0p0ek //密钥
merchantCallbackURL=http\://localhost\:8080/payment/servlet/yeepay/response //
// 这个地址是用来接收易宝支付返回结果的路径.这个路径必须外网可以访问.
* */
request.setCharacterEncoding("GBK");
String orderid = request.getParameter("orderid");//订单号
String amount = request.getParameter("amount");//支付金额
String pd_FrpId = request.getParameter("pd_FrpId");//选择的支付银行
String p1_MerId = ConfigInfo.getValue("p1_MerId");
String keyValue = ConfigInfo.getValue("keyValue");
String merchantCallbackURL = ConfigInfo.getValue("merchantCallbackURL");
String messageType = "Buy"; // 请求命令,在线支付固定为Buy
String currency = "CNY"; // 货币单位
String productDesc = ""; // 商品描述
String productCat = ""; // 商品种类
String productId = ""; // 商品ID
String addressFlag = "0"; // 需要填写送货信息 0:不需要 1:需要
String sMctProperties = ""; // 商家扩展信息
String pr_NeedResponse = "0"; // 应答机制
// 下面这个方法用来进行加密.通过调用加密类.
String md5hmac = PanymentUtil.buildHmac(messageType, p1_MerId, orderid, amount, currency,
productId, productCat, productDesc, merchantCallbackURL, addressFlag, sMctProperties,
pd_FrpId, pr_NeedResponse, keyValue);
//1.注意这里是根据易宝支付的原理来的,商户需要把,一些支付信息,和加密后的支付信息,同时发给易宝支付
//易宝支付收到信息后,利用密钥进行对信息再次加密,拿自己加密后的信息和商户发过来的加密信息
//进行对比,对比结果为一致的时候,那么说明信息没有被串改过.
// 得到加密后的字串.
request.setAttribute("messageType", messageType);//支付命令
request.setAttribute("merchantID", p1_MerId);//商户id
request.setAttribute("orderId", orderid);//订单号
request.setAttribute("amount", amount);//订单金额
request.setAttribute("currency", currency);//货币类型
request.setAttribute("productId", productId);//产品id
request.setAttribute("productCat", productCat);//产品种类
request.setAttribute("productDesc", productDesc);//商品描述
request.setAttribute("merchantCallbackURL", merchantCallbackURL);//返回的URL
request.setAttribute("addressFlag", addressFlag);//收货地址
request.setAttribute("sMctProperties", sMctProperties);//商家扩展信息
request.setAttribute("frpId", pd_FrpId);//银行id
request.setAttribute("pr_NeedResponse", pr_NeedResponse);//应答机制.
request.setAttribute("hmac", md5hmac);//MD5验证码
// 转发.
request.getRequestDispatcher("/WEB-INF/page/connection.jsp").forward(request, response);
}
}
----------------------------------------------------------------------------------------------
07_在线支付_集成和测试向易宝发送支付请求
----------------------------------------------------
a. <!-- http://tech.yeepay.com:8080/robot/debug.action -->
<!--
http://tech.yeepay.com:8080/robot/debug.action
这个是易宝支付的调试路径.在做好之前最好用调试网关.
https://www.yeepay.com/app-merchant-proxy/node
这个是易宝支付商用的网关.
--><form name="yeepay" action="https://www.yeepay.com/app-merchant-proxy/node" method='post'>
先用测试网关,然后用正式网关开始测试.
----------------------------------------------------------------------
08_在线支付_实现浏览器自动向易宝发送支付请求
<body onload="javascript:document.forms[0].submit()">
------------------------------------------------------