实现方法

实现流程

  1. 用户在移动端浏览器中发起银联支付
  2. 商户系统调用 OTT Pay API 进行支付,OTT Pay 服务器返回 Form(HTML)
  3. 商户系统将此 Form(HTML) 嵌入到前端网页中,通过代码提交此 Form (可以做成支付按钮由用户点击进行提交) 会调起银联支付页面或云闪付 APP 进行支付
  4. 支付完成前端会跳转到请求参数中指定的 returnURL
  5. 支付结果也会通过回调的方式通知到商户系统

代码示例

获得 Form 代码:

Map<String, Object> data = new HashMap<>();
data.put("amount", "100");
data.put("callbackURL", "https://your.callback.url");
data.put("returnURL", "https://your.return.url");

Gson gson = new Gson();
RequestBody body = RequestBody.create(gson.toJson(data), MediaType.parse("application/json; charset=utf-8"));
String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgyMTU4MDU2NjYsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMjQ4MDUsInVzZXJpZCI6MTMwfQ.WVpasVp958R6kHOcqC3QgQjCqTXIkyagutkONxCV97yT_hmp9Q6WaZ921cjxhzJA4v2Bhd0RTF5QHMLddVnzOQ";
Request request = new Request.Builder()
        .url("https://ecom-api.ottpay.com/api/v1/pay/unionpay/web-secure-pay")
        .addHeader("Authorization", "Bearer " + token)
        .post(body)
        .build();

final OkHttpClient httpClient = new OkHttpClient();
try (Response response = httpClient.newCall(request).execute()) {

    if (!response.isSuccessful()) {
        System.out.println(response.body().string());
        throw new IOException("Unexpected code " + response);
    }

    // 响应结果
    System.out.println(response.body().string());
} catch (IOException e) {
    throw new RuntimeException(e);
}

WEB APP 代码示例: