实现方法

实现流程

  1. 用户在移动端浏览器中发起支付宝支付。
  2. 商户系统调用 OTT Pay API 进行支付,OTT Pay 服务器返回 支付跳转链接
  3. 商户系统跳转到此 支付跳转链接 会调起支付宝钱包进行支付
  4. 支付结果将通过回调的方式通知到商户系统

代码示例

Map<String, Object> data = new HashMap<>();
data.put("amount", "1");
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.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgyMDE3OTU3NTQsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMTA3OTUsInVzZXJpZCI6MTMwfQ.Y77IAPtuEhawmcBQl9E22g8G7oZYNKClZUgWD7J28wj9Z5Hq_cI3ESG_2nmD_Uma862Z1OX3dSjPpE0OF0LHGg";
Request request = new Request.Builder()
       .url("https://ecom-api.ottpay.com/api/v1/pay/weixin/h5-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);
}

返回响应结果中的 payInfo 中就是 支付跳转链接,前端页面直接调转到此链接,可调起支付宝钱包进行支付。