---
url: "https://pay.weixin.qq.com/doc/v3/partner/4012803072-go.md"
title: "查询子商户管控情况 -请求示例-go"
doc_id: 4012803072
example_lang: "go"
---

## Go


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

```
package main

import (
	"demo/wxpay_utility" // 引用微信支付工具库，参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
	"strings"
)

func main() {
	// TODO: 请准备商户开发必要参数，参考：https://pay.weixin.qq.com/doc/v3/partner/4013080340
	config, err := wxpay_utility.CreateMchConfig(
		"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",       // 微信支付公钥文件路径，本地文件路径
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	request := &QuerySubMchLimitationRequest{
		SubMchid: wxpay_utility.String("123000110"),
	}

	response, err := QuerySubMchLimitation(config, request)
	if err != nil {
		fmt.Printf("请求失败: %+v\n", err)
		// TODO: 请求失败，根据状态码执行不同的处理
		return
	}

	// TODO: 请求成功，继续业务逻辑
	fmt.Printf("请求成功: %+v\n", response)
}

func QuerySubMchLimitation(config *wxpay_utility.MchConfig, request *QuerySubMchLimitationRequest) (response *MchLimitation, err error) {
	const (
		host   = "https://api.mch.weixin.qq.com"
		method = "GET"
		path   = "/v3/mch-operation-manage/merchant-limitations/sub-mchid/{sub_mchid}"
	)

	reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
	if err != nil {
		return nil, err
	}
	reqUrl.Path = strings.Replace(reqUrl.Path, "{sub_mchid}", url.PathEscape(*request.SubMchid), -1)
	httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
	if err != nil {
		return nil, err
	}
	httpRequest.Header.Set("Accept", "application/json")
	httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
	authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
	if err != nil {
		return nil, err
	}
	httpRequest.Header.Set("Authorization", authorization)

	client := &http.Client{}
	httpResponse, err := client.Do(httpRequest)
	if err != nil {
		return nil, err
	}
	respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
	if err != nil {
		return nil, err
	}
	if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
		// 2XX 成功，验证应答签名
		err = wxpay_utility.ValidateResponse(
			config.WechatPayPublicKeyId(),
			config.WechatPayPublicKey(),
			&httpResponse.Header,
			respBody,
		)
		if err != nil {
			return nil, err
		}
		response := &MchLimitation{}
		if err := json.Unmarshal(respBody, response); err != nil {
			return nil, err
		}

		return response, nil
	} else {
		return nil, wxpay_utility.NewApiException(
			httpResponse.StatusCode,
			httpResponse.Header,
			respBody,
		)
	}
}

type QuerySubMchLimitationRequest struct {
	SubMchid *string `json:"sub_mchid,omitempty"`
}

func (o *QuerySubMchLimitationRequest) MarshalJSON() ([]byte, error) {
	type Alias QuerySubMchLimitationRequest
	a := &struct {
		SubMchid *string `json:"sub_mchid,omitempty"`
		*Alias
	}{
		// 序列化时移除非 Body 字段
		SubMchid: nil,
		Alias:    (*Alias)(o),
	}
	return json.Marshal(a)
}

type MchLimitation struct {
	Mchid                  *string                            `json:"mchid,omitempty"`
	LimitedFunctions       []EnumTypeFunctionLimitation       `json:"limited_functions,omitempty"`
	OtherLimitedFunctions  *string                            `json:"other_limited_functions,omitempty"`
	RecoverySpecifications []MchLimitationReasonAndRecoverWay `json:"recovery_specifications,omitempty"`
}

type EnumTypeFunctionLimitation string

func (e EnumTypeFunctionLimitation) Ptr() *EnumTypeFunctionLimitation {
	return &e
}

const (
	ENUMTYPEFUNCTIONLIMITATION_NO_TRANSACTION_AND_RECHARGE     EnumTypeFunctionLimitation = "NO_TRANSACTION_AND_RECHARGE"
	ENUMTYPEFUNCTIONLIMITATION_NO_PAYMENT                      EnumTypeFunctionLimitation = "NO_PAYMENT"
	ENUMTYPEFUNCTIONLIMITATION_NO_WITHDRAWAL                   EnumTypeFunctionLimitation = "NO_WITHDRAWAL"
	ENUMTYPEFUNCTIONLIMITATION_NO_REFUND                       EnumTypeFunctionLimitation = "NO_REFUND"
	ENUMTYPEFUNCTIONLIMITATION_NO_TRANSACTION                  EnumTypeFunctionLimitation = "NO_TRANSACTION"
	ENUMTYPEFUNCTIONLIMITATION_NO_PROFIT_SHARING               EnumTypeFunctionLimitation = "NO_PROFIT_SHARING"
	ENUMTYPEFUNCTIONLIMITATION_NO_PAYMENT_POINT_COMPLETE_ORDER EnumTypeFunctionLimitation = "NO_PAYMENT_POINT_COMPLETE_ORDER"
)

type MchLimitationReasonAndRecoverWay struct {
	LimitationCaseId         *string                      `json:"limitation_case_id,omitempty"`
	LimitationReasonType     *EnumTypeLimitationReason    `json:"limitation_reason_type,omitempty"`
	LimitationReason         *string                      `json:"limitation_reason,omitempty"`
	LimitationReasonDescribe *string                      `json:"limitation_reason_describe,omitempty"`
	RelateLimitations        []EnumTypeFunctionLimitation `json:"relate_limitations,omitempty"`
	OtherRelateLimitations   *string                      `json:"other_relate_limitations,omitempty"`
	RecoverWay               *EnumTypeRecoveWay           `json:"recover_way,omitempty"`
	RecoverWayParam          *string                      `json:"recover_way_param,omitempty"`
	RecoverHelpUrl           *string                      `json:"recover_help_url,omitempty"`
	LimitationActionType     *EnumTypeLimitActionType     `json:"limitation_action_type,omitempty"`
	LimitationStartDate      *string                      `json:"limitation_start_date,omitempty"`
	LimitationDate           *string                      `json:"limitation_date,omitempty"`
}

type EnumTypeLimitationReason string

func (e EnumTypeLimitationReason) Ptr() *EnumTypeLimitationReason {
	return &e
}

const (
	ENUMTYPELIMITATIONREASON_LICENSE_ABNORMAL                   EnumTypeLimitationReason = "LICENSE_ABNORMAL"
	ENUMTYPELIMITATIONREASON_NO_TRADE                           EnumTypeLimitationReason = "NO_TRADE"
	ENUMTYPELIMITATIONREASON_SETTLE_ACCOUNT_ABNORMAL            EnumTypeLimitationReason = "SETTLE_ACCOUNT_ABNORMAL"
	ENUMTYPELIMITATIONREASON_RISK_ABNORMAL                      EnumTypeLimitationReason = "RISK_ABNORMAL"
	ENUMTYPELIMITATIONREASON_OTHER                              EnumTypeLimitationReason = "OTHER"
	ENUMTYPELIMITATIONREASON_INSPECT_ABNORMAL                   EnumTypeLimitationReason = "INSPECT_ABNORMAL"
	ENUMTYPELIMITATIONREASON_INVALID_REPRESENTATIVE_INFORMATION EnumTypeLimitationReason = "INVALID_REPRESENTATIVE_INFORMATION"
	ENUMTYPELIMITATIONREASON_INVALID_BUSINESS_STATUS            EnumTypeLimitationReason = "INVALID_BUSINESS_STATUS"
	ENUMTYPELIMITATIONREASON_INVALID_BUSINESS_LICENSE           EnumTypeLimitationReason = "INVALID_BUSINESS_LICENSE"
	ENUMTYPELIMITATIONREASON_INVALID_BENEFICIARY_INFORMATION    EnumTypeLimitationReason = "INVALID_BENEFICIARY_INFORMATION"
)

type EnumTypeRecoveWay string

func (e EnumTypeRecoveWay) Ptr() *EnumTypeRecoveWay {
	return &e
}

const (
	ENUMTYPERECOVEWAY_IRRECOVERABLE                                  EnumTypeRecoveWay = "IRRECOVERABLE"
	ENUMTYPERECOVEWAY_MODIFY_SUBJECT_INFORMATION                     EnumTypeRecoveWay = "MODIFY_SUBJECT_INFORMATION"
	ENUMTYPERECOVEWAY_MODIFY_SETTLE_ACCOUNT_INFORMATION              EnumTypeRecoveWay = "MODIFY_SETTLE_ACCOUNT_INFORMATION"
	ENUMTYPERECOVEWAY_VERIFY_INACTIVE_MERCHANT_IDENTITY              EnumTypeRecoveWay = "VERIFY_INACTIVE_MERCHANT_IDENTITY"
	ENUMTYPERECOVEWAY_SUBMIT_OFFLINE_BUSINESS_SCENARIO_INFORMATION   EnumTypeRecoveWay = "SUBMIT_OFFLINE_BUSINESS_SCENARIO_INFORMATION"
	ENUMTYPERECOVEWAY_SUBMIT_INFORMATION_FOR_APPEAL                  EnumTypeRecoveWay = "SUBMIT_INFORMATION_FOR_APPEAL"
	ENUMTYPERECOVEWAY_RESOLVE_TRANSACTION_DISPUTES                   EnumTypeRecoveWay = "RESOLVE_TRANSACTION_DISPUTES"
	ENUMTYPERECOVEWAY_MODIFY_ADMINISTRATOR_INFORMATION               EnumTypeRecoveWay = "MODIFY_ADMINISTRATOR_INFORMATION"
	ENUMTYPERECOVEWAY_CALL_CUSTOMER_SERVICE_AT_95017                 EnumTypeRecoveWay = "CALL_CUSTOMER_SERVICE_AT_95017"
	ENUMTYPERECOVEWAY_UPDATE_BUSINESS_SCENARIO_INFORMATION           EnumTypeRecoveWay = "UPDATE_BUSINESS_SCENARIO_INFORMATION"
	ENUMTYPERECOVEWAY_SUBMIT_CDD_INFORMATION                         EnumTypeRecoveWay = "SUBMIT_CDD_INFORMATION"
	ENUMTYPERECOVEWAY_WAITING_FOR_PLATFORM_REVIEW                    EnumTypeRecoveWay = "WAITING_FOR_PLATFORM_REVIEW"
	ENUMTYPERECOVEWAY_SUBMIT_UBO_INFORMATION                         EnumTypeRecoveWay = "SUBMIT_UBO_INFORMATION"
	ENUMTYPERECOVEWAY_SIGN_ANTI_FRAUD_PLEDGE_AND_VERIFY_FACE         EnumTypeRecoveWay = "SIGN_ANTI_FRAUD_PLEDGE_AND_VERIFY_FACE"
	ENUMTYPERECOVEWAY_CONTACT_APPROPRIATE_AUTHORITY_FOR_CONSULTATION EnumTypeRecoveWay = "CONTACT_APPROPRIATE_AUTHORITY_FOR_CONSULTATION"
	ENUMTYPERECOVEWAY_MODIFY_ABBREVIATION_INFORMATION                EnumTypeRecoveWay = "MODIFY_ABBREVIATION_INFORMATION"
	ENUMTYPERECOVEWAY_CONFIRM_BUSINESS_TYPE                          EnumTypeRecoveWay = "CONFIRM_BUSINESS_TYPE"
	ENUMTYPERECOVEWAY_SUBMIT_ONLINE_BUSINESS_SCENARIO_INFORMATION    EnumTypeRecoveWay = "SUBMIT_ONLINE_BUSINESS_SCENARIO_INFORMATION"
)

type EnumTypeLimitActionType string

func (e EnumTypeLimitActionType) Ptr() *EnumTypeLimitActionType {
	return &e
}

const (
	ENUMTYPELIMITACTIONTYPE_LIMIT_ACTION_TYPE_IMMEDIATE_CONTROL EnumTypeLimitActionType = "LIMIT_ACTION_TYPE_IMMEDIATE_CONTROL"
	ENUMTYPELIMITACTIONTYPE_LIMIT_ACTION_TYPE_DELAY_CONTROL     EnumTypeLimitActionType = "LIMIT_ACTION_TYPE_DELAY_CONTROL"
)

```
