---
url: "https://pay.weixin.qq.com/doc/v3/partner/4012713017-java.md"
title: "提交申请单-请求示例-java"
doc_id: 4012713017
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;

/**
 * 二级商户进件申请
 */
public class SubmitApplyment {
  private static String HOST = "https://api.mch.weixin.qq.com";
  private static String METHOD = "POST";
  private static String PATH = "/v3/ecommerce/applyments/";

  public static void main(String[] args) {
    // TODO: 请准备商户开发必要参数，参考：https://pay.weixin.qq.com/doc/v3/partner/4013080340
    SubmitApplyment client = new SubmitApplyment(
      "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"           // 微信支付公钥文件路径，本地文件路径
    );

    SubmitReq request = new SubmitReq();
    request.outRequestNo = "APPLYMENT_00000000001";
    request.organizationType = "2";
    request.financeInstitution = true;
    request.businessLicenseInfo = new BusinessLicense();
    request.businessLicenseInfo.certType = CertificateType.CERTIFICATE_TYPE_2388;
    request.businessLicenseInfo.businessLicenseCopy = "47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.businessLicenseInfo.businessLicenseNumber = "123456789012345678";
    request.businessLicenseInfo.merchantName = "腾讯科技有限公司";
    request.businessLicenseInfo.legalPerson = "张三";
    request.businessLicenseInfo.companyAddress = "深圳南山区科苑路";
    request.businessLicenseInfo.businessTime = "[\\\"2014-01-01\\\",\\\"长期\\\"]";
    request.financeInstitutionInfo = new FinanceInstitutionInfo();
    request.financeInstitutionInfo.financeType = FinanceType.BANK_AGENT;
    request.financeInstitutionInfo.financeLicensePics = new ArrayList<>();
    {
      request.financeInstitutionInfo.financeLicensePics.add("example_financeLicensePics");
    };
    request.idHolderType = IdHolderType.LEGAL;
    request.idDocType = IdentificationType.IDENTIFICATION_TYPE_MACAO;
    request.authorizeLetterCopy = "47ZC6GC-vnrbEny_Ie_An5-tCpqxucuxi-vByf3Gjm7KEIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.idCardInfo = new IdCardInfo();
    request.idCardInfo.idCardCopy = "jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ";
    request.idCardInfo.idCardNational = "47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.idCardInfo.idCardName = client.encrypt("id_card_name");
    request.idCardInfo.idCardNumber = client.encrypt("id_card_number");
    request.idCardInfo.idCardValidTimeBegin = "2019-06-06";
    request.idCardInfo.idCardValidTime = "2026-06-06";
    request.idDocInfo = new IdDocInfo();
    request.idDocInfo.idDocName = client.encrypt("id_doc_name");
    request.idDocInfo.idDocNumber = client.encrypt("id_doc_number");
    request.idDocInfo.idDocCopy = "47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.idDocInfo.idDocCopyBack = "47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.idDocInfo.docPeriodBegin = "2019-06-06";
    request.idDocInfo.docPeriodEnd = "2020-01-02";
    request.owner = true;
    request.accountInfo = new AccountInfo();
    request.accountInfo.bankAccountType = "75";
    request.accountInfo.accountBank = "工商银行";
    request.accountInfo.accountName = client.encrypt("account_name");
    request.accountInfo.bankAddressCode = "110000";
    request.accountInfo.bankBranchId = "402713354941";
    request.accountInfo.bankName = "施秉县农村信用合作联社城关信用社";
    request.accountInfo.accountNumber = client.encrypt("account_number");
    request.contactInfo = new ContactInfo();
    request.contactInfo.contactType = "65";
    request.contactInfo.contactName = client.encrypt("contact_name");
    request.contactInfo.contactIdDocType = IdentificationType.IDENTIFICATION_TYPE_MACAO;
    request.contactInfo.contactIdCardNumber = client.encrypt("contact_id_card_number");
    request.contactInfo.contactIdDocCopy = "jTpGmxUX3FBWVQ5NJTZvvDujqhThn4ReFxikqJ5YW6zFQ";
    request.contactInfo.contactIdDocCopyBack = "jTpGmxUX3FBWVQ5NJTZvvDujqhThn4ReFxikqJ5YW6zFQ";
    request.contactInfo.contactIdDocPeriodBegin = "2019-06-06";
    request.contactInfo.contactIdDocPeriodEnd = "2026-06-06";
    request.contactInfo.businessAuthorizationLetter = "47ZC6GC-vnrbEny_Ie_An5-tCpqxucuxi-vByf3Gjm7KEIUv0OF4wFNIO4kqg05InE4d2I6_H7I4";
    request.contactInfo.mobilePhone = client.encrypt("mobile_phone");
    request.salesSceneInfo = new SalesSceneInfo();
    request.salesSceneInfo.storeName = "爱烧烤";
    request.salesSceneInfo.storeUrl = "http://www.qq.com";
    request.salesSceneInfo.storeQrCode = "jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ";
    request.salesSceneInfo.miniProgramSubAppid = "wxa123344545577";
    request.settlementInfo = new SettlementInfo();
    request.settlementInfo.settlementId = 719L;
    request.settlementInfo.qualificationType = "零售批发/生活娱乐/其他";
    request.merchantShortname = "腾讯";
    request.qualifications = "[\\\"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ\\\",\\\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4\\\"]";
    request.businessAdditionPics = "[\\\"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ\\\",\\\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4\\\"]";
    request.businessAdditionDesc = "特殊情况，说明原因";
    request.uboInfoList = new ArrayList<>();
    {
      UBOInfo uboInfoListItem = new UBOInfo();
      uboInfoListItem.uboIdDocType = IdentificationType.IDENTIFICATION_TYPE_MAINLAND_IDCARD;
      uboInfoListItem.uboIdDocCopy = "jTpGmxUXqRTvDujqhThn4ReFxikqJ5YW6zFQ";
      uboInfoListItem.uboIdDocCopyBack = "jTpGmxUX3FBWVQ5NJTZvvDujqhThn4ReFxikqJ5YW6zFQ";
      uboInfoListItem.uboIdDocName = client.encrypt("ubo_id_doc_name");
      uboInfoListItem.uboIdDocNumber = client.encrypt("ubo_id_doc_number");
      uboInfoListItem.uboIdDocAddress = client.encrypt("ubo_id_doc_address");
      uboInfoListItem.uboIdDocPeriodBegin = "2019-06-06";
      uboInfoListItem.uboIdDocPeriodEnd = "2026-06-06";
      request.uboInfoList.add(uboInfoListItem);
    };
    try {
      SubmitResp response = client.run(request);
        // TODO: 请求成功，继续业务逻辑
        System.out.println(response);
    } catch (WXPayUtility.ApiException e) {
        // TODO: 请求失败，根据状态码执行不同的逻辑
        e.printStackTrace();
    }
  }

  public SubmitResp run(SubmitReq 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, SubmitResp.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 SubmitApplyment(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 SubmitReq {
    @SerializedName("out_request_no")
    public String outRequestNo;

    @SerializedName("organization_type")
    public String organizationType;

    @SerializedName("finance_institution")
    public Boolean financeInstitution;

    @SerializedName("business_license_info")
    public BusinessLicense businessLicenseInfo;

    @SerializedName("finance_institution_info")
    public FinanceInstitutionInfo financeInstitutionInfo;

    @SerializedName("id_holder_type")
    public IdHolderType idHolderType;

    @SerializedName("id_doc_type")
    public IdentificationType idDocType;

    @SerializedName("authorize_letter_copy")
    public String authorizeLetterCopy;

    @SerializedName("id_card_info")
    public IdCardInfo idCardInfo;

    @SerializedName("id_doc_info")
    public IdDocInfo idDocInfo;

    @SerializedName("owner")
    public Boolean owner;

    @SerializedName("account_info")
    public AccountInfo accountInfo;

    @SerializedName("contact_info")
    public ContactInfo contactInfo;

    @SerializedName("sales_scene_info")
    public SalesSceneInfo salesSceneInfo;

    @SerializedName("settlement_info")
    public SettlementInfo settlementInfo;

    @SerializedName("merchant_shortname")
    public String merchantShortname;

    @SerializedName("qualifications")
    public String qualifications;

    @SerializedName("business_addition_pics")
    public String businessAdditionPics;

    @SerializedName("business_addition_desc")
    public String businessAdditionDesc;

    @SerializedName("ubo_info_list")
    public List<UBOInfo> uboInfoList;
  }

  public static class SubmitResp {
    @SerializedName("applyment_id")
    public Long applymentId;

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

  public static class BusinessLicense {
    @SerializedName("cert_type")
    public CertificateType certType;

    @SerializedName("business_license_copy")
    public String businessLicenseCopy;

    @SerializedName("business_license_number")
    public String businessLicenseNumber;

    @SerializedName("merchant_name")
    public String merchantName;

    @SerializedName("legal_person")
    public String legalPerson;

    @SerializedName("company_address")
    public String companyAddress;

    @SerializedName("business_time")
    public String businessTime;
  }

  public static class FinanceInstitutionInfo {
    @SerializedName("finance_type")
    public FinanceType financeType;

    @SerializedName("finance_license_pics")
    public List<String> financeLicensePics = new ArrayList<String>();
  }

  public enum IdHolderType {
    @SerializedName("LEGAL")
    LEGAL,
    @SerializedName("SUPER")
    SUPER
  }

  public enum IdentificationType {
    @SerializedName("IDENTIFICATION_TYPE_MAINLAND_IDCARD")
    IDENTIFICATION_TYPE_MAINLAND_IDCARD,
    @SerializedName("IDENTIFICATION_TYPE_OVERSEA_PASSPORT")
    IDENTIFICATION_TYPE_OVERSEA_PASSPORT,
    @SerializedName("IDENTIFICATION_TYPE_HONGKONG")
    IDENTIFICATION_TYPE_HONGKONG,
    @SerializedName("IDENTIFICATION_TYPE_MACAO")
    IDENTIFICATION_TYPE_MACAO,
    @SerializedName("IDENTIFICATION_TYPE_TAIWAN")
    IDENTIFICATION_TYPE_TAIWAN,
    @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
  }

  public static class IdCardInfo {
    @SerializedName("id_card_copy")
    public String idCardCopy;

    @SerializedName("id_card_national")
    public String idCardNational;

    @SerializedName("id_card_name")
    public String idCardName;

    @SerializedName("id_card_number")
    public String idCardNumber;

    @SerializedName("id_card_valid_time_begin")
    public String idCardValidTimeBegin;

    @SerializedName("id_card_valid_time")
    public String idCardValidTime;
  }

  public static class IdDocInfo {
    @SerializedName("id_doc_name")
    public String idDocName;

    @SerializedName("id_doc_number")
    public String idDocNumber;

    @SerializedName("id_doc_copy")
    public String idDocCopy;

    @SerializedName("id_doc_copy_back")
    public String idDocCopyBack;

    @SerializedName("doc_period_begin")
    public String docPeriodBegin;

    @SerializedName("doc_period_end")
    public String docPeriodEnd;
  }

  public static class AccountInfo {
    @SerializedName("bank_account_type")
    public String bankAccountType;

    @SerializedName("account_bank")
    public String accountBank;

    @SerializedName("account_name")
    public String accountName;

    @SerializedName("bank_address_code")
    public String bankAddressCode;

    @SerializedName("bank_branch_id")
    public String bankBranchId;

    @SerializedName("bank_name")
    public String bankName;

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

  public static class ContactInfo {
    @SerializedName("contact_type")
    public String contactType;

    @SerializedName("contact_name")
    public String contactName;

    @SerializedName("contact_id_doc_type")
    public IdentificationType contactIdDocType;

    @SerializedName("contact_id_card_number")
    public String contactIdCardNumber;

    @SerializedName("contact_id_doc_copy")
    public String contactIdDocCopy;

    @SerializedName("contact_id_doc_copy_back")
    public String contactIdDocCopyBack;

    @SerializedName("contact_id_doc_period_begin")
    public String contactIdDocPeriodBegin;

    @SerializedName("contact_id_doc_period_end")
    public String contactIdDocPeriodEnd;

    @SerializedName("business_authorization_letter")
    public String businessAuthorizationLetter;

    @SerializedName("mobile_phone")
    public String mobilePhone;
  }

  public static class SalesSceneInfo {
    @SerializedName("store_name")
    public String storeName;

    @SerializedName("store_url")
    public String storeUrl;

    @SerializedName("store_qr_code")
    public String storeQrCode;

    @SerializedName("mini_program_sub_appid")
    public String miniProgramSubAppid;
  }

  public static class SettlementInfo {
    @SerializedName("settlement_id")
    public Long settlementId;

    @SerializedName("qualification_type")
    public String qualificationType;
  }

  public static class UBOInfo {
    @SerializedName("ubo_id_doc_type")
    public IdentificationType uboIdDocType;

    @SerializedName("ubo_id_doc_copy")
    public String uboIdDocCopy;

    @SerializedName("ubo_id_doc_copy_back")
    public String uboIdDocCopyBack;

    @SerializedName("ubo_id_doc_name")
    public String uboIdDocName;

    @SerializedName("ubo_id_doc_number")
    public String uboIdDocNumber;

    @SerializedName("ubo_id_doc_address")
    public String uboIdDocAddress;

    @SerializedName("ubo_id_doc_period_begin")
    public String uboIdDocPeriodBegin;

    @SerializedName("ubo_id_doc_period_end")
    public String uboIdDocPeriodEnd;
  }

  public enum CertificateType {
    @SerializedName("CERTIFICATE_TYPE_2388")
    CERTIFICATE_TYPE_2388,
    @SerializedName("CERTIFICATE_TYPE_2389")
    CERTIFICATE_TYPE_2389,
    @SerializedName("CERTIFICATE_TYPE_2394")
    CERTIFICATE_TYPE_2394,
    @SerializedName("CERTIFICATE_TYPE_2395")
    CERTIFICATE_TYPE_2395,
    @SerializedName("CERTIFICATE_TYPE_2396")
    CERTIFICATE_TYPE_2396,
    @SerializedName("CERTIFICATE_TYPE_2399")
    CERTIFICATE_TYPE_2399,
    @SerializedName("CERTIFICATE_TYPE_2400")
    CERTIFICATE_TYPE_2400,
    @SerializedName("CERTIFICATE_TYPE_2520")
    CERTIFICATE_TYPE_2520,
    @SerializedName("CERTIFICATE_TYPE_2521")
    CERTIFICATE_TYPE_2521,
    @SerializedName("CERTIFICATE_TYPE_2522")
    CERTIFICATE_TYPE_2522
  }

  public enum FinanceType {
    @SerializedName("BANK_AGENT")
    BANK_AGENT,
    @SerializedName("PAYMENT_AGENT")
    PAYMENT_AGENT,
    @SerializedName("INSURANCE")
    INSURANCE,
    @SerializedName("TRADE_AND_SETTLE")
    TRADE_AND_SETTLE,
    @SerializedName("OTHER")
    OTHER
  }

}

```
