java得到PayU api poland的回复

时间:2017-10-01 10:51:07

标签: java jsp curl payu

我正在尝试将payu波兰支付系统整合到我的网站,但无法获得成功回应。网站由jsp完成。以下是payu为帮助click使用“创建新订单”进行配置的链接。但它没有找回任何答案。 anywane可以帮助我吗?这是我的jsp代码:

 `public static String sendPostRequest2(String requestUrl, String payload, String x, String y) {
    StringBuilder jsonString = new StringBuilder();
    try {
        URL url = new URL(requestUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");

        connection.setRequestProperty("Content-Type", "application/json");
        try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8")) {
            writer.write(payload);
        }
        connection.setRequestProperty(x, y);
        try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String line;
            while ((line = br.readLine()) != null) {
                jsonString.append(line);
                jsonString.append("<br>\n");
            }
        }
        connection.disconnect();
    } catch (IOException e) {
        try {
            URL url = new URL(requestUrl);
            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
            InputStream is;
            if (httpConn.getResponseCode() >= 400) {
                is = httpConn.getErrorStream();
            } else {
                is = httpConn.getInputStream();
            }
            try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
                String line;
                while ((line = br.readLine()) != null) {
                    jsonString.append(line);
                    jsonString.append("<br>\n");
                }
            }
            jsonString.append(new RuntimeException(e.getMessage()));
        } catch (MalformedURLException ex) {
            jsonString.append(new RuntimeException(ex.getMessage()));
            Logger.getLogger(PayU.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            jsonString.append(new RuntimeException(ex.getMessage()));
            Logger.getLogger(PayU.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return jsonString.toString();
}
public static String get() {
    String x = "";
    String payload2 = "{  'notifyUrl': 'https://your.eshop.com/notify',  'customerIp': '127.0.0.1',  'merchantPosId': '145227',  'description': 'RTV market',  'currencyCode': 'PLN',  'totalAmount': '21000',  'products': [    {      'name': 'Wireless mouse',      'unitPrice': '15000',      'quantity': '1'    },    {      'name': 'HDMI cable',      'unitPrice': '6000',      'quantity': '1'    }  ]}";
    String requestUrl2 = "https://secure.payu.com/api/v2_1/orders/";
    x += sendPostRequest2(requestUrl2, payload2, "Authorization", "Bearer 3e5cac39-7e38-4139-8fd6-30adc06a61bd");

    return x;
}`

1 个答案:

答案 0 :(得分:0)

设置重定向关闭后,您将获得json响应。所以在你的java代码中重定向为false。 connection.setInstanceFollowRedirects(假);