Implementation

Implementation Procedure

  1. The user initiates WeChat payment in the PC Browser
  2. The merchant system calls the OTT Pay API to make payment, and the OTT Pay server returns Payment Link
  3. Themerchant system generates a Payment QR Code based on the Payment Link and displays it in the PC web page
  4. The user scans the Payment QR Code with WeChat, and the WeChat wallet will be activated for payment
  5. The application obtains the payment result through Query Payment Status API

Flow Diagram

Code Example

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.eyJzdWIiOiJBQjAwMDAwMDA0OTUiLCJhdWRpZW5jZSI6bnVsbCwicm9sZSI6bnVsbCwiY3JlYXRlZCI6MTY3ODQ3NTg0MjgxMiwidXNlcnR5cGUiOiJDVVNUT01FUiIsImV4cCI6MTY3ODQ3Njc0MiwidXNlcmlkIjo5NX0.8MbJ4I8CrhrCKPALFuoCajnBw-KXyZDO8K1NGTHaQdazJh1C2jbBUaXKkXAgjSpm1GNmCZ5J6wtLM3livq-3rg";
Request request = new Request.Builder()
    .url("https://ecom-api.ottpay.com/api/v1/pay/weixin/active-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);

    // Response
    System.out.println(response.body().string());
} catch (IOException e) {
    throw new RuntimeException(e);
}