实现方法

实现流程

  1. 用户在电脑桌面端的浏览器中发起支付宝支付
  2. 商户系统调用 OTT Pay API 进行支付,OTT Pay 服务器返回 支付链接
  3. 商户系统在电脑桌面端浏览器中跳转到 支付链接,会调起支付宝收银台来进行支付

流程图

代码示例

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

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

final OkHttpClient httpClient = new OkHttpClient();
try (Response response = httpClient.newCall(request).execute()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
   
   // 响应结果
   System.out.println(response.body().string());
} catch (IOException e) {
    throw new RuntimeException(e);
}