java实现网上在线支付--13java在线支付所有源码

13.Java在线支付所有源码

------------------------------------------------------------------------------------------------

a.新建工程payment

------------------------------------------------------------------------------------------------

b.payment/src/com/credream/servlet/PaymentRequest.java

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);  
        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);  
    }  
}  
c.payment/src/com/credream/servlet/PaymentResutlResponse.java
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 PaymentResutlResponse extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(re
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值