Java使用支付宝接口-demo案例源码架包一起(jsp+servlet)packagezhifubao.servletTest;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importcom.alipay.api.AlipayApiException;importzhifubao.service.order.OrderController;/***@authorYXqiang*/@WebServlet(description="支付宝测试支付功能",urlPatterns={"/mydo"})publicclasszhifubaoServletextendsHttpServlet{ privatestaticfinallongserialVersionUID=1L; @Override protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp) throwsServletException,IOException{ //TODOAuto-generatedmethodstub doPost(req,resp); } @Override protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp) throwsServletException,IOException{ req.setCharacterEncoding("utf-8"); //StringoutTradeNo,Stringsubject,StringtotalAmount,Stringbody System.out.println(req.getParameter("outTradeNo"));//买卖编号 System.out.println(req.getParameter("subject"));//商品 System.out.println(req.getParameter("totalAmount"));//总价 System.out.println(req.getParameter("body"));//商品描述信息 StringoutTradeNo,subject,totalAmount,body; outTradeNo=req.getParameter("outTradeNo"); subject=req.getParameter("subject"); totalAmount=req.getParameter("totalAmount"); body=req.getParameter("body"); OrderControllerorder=newOrderController(); try{ Stringformestr=order.alipay(outTradeNo,subject,totalAmount,body); req.setAttribute("mycalls",formestr); req.getRequestDispatcher("main.jsp").forward(req,resp); }catch(AlipayApiExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } }}
1