java在线支付---05_在线支付_编写用于准备请求数据的Servlet
2013-06-09 19:25
513 查看
05_在线支付_编写用于准备请求数据的Servlet
创梦综合技术qq交流群:CreDream:251572072
--------------------------------------------------
c./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 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);
// 得到加密后的字串.
request.setAttribute("messageType", messageType);
request.setAttribute("merchantID", p1_MerId);
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("frpId", pd_FrpId);
request.setAttribute("pr_NeedResponse", pr_NeedResponse);
request.setAttribute("hmac", md5hmac);
request.getRequestDispatcher("/WEB-INF/page/connection.jsp").forward(request, response);
}
}
--------------------------------------------------------------------------------------------
d./payment/src/merchantInfo.properties
p1_MerId=10000326625
keyValue=0acqgug6x57m0wrsiod6clpn1ezh47r2ot5h1zkq5dztiic8y5xkm5g0p0ek
merchantCallbackURL=http\://localhost\:8080/payment/servlet/yeepay/response
第一个是商户的id,第二个是易宝给商户的密钥,第三个是接收易宝支付返回的支付结果的地址.
----------------------------------------------------------------------------------
e./payment/src/com/credream/utils/ConfigInfo.java
package com.credream.utils;
import java.util.Properties;
import java.util.ResourceBundle;
/**
* 读取配置文件
*
*/
public class ConfigInfo {
// 读取配置文件.
// private static ResourceBundle cacheBundle =null;
private static Properties cache = new Properties();
static{
try {
// cacheBundle = ResourceBundle.getBundle("");
cache.load(ConfigInfo.class.getClassLoader().getResourceAsStream("merchantInfo.properties"));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取指定key的值
* @param key
* @return
*/
public static String getValue(String key){
return cache.getProperty(key);
}
}
---------------------------------------------------------------------------------------------------
创梦综合技术qq交流群:CreDream:251572072
--------------------------------------------------
c./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 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);
// 得到加密后的字串.
request.setAttribute("messageType", messageType);
request.setAttribute("merchantID", p1_MerId);
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("frpId", pd_FrpId);
request.setAttribute("pr_NeedResponse", pr_NeedResponse);
request.setAttribute("hmac", md5hmac);
request.getRequestDispatcher("/WEB-INF/page/connection.jsp").forward(request, response);
}
}
--------------------------------------------------------------------------------------------
d./payment/src/merchantInfo.properties
p1_MerId=10000326625
keyValue=0acqgug6x57m0wrsiod6clpn1ezh47r2ot5h1zkq5dztiic8y5xkm5g0p0ek
merchantCallbackURL=http\://localhost\:8080/payment/servlet/yeepay/response
第一个是商户的id,第二个是易宝给商户的密钥,第三个是接收易宝支付返回的支付结果的地址.
----------------------------------------------------------------------------------
e./payment/src/com/credream/utils/ConfigInfo.java
package com.credream.utils;
import java.util.Properties;
import java.util.ResourceBundle;
/**
* 读取配置文件
*
*/
public class ConfigInfo {
// 读取配置文件.
// private static ResourceBundle cacheBundle =null;
private static Properties cache = new Properties();
static{
try {
// cacheBundle = ResourceBundle.getBundle("");
cache.load(ConfigInfo.class.getClassLoader().getResourceAsStream("merchantInfo.properties"));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取指定key的值
* @param key
* @return
*/
public static String getValue(String key){
return cache.getProperty(key);
}
}
---------------------------------------------------------------------------------------------------
相关文章推荐
- java实现网上在线支付--05_编写用于准备请求数据的Servlet
- java在线支付---06,07,08_在线支付_编写将数据提交给易宝支付的JSP页面,集成和测试向易宝发送支付请求,实现浏览器自动向易宝发送支付请求
- java在线支付---09,10,11,12_在线支付_分析易宝支付网关的应答协议与处理代码,完成用于处理支付响应的Servlet的初步编写和调试,完成处理支付网关响应结果的Servlet,支付实现
- java实现网上在线支付--06,07,08_在线支付_编写将数据提交给易宝支付的JSP页面,集成和测试向易宝发送支付请求,实现浏览器自动向易宝发送支付请求
- java实现网上在线支付--09,10,11,12_分析易宝支付网关的应答协议与处理代码,完成用于处理支付响应的Servlet的初步编写和调试,完成处理支付网关响应结果的Servlet,支付实现
- 以Base64字符串形式上传文件——服务器端Java/Servlet接受请求数据中的字符串内容并转换成文件
- Java中解决Servlet获取请求(GET/POST)数据时数据乱码问题
- JavaWeb 初步学习一(ServletConfig参数获取,ServletContext共享数据与请求转发)
- action提交form表单,用于登录请求,servlet接收数据
- 编写Java程序,模拟简单的计算器。 定义名为Number的类,其中有两个整型数据成员n1和n2,应声明为私有。 编写构造方法,用于初始化n1和n2,再为该类定义 加(addition)、 减(su
- 创建Servlet基类,用于解决由于业务太多,来编写太多是Servlet类。--模板设计模式
- java http请求数据 未完待续
- javaweb servlet实现简单的mvc分发请求
- java Servlet Filter 拦截Ajax请求
- jsp+servlet+javabean实现数据分页
- Java根据URL连接请求JSON数据解析代码
- 在java里面怎么定义异常类用于自己编写的类的异常处理?
- Java后台模拟向Servlet发送POST文件上传请求(转载)
- Java实训——编写一个窗体程序,用于计算一元二次方程。
- Rhino 是一个完全使用Java语言编写的开源JavaScript实现。Rhino通常用于在Java程序中,为最终用户提供脚本化能力。它被作为J2SE 6上的默认Java脚本化引擎。