---
url: "https://pay.weixin.qq.com/doc/v3/partner/4013892756-java.md"
title: "提交注销提现申请-请求示例-java"
doc_id: 4013892756
example_lang: "java"
---

## Java


需配合微信支付工具库 WXPayUtility 使用，请参考 [Java](https://pay.weixin.qq.com/doc/v3/partner/4014985777.md)

```
package com.java.demo;

import com.java.utils.WXPayUtility; // 引用微信支付工具库，参考：https://pay.weixin.qq.com/doc/v3/partner/4014985777

import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.Expose;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 提交注销提现申请API
 */
public class SubmitApply {
  private static String HOST = "https://api.mch.weixin.qq.com";
  private static String METHOD = "POST";
  private static String PATH = "/v3/ecommerce/account/apply-cancel-withdraw";

  public static void main(String[] args) {
    // TODO: 请准备商户开发必要参数，参考：https://pay.weixin.qq.com/doc/v3/partner/4013080340
    SubmitApply client = new SubmitApply(
      "19xxxxxxxx",                    // 商户号，是由微信支付系统生成并分配给每个商户的唯一标识符，商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340
      "1DDE55AD98Exxxxxxxxxx",         // 商户API证书序列号，如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924
      "/path/to/apiclient_key.pem",     // 商户API证书私钥文件路径，本地文件路径
      "PUB_KEY_ID_xxxxxxxxxxxxx",      // 微信支付公钥ID，如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589
      "/path/to/wxp_pub.pem"           // 微信支付公钥文件路径，本地文件路径
    );

    SubmitRequest request = new SubmitRequest();
    request.subMchid = "1900000109";
    request.outRequestNo = "P202410241010125346";
    request.withdraw = ApplyWithdraw.APPLY_WITHDRAW;
    request.payeeInfo = new PayeeInfo();
    request.payeeInfo.accountType = AccountType.ACCOUNT_TYPE_CORPORATE;
    request.payeeInfo.bankAccountInfo = new BankAccountInfo();
    request.payeeInfo.bankAccountInfo.accountName = client.encrypt("account_name");
    request.payeeInfo.bankAccountInfo.accountBank = "工商银行";
    request.payeeInfo.bankAccountInfo.bankBranchId = "402713354941";
    request.payeeInfo.bankAccountInfo.bankBranchName = "施秉县农村信用合作联社城关信用社";
    request.payeeInfo.bankAccountInfo.accountNumber = client.encrypt("account_number");
    request.payeeInfo.identityInfo = new IdentityInfo();
    request.payeeInfo.identityInfo.idDocType = IdentificationType.IDENTIFICATION_TYPE_ID_CARD;
    request.payeeInfo.identityInfo.identificationName = client.encrypt("identification_name");
    request.payeeInfo.identityInfo.identificationNo = client.encrypt("identification_no");
    request.proofMedias = new ArrayList<>();
    {
      ProofMedia proofMediasItem = new ProofMedia();
      proofMediasItem.proofMediaType = ProofMediaType.WITHDRAWAL_APPLICATION;
      proofMediasItem.proofMedia = "jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ";
      request.proofMedias.add(proofMediasItem);
    };
    request.additionalMaterials = new ArrayList<>();
    {
      request.additionalMaterials.add("jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ");
    };
    request.remark = "特殊理由";
    try {
      SubmitResponse response = client.run(request);
        // TODO: 请求成功，继续业务逻辑
        System.out.println(response);
    } catch (WXPayUtility.ApiException e) {
        // TODO: 请求失败，根据状态码执行不同的逻辑
        e.printStackTrace();
    }
  }

  public SubmitResponse run(SubmitRequest request) {
    String uri = PATH;
    String reqBody = WXPayUtility.toJson(request);

    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
    reqBuilder.addHeader("Accept", "application/json");
    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody));
    reqBuilder.addHeader("Content-Type", "application/json");
    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody);
    reqBuilder.method(METHOD, requestBody);
    Request httpRequest = reqBuilder.build();

    // 发送HTTP请求
    OkHttpClient client = new OkHttpClient.Builder().build();
    try (Response httpResponse = client.newCall(httpRequest).execute()) {
      String respBody = WXPayUtility.extractBody(httpResponse);
      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
        // 2XX 成功，验证应答签名
        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
            httpResponse.headers(), respBody);

        // 从HTTP应答报文构建返回数据
        return WXPayUtility.fromJson(respBody, SubmitResponse.class);
      } else {
        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
      }
    } catch (IOException e) {
      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
    }
  }

  private final String mchid;
  private final String certificateSerialNo;
  private final PrivateKey privateKey;
  private final String wechatPayPublicKeyId;
  private final PublicKey wechatPayPublicKey;

  public SubmitApply(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
    this.mchid = mchid;
    this.certificateSerialNo = certificateSerialNo;
    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
  }

  public String encrypt(String plainText) {
    return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText);
  }

  public static class SubmitRequest {
    @SerializedName("sub_mchid")
    public String subMchid;

    @SerializedName("out_request_no")
    public String outRequestNo;

    @SerializedName("withdraw")
    public ApplyWithdraw withdraw;

    @SerializedName("payee_info")
    public PayeeInfo payeeInfo;

    @SerializedName("proof_medias")
    public List<ProofMedia> proofMedias;

    @SerializedName("additional_materials")
    public List<String> additionalMaterials;

    @SerializedName("remark")
    public String remark;
  }

  public static class SubmitResponse {
    @SerializedName("applyment_id")
    public String applymentId;

    @SerializedName("out_request_no")
    public String outRequestNo;
  }

  public enum ApplyWithdraw {
    @SerializedName("NOT_APPLY_WITHDRAW")
    NOT_APPLY_WITHDRAW,
    @SerializedName("APPLY_WITHDRAW")
    APPLY_WITHDRAW
  }

  public static class PayeeInfo {
    @SerializedName("account_type")
    public AccountType accountType;

    @SerializedName("bank_account_info")
    public BankAccountInfo bankAccountInfo;

    @SerializedName("identity_info")
    public IdentityInfo identityInfo;
  }

  public static class ProofMedia {
    @SerializedName("proof_media_type")
    public ProofMediaType proofMediaType;

    @SerializedName("proof_media")
    public String proofMedia;
  }

  public enum AccountType {
    @SerializedName("ACCOUNT_TYPE_CORPORATE")
    ACCOUNT_TYPE_CORPORATE,
    @SerializedName("ACCOUNT_TYPE_PERSONAL")
    ACCOUNT_TYPE_PERSONAL
  }

  public static class BankAccountInfo {
    @SerializedName("account_name")
    public String accountName;

    @SerializedName("account_bank")
    public String accountBank;

    @SerializedName("bank_branch_id")
    public String bankBranchId;

    @SerializedName("bank_branch_name")
    public String bankBranchName;

    @SerializedName("account_number")
    public String accountNumber;
  }

  public static class IdentityInfo {
    @SerializedName("id_doc_type")
    public IdentificationType idDocType;

    @SerializedName("identification_name")
    public String identificationName;

    @SerializedName("identification_no")
    public String identificationNo;
  }

  public enum ProofMediaType {
    @SerializedName("WITHDRAWAL_APPLICATION")
    WITHDRAWAL_APPLICATION
  }

  public enum IdentificationType {
    @SerializedName("IDENTIFICATION_TYPE_ID_CARD")
    IDENTIFICATION_TYPE_ID_CARD,
    @SerializedName("IDENTIFICATION_TYPE_OVERSEA_PASSPORT")
    IDENTIFICATION_TYPE_OVERSEA_PASSPORT,
    @SerializedName("IDENTIFICATION_TYPE_HONGKONG_PASSPORT")
    IDENTIFICATION_TYPE_HONGKONG_PASSPORT,
    @SerializedName("IDENTIFICATION_TYPE_MACAO_PASSPORT")
    IDENTIFICATION_TYPE_MACAO_PASSPORT,
    @SerializedName("IDENTIFICATION_TYPE_TAIWAN_PASSPORT")
    IDENTIFICATION_TYPE_TAIWAN_PASSPORT,
    @SerializedName("IDENTIFICATION_TYPE_FOREIGN_RESIDENT")
    IDENTIFICATION_TYPE_FOREIGN_RESIDENT,
    @SerializedName("IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT")
    IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT,
    @SerializedName("IDENTIFICATION_TYPE_TAIWAN_RESIDENT")
    IDENTIFICATION_TYPE_TAIWAN_RESIDENT
  }

}

```
