实现方法

实现流程

  1. 用户在电脑桌面端的浏览器中发起微信支付
  2. 商户系统调用 OTT Pay API 进行支付,OTT Pay 服务器返回 支付链接
  3. 商户系统前端页面根据 支付链接 生成 支付二维码,并在电脑桌面端浏览器中显示
  4. 用户用微信扫描 支付二维码 会调起微信钱包进行支付
  5. 应用程序通过 查询支付状态 API 获得支付结果

流程图

代码示例

调用 微信电脑桌面端扫码支付 API,获得微信支付链接
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);
    
    // 响应结果
    System.out.println(response.body().string());
} catch (IOException e) {
    throw new RuntimeException(e);
}