---
url: "https://pay.weixin.qq.com/doc/v3/partner/4012803072-java.md"
title: "查询子商户管控情况 -请求示例-java"
doc_id: 4012803072
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 QuerySubMchLimitation {
  private static String HOST = "https://api.mch.weixin.qq.com";
  private static String METHOD = "GET";
  private static String PATH = "/v3/mch-operation-manage/merchant-limitations/sub-mchid/{sub_mchid}";

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

    QuerySubMchLimitationRequest request = new QuerySubMchLimitationRequest();
    request.subMchid = "123000110";
    try {
      MchLimitation response = client.run(request);
        // TODO: 请求成功，继续业务逻辑
        System.out.println(response);
    } catch (WXPayUtility.ApiException e) {
        // TODO: 请求失败，根据状态码执行不同的逻辑
        e.printStackTrace();
    }
  }

  public MchLimitation run(QuerySubMchLimitationRequest request) {
    String uri = PATH;
    uri = uri.replace("{sub_mchid}", WXPayUtility.urlEncode(request.subMchid));

    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, null));
    reqBuilder.method(METHOD, null);
    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, MchLimitation.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 QuerySubMchLimitation(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 static class QuerySubMchLimitationRequest {
    @SerializedName("sub_mchid")
    @Expose(serialize = false)
    public String subMchid;
  }

  public static class MchLimitation {
    @SerializedName("mchid")
    public String mchid;

    @SerializedName("limited_functions")
    public List<EnumTypeFunctionLimitation> limitedFunctions;

    @SerializedName("other_limited_functions")
    public String otherLimitedFunctions;

    @SerializedName("recovery_specifications")
    public List<MchLimitationReasonAndRecoverWay> recoverySpecifications;
  }

  public enum EnumTypeFunctionLimitation {
    @SerializedName("NO_TRANSACTION_AND_RECHARGE")
    NO_TRANSACTION_AND_RECHARGE,
    @SerializedName("NO_PAYMENT")
    NO_PAYMENT,
    @SerializedName("NO_WITHDRAWAL")
    NO_WITHDRAWAL,
    @SerializedName("NO_REFUND")
    NO_REFUND,
    @SerializedName("NO_TRANSACTION")
    NO_TRANSACTION,
    @SerializedName("NO_PROFIT_SHARING")
    NO_PROFIT_SHARING,
    @SerializedName("NO_PAYMENT_POINT_COMPLETE_ORDER")
    NO_PAYMENT_POINT_COMPLETE_ORDER
  }

  public static class MchLimitationReasonAndRecoverWay {
    @SerializedName("limitation_case_id")
    public String limitationCaseId;

    @SerializedName("limitation_reason_type")
    public EnumTypeLimitationReason limitationReasonType;

    @SerializedName("limitation_reason")
    public String limitationReason;

    @SerializedName("limitation_reason_describe")
    public String limitationReasonDescribe;

    @SerializedName("relate_limitations")
    public List<EnumTypeFunctionLimitation> relateLimitations;

    @SerializedName("other_relate_limitations")
    public String otherRelateLimitations;

    @SerializedName("recover_way")
    public EnumTypeRecoveWay recoverWay;

    @SerializedName("recover_way_param")
    public String recoverWayParam;

    @SerializedName("recover_help_url")
    public String recoverHelpUrl;

    @SerializedName("limitation_action_type")
    public EnumTypeLimitActionType limitationActionType;

    @SerializedName("limitation_start_date")
    public String limitationStartDate;

    @SerializedName("limitation_date")
    public String limitationDate;
  }

  public enum EnumTypeLimitationReason {
    @SerializedName("LICENSE_ABNORMAL")
    LICENSE_ABNORMAL,
    @SerializedName("NO_TRADE")
    NO_TRADE,
    @SerializedName("SETTLE_ACCOUNT_ABNORMAL")
    SETTLE_ACCOUNT_ABNORMAL,
    @SerializedName("RISK_ABNORMAL")
    RISK_ABNORMAL,
    @SerializedName("OTHER")
    OTHER,
    @SerializedName("INSPECT_ABNORMAL")
    INSPECT_ABNORMAL,
    @SerializedName("INVALID_REPRESENTATIVE_INFORMATION")
    INVALID_REPRESENTATIVE_INFORMATION,
    @SerializedName("INVALID_BUSINESS_STATUS")
    INVALID_BUSINESS_STATUS,
    @SerializedName("INVALID_BUSINESS_LICENSE")
    INVALID_BUSINESS_LICENSE,
    @SerializedName("INVALID_BENEFICIARY_INFORMATION")
    INVALID_BENEFICIARY_INFORMATION
  }

  public enum EnumTypeRecoveWay {
    @SerializedName("IRRECOVERABLE")
    IRRECOVERABLE,
    @SerializedName("MODIFY_SUBJECT_INFORMATION")
    MODIFY_SUBJECT_INFORMATION,
    @SerializedName("MODIFY_SETTLE_ACCOUNT_INFORMATION")
    MODIFY_SETTLE_ACCOUNT_INFORMATION,
    @SerializedName("VERIFY_INACTIVE_MERCHANT_IDENTITY")
    VERIFY_INACTIVE_MERCHANT_IDENTITY,
    @SerializedName("SUBMIT_OFFLINE_BUSINESS_SCENARIO_INFORMATION")
    SUBMIT_OFFLINE_BUSINESS_SCENARIO_INFORMATION,
    @SerializedName("SUBMIT_INFORMATION_FOR_APPEAL")
    SUBMIT_INFORMATION_FOR_APPEAL,
    @SerializedName("RESOLVE_TRANSACTION_DISPUTES")
    RESOLVE_TRANSACTION_DISPUTES,
    @SerializedName("MODIFY_ADMINISTRATOR_INFORMATION")
    MODIFY_ADMINISTRATOR_INFORMATION,
    @SerializedName("CALL_CUSTOMER_SERVICE_AT_95017")
    CALL_CUSTOMER_SERVICE_AT_95017,
    @SerializedName("UPDATE_BUSINESS_SCENARIO_INFORMATION")
    UPDATE_BUSINESS_SCENARIO_INFORMATION,
    @SerializedName("SUBMIT_CDD_INFORMATION")
    SUBMIT_CDD_INFORMATION,
    @SerializedName("WAITING_FOR_PLATFORM_REVIEW")
    WAITING_FOR_PLATFORM_REVIEW,
    @SerializedName("SUBMIT_UBO_INFORMATION")
    SUBMIT_UBO_INFORMATION,
    @SerializedName("SIGN_ANTI_FRAUD_PLEDGE_AND_VERIFY_FACE")
    SIGN_ANTI_FRAUD_PLEDGE_AND_VERIFY_FACE,
    @SerializedName("CONTACT_APPROPRIATE_AUTHORITY_FOR_CONSULTATION")
    CONTACT_APPROPRIATE_AUTHORITY_FOR_CONSULTATION,
    @SerializedName("MODIFY_ABBREVIATION_INFORMATION")
    MODIFY_ABBREVIATION_INFORMATION,
    @SerializedName("CONFIRM_BUSINESS_TYPE")
    CONFIRM_BUSINESS_TYPE,
    @SerializedName("SUBMIT_ONLINE_BUSINESS_SCENARIO_INFORMATION")
    SUBMIT_ONLINE_BUSINESS_SCENARIO_INFORMATION
  }

  public enum EnumTypeLimitActionType {
    @SerializedName("LIMIT_ACTION_TYPE_IMMEDIATE_CONTROL")
    LIMIT_ACTION_TYPE_IMMEDIATE_CONTROL,
    @SerializedName("LIMIT_ACTION_TYPE_DELAY_CONTROL")
    LIMIT_ACTION_TYPE_DELAY_CONTROL
  }

}

```
