Implementation
Implementation Procedure
- The user initiates WeChat payment on the WeChat internal browser
- The web page program calls the OTT Pay API to make payment, and the OTT Pay server returns Payment Navigation Link
- The web page program uses navigate to Payment Navigation Link to call the WeChat wallet for payment
- After the user pays, regardless of success or failure, it will jump to the returnURL provided in the request parameter, and the URL returned by the navigation will have paymentId=xxxx (xxxx is the paymentId returned by OTT Pay)
Code Example
Get Payment Parameters:
Map<String, Object> data = new HashMap<>();
data.put("amount", "100");
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.eyJzdWIiOiJBQjAwMDAwMDA0OTUiLCJhdWRpZW5jZSI6bnVsbCwicm9sZSI6bnVsbCwiY3JlYXRlZCI6MTY3ODQ3MTEwMjU5NiwidXNlcnR5cGUiOiJDVVNUT01FUiIsImV4cCI6MTY3ODQ3MjAwMiwidXNlcmlkIjo5NX0.UjhYQc5UCMiKiSiuClEMn1ugPcUYQWvD81qmN2awToWsJOInq-S6LFtaNaoZosRMm__UUT2UMjO2CCfTHrThJg";
Request request = new Request.Builder()
.url("https://ecom-api.ottpay.com/api/v1/pay/weixin/public-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);
}
// Response
System.out.println(response.body().string());
} catch (IOException e) {
throw new RuntimeException(e);
}
The payInfo in the returned result is the payment navigation link, and the web page will navigate to this link for payment to complete