1. 程式人生 > >App支付寶H5支付回撥函式編寫記錄

App支付寶H5支付回撥函式編寫記錄

記錄一下從零開始開發App支付寶H5支付的回撥函式的過程。 系統環境:64位Win10 JDK版本:1.8.0_181 思路:搭建Java環境,編寫簡單的Web專案,用Servlet實現介面功能。

1,下載安裝Eclipse 用eclipse_v4.7.0進行下載 連結:https://pan.baidu.com/s/1JHskgf7DkLi_XkEnyOuxxg 密碼:wcnc 選擇Eclipse IDE for Java EE Developers,因為只有這個裡面有Dynamic Web Project

3,建立Server和Web Project Eclipse中新建Dynamic Web Project專案TestSDK,在Project Explorer - TestSDK - Java Resources - src 下面新建Servlet,名叫TYBCallback。

/**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//  response.getWriter().append("Served at: ").append(request.getContextPath());
//  System.out.println(request.getQueryString());
try { File f = new File(""); String absolutePath = f.getAbsolutePath(); String fullPath = absolutePath + "\\TestSDK.txt"; FileWriter fw = new FileWriter(fullPath,true); String param = request.getQueryString(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//設定日期格式
String content = df.format(new Date()) + " " + param + "\r\n"; fw.write(content); fw.close(); } catch (Exception e) { e.printStackTrace(); } response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print("success"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }

只能用localhost不能用IP訪問時,將防火牆關掉