接收支付宝的POST异步通知(回调)

public void  getUnSignData(HttpServletRequest request, HttpServletResponse response){
    try {
            //这里拿到支付宝通知数据
            Map requestParams = request.getParameterMap();
            for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
                String name = (String) iter.next();
                String[] values = (String[]) requestParams.get(name);
                String valueStr = "";
                for (int i = 0; i < values.length; i++) {
                    valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
                }
                // 乱码解决,这段代码在出现乱码时使用
                // valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
                params.put(name, valueStr);
            }
            //打印数据看看
            logger.debug("数据:"+gson.toJson(requestParams));
            //获取其中一个值看看
            String notifyType = params.get("notify_type");
      } catch(Exception e){
            logger.error("error",e);
    }
    //支付宝要求必须返回success,不然就会一直给你回调
    PrintWriter writer = null;
    writer = response.getWriter();
    writer.write("success"); // 一定要打印success
    writer.flush();
    return;
    
 }

你可能感兴趣的:(Java)