---
url: "https://pay.weixin.qq.com/doc/v3/partner/4016249989-go.md"
title: "提交入驻申请-请求示例-go"
doc_id: 4016249989
example_lang: "go"
---

## Go


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

```
package main

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

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 := &SubmitApplyRequest{
		BusinessCode: wxpay_utility.String("1900013511_10000"),
		AdminInfo: &AdminInfo{
			AdminName:    wxpay_utility.String("U2FsdGVkX1+3vZQv5+9JhTq3Xy6LdKjP0o9iYx5W7vRtNqY3sDfGhJkLmNbVcXz4Qw1UbP6oE8iC="), /*请传入wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/
			IdDocType:    IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_MAINLAND_ID_CARD.Ptr(),
			IdCardNumber: wxpay_utility.String("AOZdYGISxo4y44/UgZ69bdu9X+tfMUJ9dl+LetjM45/zMbrYu+wWZ8gn4CTdo+D/m9MrPg+V4sm73oxqdQu/hj7aWyDl4GQtPXVdaztB9jVbVZh3QFzV+BEmytMNQp9dt1uWJktlfdDdLR3AMWyMB377xd+m9bSr/ioDTzagEcGe+vLYiKrzcroQv3OR0p3ppFYoQ3IfYeU/04S4t9rNFL+kyblK2FCCqQ11NdbbHoCrJc7NV4oASq6ZFonjTtgjjgKsadIKHXtb3JZKGZjduGdtkRJJp0/0eow96uY1Pk7Rq79Jtt7+I8juwEc4P4TG5xzchG/5IL9DBd+Z0zZXkw=="), /*请传入wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/
		},
		SubjectInfo: &SubjectInfo{
			SubjectType:             SUBJECTTYPE_SUBJECT_TYPE_ENTERPRISE.Ptr(),
			SubjectName:             wxpay_utility.String("xx有限公司"),
			UnifiedSocialCreditCode: wxpay_utility.String("91310101MA1FPX1234"),
		},
		BrandBasicInfo: &BrandBasicInfo{
			BrandName: wxpay_utility.String("爱马哥"),
			BrandLogo: wxpay_utility.String("U2FsdGVkX1+8n2qLk9jP4vRtY6Wx1Zc3DqF7sH0mNpBvY2Tq5X9gLkE4wRz1oU6IcJ8mVfA0sBd="),
		},
		Trademark: &Trademark{
			TrademarkExists: TRADEMARKSTATE_TRADEMARK_EXISTS.Ptr(),
			TrademarkRegistrationCertificate: &TrademarkRegCert{
				Certificate:            wxpay_utility.String("jTpGmxUX3FBWVQ5NJTZvvDujqhThn4ReFxikqJ5YW6zFQ"),
				Name:                   wxpay_utility.String("爱马哥"),
				Number:                 wxpay_utility.String("12345678"),
				ValidBeginTime:         wxpay_utility.String("2025-09-08"),
				ValidEndTime:           wxpay_utility.String("2035-09-08"),
				InternationalClass:     wxpay_utility.String("25"),
				Holder:                 wxpay_utility.String("腾讯科技有限公司"),
				License:                wxpay_utility.String("jTpGmxUXqRTvDujqhThn4ReFxikqJ5YW6zFQ"),
				AuthorizationBeginTime: wxpay_utility.String("2025-09-08"),
				AuthorizationEndTime:   wxpay_utility.String("2035-09-08"),
				CertificateList:        []string{"example_CertificateList"},
				LicenseList:            []string{"example_LicenseList"},
			},
			LogoTrademarkRegistrationCertificate: &LogoTrademarkRegCert{
				Certificate:            wxpay_utility.String("jTpGmxUXqRTvDujqhThn4ReFxikqJ5YW6zFQ"),
				Name:                   wxpay_utility.String("爱马哥"),
				Number:                 wxpay_utility.String("21312344"),
				ValidBeginTime:         wxpay_utility.String("2025-09-08"),
				ValidEndTime:           wxpay_utility.String("2035-09-08"),
				InternationalClass:     wxpay_utility.String("25"),
				Holder:                 wxpay_utility.String("腾讯科技有限公司"),
				License:                wxpay_utility.String("jTpGmxUXqRTvDujqhThn4ReFxikqJ5YW6zFQ"),
				AuthorizationBeginTime: wxpay_utility.String("2025-09-08"),
				AuthorizationEndTime:   wxpay_utility.String("2035-09-08"),
				CertificateList:        []string{"example_CertificateList"},
				LicenseList:            []string{"example_LicenseList"},
			},
			NoTrademarkAdditionProve:     wxpay_utility.String("jTpGmxUX3FBWVQ5NJTZvvDujqhThn4ReFxikqJ5YW6zFQ"),
			NoTrademarkAdditionProveList: []string{"example_NoTrademarkAdditionProveList"},
		},
	}

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

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

func SubmitApplyment(config *wxpay_utility.MchConfig, request *SubmitApplyRequest) (response *SubmitApplyResponse, err error) {
	const (
		host   = "https://api.mch.weixin.qq.com"
		method = "POST"
		path   = "/v3/brand/applyments"
	)

	reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
	if err != nil {
		return nil, err
	}
	reqBody, err := json.Marshal(request)
	if err != nil {
		return nil, err
	}
	httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody))
	if err != nil {
		return nil, err
	}
	httpRequest.Header.Set("Accept", "application/json")
	httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
	httpRequest.Header.Set("Content-Type", "application/json")
	authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody)
	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 := &SubmitApplyResponse{}
		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 SubmitApplyRequest struct {
	BusinessCode   *string         `json:"business_code,omitempty"`
	AdminInfo      *AdminInfo      `json:"admin_info,omitempty"`
	SubjectInfo    *SubjectInfo    `json:"subject_info,omitempty"`
	BrandBasicInfo *BrandBasicInfo `json:"brand_basic_info,omitempty"`
	Trademark      *Trademark      `json:"trademark,omitempty"`
}

type SubmitApplyResponse struct {
	ApplymentId  *string `json:"applyment_id,omitempty"`
	BusinessCode *string `json:"business_code,omitempty"`
}

type AdminInfo struct {
	AdminName    *string             `json:"admin_name,omitempty"`
	IdDocType    *IdentificationType `json:"id_doc_type,omitempty"`
	IdCardNumber *string             `json:"id_card_number,omitempty"`
}

type SubjectInfo struct {
	SubjectType             *SubjectType `json:"subject_type,omitempty"`
	SubjectName             *string      `json:"subject_name,omitempty"`
	UnifiedSocialCreditCode *string      `json:"unified_social_credit_code,omitempty"`
}

type BrandBasicInfo struct {
	BrandName *string `json:"brand_name,omitempty"`
	BrandLogo *string `json:"brand_logo,omitempty"`
}

type Trademark struct {
	TrademarkExists                      *TrademarkState       `json:"trademark_exists,omitempty"`
	TrademarkRegistrationCertificate     *TrademarkRegCert     `json:"trademark_registration_certificate,omitempty"`
	LogoTrademarkRegistrationCertificate *LogoTrademarkRegCert `json:"logo_trademark_registration_certificate,omitempty"`
	NoTrademarkAdditionProve             *string               `json:"no_trademark_addition_prove,omitempty"`
	NoTrademarkAdditionProveList         []string              `json:"no_trademark_addition_prove_list,omitempty"`
}

type IdentificationType string

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

const (
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_MAINLAND_ID_CARD        IdentificationType = "IDENTIFICATION_TYPE_MAINLAND_ID_CARD"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_HONGKONG                IdentificationType = "IDENTIFICATION_TYPE_HONGKONG"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_MACAO                   IdentificationType = "IDENTIFICATION_TYPE_MACAO"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_TAIWAN                  IdentificationType = "IDENTIFICATION_TYPE_TAIWAN"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT IdentificationType = "IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_TAIWAN_RESIDENT         IdentificationType = "IDENTIFICATION_TYPE_TAIWAN_RESIDENT"
)

type SubjectType string

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

const (
	SUBJECTTYPE_SUBJECT_TYPE_ENTERPRISE SubjectType = "SUBJECT_TYPE_ENTERPRISE"
	SUBJECTTYPE_SUBJECT_TYPE_INDIVIDUAL SubjectType = "SUBJECT_TYPE_INDIVIDUAL"
)

type TrademarkState string

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

const (
	TRADEMARKSTATE_TRADEMARK_EXISTS TrademarkState = "TRADEMARK_EXISTS"
	TRADEMARKSTATE_TRADEMARK_NONE   TrademarkState = "TRADEMARK_NONE"
)

type TrademarkRegCert struct {
	Certificate            *string  `json:"certificate,omitempty"`
	Name                   *string  `json:"name,omitempty"`
	Number                 *string  `json:"number,omitempty"`
	ValidBeginTime         *string  `json:"valid_begin_time,omitempty"`
	ValidEndTime           *string  `json:"valid_end_time,omitempty"`
	InternationalClass     *string  `json:"international_class,omitempty"`
	Holder                 *string  `json:"holder,omitempty"`
	License                *string  `json:"license,omitempty"`
	AuthorizationBeginTime *string  `json:"authorization_begin_time,omitempty"`
	AuthorizationEndTime   *string  `json:"authorization_end_time,omitempty"`
	CertificateList        []string `json:"certificate_list,omitempty"`
	LicenseList            []string `json:"license_list,omitempty"`
}

type LogoTrademarkRegCert struct {
	Certificate            *string  `json:"certificate,omitempty"`
	Name                   *string  `json:"name,omitempty"`
	Number                 *string  `json:"number,omitempty"`
	ValidBeginTime         *string  `json:"valid_begin_time,omitempty"`
	ValidEndTime           *string  `json:"valid_end_time,omitempty"`
	InternationalClass     *string  `json:"international_class,omitempty"`
	Holder                 *string  `json:"holder,omitempty"`
	License                *string  `json:"license,omitempty"`
	AuthorizationBeginTime *string  `json:"authorization_begin_time,omitempty"`
	AuthorizationEndTime   *string  `json:"authorization_end_time,omitempty"`
	CertificateList        []string `json:"certificate_list,omitempty"`
	LicenseList            []string `json:"license_list,omitempty"`
}

```
