代码示例

Map<String, Object> data=new HashMap<>();

data.put("amount","100");
data.put("accountNumber","4000620000000007");
data.put("accountName","Some One");
data.put("accountExpire","0625");
data.put("cvn2","737");
data.put("sslAvsAddress","100 Yong stree");
data.put("sslAvsCity","Toronto");
data.put("sslAvsCountry","CA");
data.put("sslAvsZip","XXX XXX");
data.put("sslEciInd","XXX XXX");
data.put("ssl3dsecureValue","XXX XXX");
data.put("sslDirServerTranId","XXX XXX");
data.put("callbackURL","https://your.callback.url");

Gson gson=new Gson();
RequestBody body=RequestBody.create(gson.toJson(data),MediaType.parse("application/json; charset=utf-8"));
String token="eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgyMTU4MDU2NjYsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMjQ4MDUsInVzZXJpZCI6MTMwfQ.WVpasVp958R6kHOcqC3QgQjCqTXIkyagutkONxCV97yT_hmp9Q6WaZ921cjxhzJA4v2Bhd0RTF5QHMLddVnzOQ";
Request request=new Request.Builder()
        .url("https://ecom-api.ottpay.com/api/v1/payment/local-card/payment")
        .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);
}