java实现网上在线支付--06,07,08_在线支付_编写将数据提交给易宝支付的JSP页面,集成和测试向易宝发送支付请求,实现浏览器自动向易宝发送支付请求

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">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  </head>
  
  <body οnlοad="JavaScript:document.form[0].submit()">
    <!-- 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 -->
		<input type="hidden" name="pr_NeedResponse" value="0">  <!-- 应答机制为"1":需要应答机制 "0":不需要应答机制 -->
		<!-- MD5-hmac验证码 -->
		<input type="hidden" name="hmac" value="${hmac}">
		<input type="submit" value="发  送">
	</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 cn.itcast.utils.ConfigInfo;
import cn.itcast.utils.PaymentUtil;
/**
* 发起支付请求
*
*/
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 merchantID=ConfigInfo.getValue("merchantID");
		String keyValue=ConfigInfo.getValue("keyValue");
		String merchantCallbackURL=ConfigInfo.getValue("merchantCallbackURL");
		
		String orderid=request.getParameter("orderid");//订单号
		String amount=request.getParameter("amount");//支付金额
		String pd_FrpId=request.getParameter("pd_FrpId");//银行支付方式
		
		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=PaymentUtil.buildHmac(messageType, merchantID, orderid, amount, currency, productId,
				productCat, productDesc, merchantCallbackURL, addressFlag, sMctProperties, pd_FrpId,
				"0", keyValue);
		//1、注意这里是根据易宝支付的原理来的,商户需要把一些支付信息,和加密后的支付信息,同时发给易宝支付,易宝支付收到信                   息后,利用密钥进行对信息再次加密,
		//拿自己加密后的信息和商户发送过来的加密信息进行对比,对比结果为一致时,那么说明信息没被改过。
		//得到加密后的字串
		request.setAttribute("messageType", messageType);
		request.setAttribute("merchantID", merchantID);
		request.setAttribute("orderid", orderid);
		request.setAttribute("amount", amount);
		request.setAttribute("currency", currency);
		request.setAttribute("productId", productId);
		request.setAttribute("productCat", productCat);
		request.setAttribute("productDesc", productDesc);
		request.setAttribute("merchantCallbackURL", merchantCallbackURL);
		request.setAttribute("addressFlag", addressFlag);
		request.setAttribute("sMctProperties", sMctProperties);
		request.setAttribute("pd_FrpId", pd_FrpId);
		request.setAttribute("pr_NeedResponse", pr_NeedResponse);
		request.setAttribute("hmac", md5hmac);
		//转发
		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 οnlοad="javascript:document.forms[0].submit()">

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值