|
|
@ -15,46 +15,66 @@ import com.cn.service.impl.PrepServiceImpl;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @ClassName: PayServlet
|
|
|
|
* @ClassName: PayServlet
|
|
|
|
* @Description: 用户付款
|
|
|
|
* @Description: 用户付款的Servlet
|
|
|
|
* @author: ljy
|
|
|
|
* @author: ljy
|
|
|
|
* @date: 2019年9月28日 下午10:38:37
|
|
|
|
* @date: 2019年9月28日 下午10:38:37
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class PayServlet extends HttpServlet {
|
|
|
|
public class PayServlet extends HttpServlet {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理GET请求的方法。
|
|
|
|
|
|
|
|
* 当客户端发送GET请求到此Servlet时,这个方法会被调用。
|
|
|
|
|
|
|
|
* @param request HttpServletRequest对象,包含客户端请求信息。
|
|
|
|
|
|
|
|
* @param response HttpServletResponse对象,用于发送响应到客户端。
|
|
|
|
|
|
|
|
* @throws ServletException 可能抛出的Servlet异常。
|
|
|
|
|
|
|
|
* @throws IOException 可能抛出的IO异常。
|
|
|
|
|
|
|
|
*/
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
throws ServletException, IOException {
|
|
|
|
throws ServletException, IOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取请求参数temp,用于判断是否是从支付宝支付接口回跳来的
|
|
|
|
String temp = request.getParameter("temp");
|
|
|
|
String temp = request.getParameter("temp");
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是从支付宝支付接口回跳来的
|
|
|
|
// 判断是否是从支付宝支付接口回跳来的
|
|
|
|
if (temp != null && "1".equals(temp)) {
|
|
|
|
if (temp != null && "1".equals(temp)) {
|
|
|
|
|
|
|
|
// 获取订单ID
|
|
|
|
Integer prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
Integer prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
|
|
|
|
// 创建PrepService的实现类对象,用于访问订单相关的业务逻辑
|
|
|
|
PrepService prepService = new PrepServiceImpl();
|
|
|
|
PrepService prepService = new PrepServiceImpl();
|
|
|
|
|
|
|
|
// 根据订单ID获取订单对象
|
|
|
|
Prep prep = prepService.getById(prepId);
|
|
|
|
Prep prep = prepService.getById(prepId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置付款状态为真
|
|
|
|
prep.setWay(true);
|
|
|
|
prep.setWay(true);
|
|
|
|
|
|
|
|
// 更新订单对象
|
|
|
|
int recordNumber = prepService.update(prep);
|
|
|
|
int recordNumber = prepService.update(prep);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取PrintWriter对象,用于向客户端发送响应
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
|
|
// 判断更新是否成功
|
|
|
|
if (recordNumber == 1) {
|
|
|
|
if (recordNumber == 1) {
|
|
|
|
out.write(
|
|
|
|
// 如果成功,弹出提示并跳转到会员中心
|
|
|
|
"<script>alert('付款成功!');" + "window.location.href='pages/user/myCenter/myCenter.jsp'</script>");
|
|
|
|
out.write("<script>alert('付款成功!');" + "window.location.href='pages/user/myCenter/myCenter.jsp'</script>");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果失败,弹出提示并跳转到我的订单页面
|
|
|
|
out.write("<script>alert('很抱歉,付款失败!');" + "window.location.href='MyPrepServlet'</script>");
|
|
|
|
out.write("<script>alert('很抱歉,付款失败!');" + "window.location.href='MyPrepServlet'</script>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭PrintWriter对象
|
|
|
|
out.close();
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取订单ID
|
|
|
|
Integer prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
Integer prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
|
|
|
|
// 创建PrepService的实现类对象
|
|
|
|
PrepService prepService = new PrepServiceImpl();
|
|
|
|
PrepService prepService = new PrepServiceImpl();
|
|
|
|
|
|
|
|
// 根据订单ID获取订单对象
|
|
|
|
Prep prep = prepService.getById(prepId);
|
|
|
|
Prep prep = prepService.getById(prepId);
|
|
|
|
|
|
|
|
|
|
|
|
// 支付接口调用 start
|
|
|
|
// 将订单对象设置为request属性,以便在支付页面中可以访问
|
|
|
|
|
|
|
|
|
|
|
|
request.setAttribute("prep", prep);
|
|
|
|
request.setAttribute("prep", prep);
|
|
|
|
|
|
|
|
// 转发请求到支付接口调用的Servlet
|
|
|
|
request.getRequestDispatcher("AlipayServlet").forward(request, response);
|
|
|
|
request.getRequestDispatcher("AlipayServlet").forward(request, response);
|
|
|
|
|
|
|
|
|
|
|
|
// 支付接口调用 end
|
|
|
|
// 支付接口调用 end
|
|
|
@ -79,10 +99,19 @@ public class PayServlet extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理POST请求的方法。
|
|
|
|
|
|
|
|
* 当客户端发送POST请求时,这个方法会被调用。
|
|
|
|
|
|
|
|
* @param request HttpServletRequest对象,包含客户端请求信息。
|
|
|
|
|
|
|
|
* @param response HttpServletResponse对象,用于发送响应到客户端。
|
|
|
|
|
|
|
|
* @throws ServletException 可能抛出的Servlet异常。
|
|
|
|
|
|
|
|
* @throws IOException 可能抛出的IO异常。
|
|
|
|
|
|
|
|
*/
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
throws ServletException, IOException {
|
|
|
|
throws ServletException, IOException {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
// 这个方法目前没有实现具体的逻辑,只是调用了doGet方法
|
|
|
|
|
|
|
|
// 这意味着无论是POST请求还是GET请求,都会执行相同的逻辑
|
|
|
|
doGet(request, response);
|
|
|
|
doGet(request, response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|