---
url: "https://pay.weixin.qq.com/doc/v3/partner/4012492967-go.md"
title: "获取活动详情接口-请求示例-go"
doc_id: 4012492967
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 := &GetActDetailRequest{
		ActivityId: wxpay_utility.String("10028001"),
	}

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

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

func GetActDetail(config *wxpay_utility.MchConfig, request *GetActDetailRequest) (response *GetActDetailResponse, err error) {
	const (
		host   = "https://api.mch.weixin.qq.com"
		method = "GET"
		path   = "/v3/marketing/paygiftactivity/activities/{activity_id}"
	)

	reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
	if err != nil {
		return nil, err
	}
	reqUrl.Path = strings.Replace(reqUrl.Path, "{activity_id}", url.PathEscape(*request.ActivityId), -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 := &GetActDetailResponse{}
		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 GetActDetailRequest struct {
	ActivityId *string `json:"activity_id,omitempty"`
}

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

type GetActDetailResponse struct {
	ActivityId        *string             `json:"activity_id,omitempty"`
	ActivityType      *ActType            `json:"activity_type,omitempty"`
	ActivityBaseInfo  *ActBaseInfo        `json:"activity_base_info,omitempty"`
	AwardSendRule     *AwardSendRule      `json:"award_send_rule,omitempty"`
	AdvancedSetting   *ActAdvancedSetting `json:"advanced_setting,omitempty"`
	ActivityStatus    *ActStatus          `json:"activity_status,omitempty"`
	CreatorMerchantId *string             `json:"creator_merchant_id,omitempty"`
	BelongMerchantId  *string             `json:"belong_merchant_id,omitempty"`
	PauseTime         *string             `json:"pause_time,omitempty"`
	RecoveryTime      *string             `json:"recovery_time,omitempty"`
	CreateTime        *string             `json:"create_time,omitempty"`
	UpdateTime        *string             `json:"update_time,omitempty"`
}

type ActType string

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

const (
	ACTTYPE_FULL_SEND_ACT_TYPE     ActType = "FULL_SEND_ACT_TYPE"
	ACTTYPE_STEP_SEND_ACT_TYPE     ActType = "STEP_SEND_ACT_TYPE"
	ACTTYPE_SPECIFIC_SEND_ACT_TYPE ActType = "SPECIFIC_SEND_ACT_TYPE"
)

type ActBaseInfo struct {
	ActivityName        *string                  `json:"activity_name,omitempty"`
	ActivitySecondTitle *string                  `json:"activity_second_title,omitempty"`
	MerchantLogoUrl     *string                  `json:"merchant_logo_url,omitempty"`
	BackgroundColor     *string                  `json:"background_color,omitempty"`
	BeginTime           *string                  `json:"begin_time,omitempty"`
	EndTime             *string                  `json:"end_time,omitempty"`
	AvailablePeriods    *AvailablePeriod         `json:"available_periods,omitempty"`
	OutRequestNo        *string                  `json:"out_request_no,omitempty"`
	DeliveryPurpose     *DeliveryPurposeCategory `json:"delivery_purpose,omitempty"`
	MiniProgramsAppid   *string                  `json:"mini_programs_appid,omitempty"`
	MiniProgramsPath    *string                  `json:"mini_programs_path,omitempty"`
}

type AwardSendRule struct {
	FullSendRule *FullSendRule `json:"full_send_rule,omitempty"`
}

type ActAdvancedSetting struct {
	DeliveryUserCategory     *DeliveryUserCategory `json:"delivery_user_category,omitempty"`
	MerchantMemberAppid      *string               `json:"merchant_member_appid,omitempty"`
	PaymentMode              *PaymentMode          `json:"payment_mode,omitempty"`
	PaymentMethodInformation *PaymentMethodInfo    `json:"payment_method_information,omitempty"`
	GoodsTags                []string              `json:"goods_tags,omitempty"`
}

type ActStatus string

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

const (
	ACTSTATUS_ACT_STATUS_UNKNOWN   ActStatus = "ACT_STATUS_UNKNOWN"
	ACTSTATUS_CREATE_ACT_STATUS    ActStatus = "CREATE_ACT_STATUS"
	ACTSTATUS_ONGOING_ACT_STATUS   ActStatus = "ONGOING_ACT_STATUS"
	ACTSTATUS_TERMINATE_ACT_STATUS ActStatus = "TERMINATE_ACT_STATUS"
	ACTSTATUS_STOP_ACT_STATUS      ActStatus = "STOP_ACT_STATUS"
	ACTSTATUS_OVER_TIME_ACT_STATUS ActStatus = "OVER_TIME_ACT_STATUS"
	ACTSTATUS_CREATE_ACT_FAILED    ActStatus = "CREATE_ACT_FAILED"
)

type AvailablePeriod struct {
	AvailableTime    []AvailableTime    `json:"available_time,omitempty"`
	AvailableDayTime []AvailableDayTime `json:"available_day_time,omitempty"`
}

type DeliveryPurposeCategory string

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

const (
	DELIVERYPURPOSECATEGORY_OFF_LINE_PAY  DeliveryPurposeCategory = "OFF_LINE_PAY"
	DELIVERYPURPOSECATEGORY_JUMP_MINI_APP DeliveryPurposeCategory = "JUMP_MINI_APP"
)

type FullSendRule struct {
	TransactionAmountMinimum *int64               `json:"transaction_amount_minimum,omitempty"`
	SendContent              *SendContentCategory `json:"send_content,omitempty"`
	AwardType                *AwardType           `json:"award_type,omitempty"`
	AwardList                []AwardBaseInfo      `json:"award_list,omitempty"`
	MerchantOption           *SendMerchantOption  `json:"merchant_option,omitempty"`
	MerchantIdList           []string             `json:"merchant_id_list,omitempty"`
}

type DeliveryUserCategory string

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

const (
	DELIVERYUSERCATEGORY_DELIVERY_ALL_PERSON    DeliveryUserCategory = "DELIVERY_ALL_PERSON"
	DELIVERYUSERCATEGORY_DELIVERY_MEMBER_PERSON DeliveryUserCategory = "DELIVERY_MEMBER_PERSON"
)

type PaymentMode struct {
	PaymentSceneList []PaymentScene `json:"payment_scene_list,omitempty"`
}

type PaymentMethodInfo struct {
	PaymentMethod    *PaymentMethodCategory `json:"payment_method,omitempty"`
	BankAbbreviation *string                `json:"bank_abbreviation,omitempty"`
}

type AvailableTime struct {
	BeginTime *string `json:"begin_time,omitempty"`
	EndTime   *string `json:"end_time,omitempty"`
}

type AvailableDayTime struct {
	BeginDayTime *string `json:"begin_day_time,omitempty"`
	EndDayTime   *string `json:"end_day_time,omitempty"`
}

type SendContentCategory string

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

const (
	SENDCONTENTCATEGORY_SINGLE_COUPON SendContentCategory = "SINGLE_COUPON"
	SENDCONTENTCATEGORY_GIFT_PACKAGE  SendContentCategory = "GIFT_PACKAGE"
)

type AwardType string

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

const (
	AWARDTYPE_BUSIFAVOR AwardType = "BUSIFAVOR"
)

type AwardBaseInfo struct {
	StockId          *string `json:"stock_id,omitempty"`
	OriginalImageUrl *string `json:"original_image_url,omitempty"`
	ThumbnailUrl     *string `json:"thumbnail_url,omitempty"`
}

type SendMerchantOption string

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

const (
	SENDMERCHANTOPTION_IN_SEVICE_COUPON_MERCHANT SendMerchantOption = "IN_SEVICE_COUPON_MERCHANT"
	SENDMERCHANTOPTION_MANUAL_INPUT_MERCHANT     SendMerchantOption = "MANUAL_INPUT_MERCHANT"
)

type PaymentScene string

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

const (
	PAYMENTSCENE_APP_SCENE        PaymentScene = "APP_SCENE"
	PAYMENTSCENE_SWING_CARD_SCENE PaymentScene = "SWING_CARD_SCENE"
	PAYMENTSCENE_NO_SECRET_SCENE  PaymentScene = "NO_SECRET_SCENE"
	PAYMENTSCENE_MINIAPP_SCENE    PaymentScene = "MINIAPP_SCENE"
	PAYMENTSCENE_FACE_PAY_SCENE   PaymentScene = "FACE_PAY_SCENE"
	PAYMENTSCENE_OTHER_SCENE      PaymentScene = "OTHER_SCENE"
)

type PaymentMethodCategory string

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

const (
	PAYMENTMETHODCATEGORY_CFT                PaymentMethodCategory = "CFT"
	PAYMENTMETHODCATEGORY_SPECIFIC_BANK_CARD PaymentMethodCategory = "SPECIFIC_BANK_CARD"
)

```
