---
url: "https://pay.weixin.qq.com/doc/v3/partner/4013892756-go.md"
title: "提交注销提现申请-请求示例-go"
doc_id: 4013892756
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 := &SubmitRequest{
		SubMchid:     wxpay_utility.String("1900000109"),
		OutRequestNo: wxpay_utility.String("P202410241010125346"),
		Withdraw:     APPLYWITHDRAW_APPLY_WITHDRAW.Ptr(),
		PayeeInfo: &PayeeInfo{
			AccountType: ACCOUNTTYPE_ACCOUNT_TYPE_CORPORATE.Ptr(),
			BankAccountInfo: &BankAccountInfo{
				AccountName:    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 加密结果*/
				AccountBank:    wxpay_utility.String("工商银行"),
				BankBranchId:   wxpay_utility.String("402713354941"),
				BankBranchName: wxpay_utility.String("施秉县农村信用合作联社城关信用社"),
				AccountNumber:  wxpay_utility.String("d+xT+MQCvrLHUVDWv/8MR/dB7TkXM2YYZlokmXzFsWs35NXUot7C0NcxIrUF5FnxqCJHkNgKtxa6RxEYyba1+VBRLnqKG2fSy/Y5qDN08Ej9zHCwJjq52Wg1VG8MRugli9YMI1fI83KGBxhuXyemgS/hqFKsfYGiOkJqjTUpgY5VqjtL2N4l4z11T0ECB/aSyVXUysOFGLVfSrUxMPZy6jWWYGvT1+4P633f+R+ki1gT4WF/2KxZOYmli385ZgVhcR30mr4/G3HBcxi13zp7FnEeOsLlvBmI1PHN4C7Rsu3WL8sPndjXTd75kPkyjqnoMRrEEaYQE8ZRGYoeorwC+w=="), /*请传入 wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/
			},
			IdentityInfo: &IdentityInfo{
				IdDocType:          IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_ID_CARD.Ptr(),
				IdentificationName: wxpay_utility.String("pVd1HJ6zyvPedzGaV+X3qtmrq9bb9tPROvwia4ibL+F6mfjbzQIzfb3HHLEjZ4YiR/cJiCrZxnAqi+pjeKIEdkwzXRAI7FUhrfPK3SNjaBTEu9GmsugMIA9r3x887Q+ODuC8HH2nzAn7NGpE/e3yiHgWhk0ps5k5DP/2qIdGdONoDzZelrxCl/NWWNUyB93K9F+jC1JX2IMttdY+aQ6zBlw0xnOiNW6Hzy7UtC+xriudjD5APomty7/mYNxLMpRSvWKIjOv/69bDnuC4EL5Kz4jBHLiCyOb+tI0m2qhZ9evAM+Jv1z0NVa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg=="), /*请传入 wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/
				IdentificationNo:   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 加密结果*/
			},
		},
		ProofMedias: []ProofMedia{ProofMedia{
			ProofMediaType: PROOFMEDIATYPE_WITHDRAWAL_APPLICATION.Ptr(),
			ProofMedia:     wxpay_utility.String("jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ"),
		}},
		AdditionalMaterials: []string{"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ"},
		Remark:              wxpay_utility.String("特殊理由"),
	}

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

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

func SubmitApply(config *wxpay_utility.MchConfig, request *SubmitRequest) (response *SubmitResponse, err error) {
	const (
		host   = "https://api.mch.weixin.qq.com"
		method = "POST"
		path   = "/v3/ecommerce/account/apply-cancel-withdraw"
	)

	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 := &SubmitResponse{}
		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 SubmitRequest struct {
	SubMchid            *string        `json:"sub_mchid,omitempty"`
	OutRequestNo        *string        `json:"out_request_no,omitempty"`
	Withdraw            *ApplyWithdraw `json:"withdraw,omitempty"`
	PayeeInfo           *PayeeInfo     `json:"payee_info,omitempty"`
	ProofMedias         []ProofMedia   `json:"proof_medias,omitempty"`
	AdditionalMaterials []string       `json:"additional_materials,omitempty"`
	Remark              *string        `json:"remark,omitempty"`
}

type SubmitResponse struct {
	ApplymentId  *string `json:"applyment_id,omitempty"`
	OutRequestNo *string `json:"out_request_no,omitempty"`
}

type ApplyWithdraw string

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

const (
	APPLYWITHDRAW_NOT_APPLY_WITHDRAW ApplyWithdraw = "NOT_APPLY_WITHDRAW"
	APPLYWITHDRAW_APPLY_WITHDRAW     ApplyWithdraw = "APPLY_WITHDRAW"
)

type PayeeInfo struct {
	AccountType     *AccountType     `json:"account_type,omitempty"`
	BankAccountInfo *BankAccountInfo `json:"bank_account_info,omitempty"`
	IdentityInfo    *IdentityInfo    `json:"identity_info,omitempty"`
}

type ProofMedia struct {
	ProofMediaType *ProofMediaType `json:"proof_media_type,omitempty"`
	ProofMedia     *string         `json:"proof_media,omitempty"`
}

type AccountType string

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

const (
	ACCOUNTTYPE_ACCOUNT_TYPE_CORPORATE AccountType = "ACCOUNT_TYPE_CORPORATE"
	ACCOUNTTYPE_ACCOUNT_TYPE_PERSONAL  AccountType = "ACCOUNT_TYPE_PERSONAL"
)

type BankAccountInfo struct {
	AccountName    *string `json:"account_name,omitempty"`
	AccountBank    *string `json:"account_bank,omitempty"`
	BankBranchId   *string `json:"bank_branch_id,omitempty"`
	BankBranchName *string `json:"bank_branch_name,omitempty"`
	AccountNumber  *string `json:"account_number,omitempty"`
}

type IdentityInfo struct {
	IdDocType          *IdentificationType `json:"id_doc_type,omitempty"`
	IdentificationName *string             `json:"identification_name,omitempty"`
	IdentificationNo   *string             `json:"identification_no,omitempty"`
}

type ProofMediaType string

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

const (
	PROOFMEDIATYPE_WITHDRAWAL_APPLICATION ProofMediaType = "WITHDRAWAL_APPLICATION"
)

type IdentificationType string

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

const (
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_ID_CARD                 IdentificationType = "IDENTIFICATION_TYPE_ID_CARD"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_OVERSEA_PASSPORT        IdentificationType = "IDENTIFICATION_TYPE_OVERSEA_PASSPORT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_HONGKONG_PASSPORT       IdentificationType = "IDENTIFICATION_TYPE_HONGKONG_PASSPORT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_MACAO_PASSPORT          IdentificationType = "IDENTIFICATION_TYPE_MACAO_PASSPORT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_TAIWAN_PASSPORT         IdentificationType = "IDENTIFICATION_TYPE_TAIWAN_PASSPORT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_FOREIGN_RESIDENT        IdentificationType = "IDENTIFICATION_TYPE_FOREIGN_RESIDENT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT IdentificationType = "IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT"
	IDENTIFICATIONTYPE_IDENTIFICATION_TYPE_TAIWAN_RESIDENT         IdentificationType = "IDENTIFICATION_TYPE_TAIWAN_RESIDENT"
)

```
