实现方法

实现流程

  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("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.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgxOTkwMTY2OTAsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMDgwMTYsInVzZXJpZCI6MTMwfQ.VhP7j4Y8fjOLFm2d_Mm8INhotX68GnHFDG4XiDQEJdxuqLMjBxsRw2sBzrqM7CXNdBW0kn8jKHGhMhVwPVkgoQ";
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 中就是支付跳转链接,前端页面跳转到此链接可以调起微信钱包进行支付。