backURL后台通知request域解析post

// 1. 从request中获取响应数据
		String notifyJsonStr = XhPayUtil.parseHttpRequest(req,
				Dict_xhPay_encoding.XHPAY_ENCODING_UTF8);

		log.info("==信合支付回调后台响应信息=={}", notifyJsonStr);

		// 2. 将json字符串解析成json对象
		JSONObject notifyJson = JSONObject.parseObject(notifyJsonStr);
		log.info("==信合支付回调后台响应信息解析json={}", notifyJson);

		String transData = notifyJson.getString("transData");// 交易信息
		String signMsg = notifyJson.getString("signMsg");// 签名信息
		Map notifyMap = notifyJson;
		log.info("==信合支付回调后台响应信息解析Map={}", notifyMap);
/**
	 * 读取请求题内容
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	public static String parseHttpRequest(HttpServletRequest request,
			String encoding) {
		// 请求原文
		StringBuffer sb = new StringBuffer();
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(
					request.getInputStream(), encoding));
			String str = null;
			while ((str = br.readLine()) != null || " ".equals(str)) {
				sb.append(str);
			}
		} catch (IOException e) {
			log.info("parseHttpRequest报错了!");
			return "";
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		String resultStr = sb.toString();

		// 防止用get传递参数
		if (" ".equals(resultStr)) {
			log.info("get传参");
			if (request.getQueryString() != null) {
				resultStr = request.getRequestURL() + "?"
						+ request.getQueryString();
			} else {
				resultStr = request.getRequestURL().toString();
			}
		}
		return resultStr;
	}

 

 

你可能感兴趣的:(支付)