
1package main
2
3import (
4 "demo/wxpay_utility"
5 "encoding/json"
6 "fmt"
7 "net/http"
8 "net/url"
9 "strings"
10)
11
12func main() {
13
14 config, err := wxpay_utility.CreateMchConfig(
15 "19xxxxxxxx",
16 "1DDE55AD98Exxxxxxxxxx",
17 "/path/to/apiclient_key.pem",
18 "PUB_KEY_ID_xxxxxxxxxxxxx",
19 "/path/to/wxp_pub.pem",
20 )
21 if err != nil {
22 fmt.Println(err)
23 return
24 }
25
26 request := &GetActDetailRequest{
27 ActivityId: wxpay_utility.String("10028001"),
28 }
29
30 response, err := GetActDetail(config, request)
31 if err != nil {
32 fmt.Printf("请求失败: %+v\n", err)
33
34 return
35 }
36
37
38 fmt.Printf("请求成功: %+v\n", response)
39}
40
41func GetActDetail(config *wxpay_utility.MchConfig, request *GetActDetailRequest) (response *GetActDetailResponse, err error) {
42 const (
43 host = "https://api.mch.weixin.qq.com"
44 method = "GET"
45 path = "/v3/marketing/paygiftactivity/activities/{activity_id}"
46 )
47
48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path))
49 if err != nil {
50 return nil, err
51 }
52 reqUrl.Path = strings.Replace(reqUrl.Path, "{activity_id}", url.PathEscape(*request.ActivityId), -1)
53 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil)
54 if err != nil {
55 return nil, err
56 }
57 httpRequest.Header.Set("Accept", "application/json")
58 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId())
59 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil)
60 if err != nil {
61 return nil, err
62 }
63 httpRequest.Header.Set("Authorization", authorization)
64
65 client := &http.Client{}
66 httpResponse, err := client.Do(httpRequest)
67 if err != nil {
68 return nil, err
69 }
70 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse)
71 if err != nil {
72 return nil, err
73 }
74 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 {
75
76 err = wxpay_utility.ValidateResponse(
77 config.WechatPayPublicKeyId(),
78 config.WechatPayPublicKey(),
79 &httpResponse.Header,
80 respBody,
81 )
82 if err != nil {
83 return nil, err
84 }
85 response := &GetActDetailResponse{}
86 if err := json.Unmarshal(respBody, response); err != nil {
87 return nil, err
88 }
89
90 return response, nil
91 } else {
92 return nil, wxpay_utility.NewApiException(
93 httpResponse.StatusCode,
94 httpResponse.Header,
95 respBody,
96 )
97 }
98}
99
100type GetActDetailRequest struct {
101 ActivityId *string `json:"activity_id,omitempty"`
102}
103
104func (o *GetActDetailRequest) MarshalJSON() ([]byte, error) {
105 type Alias GetActDetailRequest
106 a := &struct {
107 ActivityId *string `json:"activity_id,omitempty"`
108 *Alias
109 }{
110
111 ActivityId: nil,
112 Alias: (*Alias)(o),
113 }
114 return json.Marshal(a)
115}
116
117type GetActDetailResponse struct {
118 ActivityId *string `json:"activity_id,omitempty"`
119 ActivityType *ActType `json:"activity_type,omitempty"`
120 ActivityBaseInfo *ActBaseInfo `json:"activity_base_info,omitempty"`
121 AwardSendRule *AwardSendRule `json:"award_send_rule,omitempty"`
122 AdvancedSetting *ActAdvancedSetting `json:"advanced_setting,omitempty"`
123 ActivityStatus *ActStatus `json:"activity_status,omitempty"`
124 CreatorMerchantId *string `json:"creator_merchant_id,omitempty"`
125 BelongMerchantId *string `json:"belong_merchant_id,omitempty"`
126 PauseTime *string `json:"pause_time,omitempty"`
127 RecoveryTime *string `json:"recovery_time,omitempty"`
128 CreateTime *string `json:"create_time,omitempty"`
129 UpdateTime *string `json:"update_time,omitempty"`
130}
131
132type ActType string
133
134func (e ActType) Ptr() *ActType {
135 return &e
136}
137
138const (
139 ACTTYPE_FULL_SEND_ACT_TYPE ActType = "FULL_SEND_ACT_TYPE"
140 ACTTYPE_STEP_SEND_ACT_TYPE ActType = "STEP_SEND_ACT_TYPE"
141 ACTTYPE_SPECIFIC_SEND_ACT_TYPE ActType = "SPECIFIC_SEND_ACT_TYPE"
142)
143
144type ActBaseInfo struct {
145 ActivityName *string `json:"activity_name,omitempty"`
146 ActivitySecondTitle *string `json:"activity_second_title,omitempty"`
147 MerchantLogoUrl *string `json:"merchant_logo_url,omitempty"`
148 BackgroundColor *string `json:"background_color,omitempty"`
149 BeginTime *string `json:"begin_time,omitempty"`
150 EndTime *string `json:"end_time,omitempty"`
151 AvailablePeriods *AvailablePeriod `json:"available_periods,omitempty"`
152 OutRequestNo *string `json:"out_request_no,omitempty"`
153 DeliveryPurpose *DeliveryPurposeCategory `json:"delivery_purpose,omitempty"`
154 MiniProgramsAppid *string `json:"mini_programs_appid,omitempty"`
155 MiniProgramsPath *string `json:"mini_programs_path,omitempty"`
156}
157
158type AwardSendRule struct {
159 FullSendRule *FullSendRule `json:"full_send_rule,omitempty"`
160}
161
162type ActAdvancedSetting struct {
163 DeliveryUserCategory *DeliveryUserCategory `json:"delivery_user_category,omitempty"`
164 MerchantMemberAppid *string `json:"merchant_member_appid,omitempty"`
165 PaymentMode *PaymentMode `json:"payment_mode,omitempty"`
166 PaymentMethodInformation *PaymentMethodInfo `json:"payment_method_information,omitempty"`
167 GoodsTags []string `json:"goods_tags,omitempty"`
168}
169
170type ActStatus string
171
172func (e ActStatus) Ptr() *ActStatus {
173 return &e
174}
175
176const (
177 ACTSTATUS_ACT_STATUS_UNKNOWN ActStatus = "ACT_STATUS_UNKNOWN"
178 ACTSTATUS_CREATE_ACT_STATUS ActStatus = "CREATE_ACT_STATUS"
179 ACTSTATUS_ONGOING_ACT_STATUS ActStatus = "ONGOING_ACT_STATUS"
180 ACTSTATUS_TERMINATE_ACT_STATUS ActStatus = "TERMINATE_ACT_STATUS"
181 ACTSTATUS_STOP_ACT_STATUS ActStatus = "STOP_ACT_STATUS"
182 ACTSTATUS_OVER_TIME_ACT_STATUS ActStatus = "OVER_TIME_ACT_STATUS"
183 ACTSTATUS_CREATE_ACT_FAILED ActStatus = "CREATE_ACT_FAILED"
184)
185
186type AvailablePeriod struct {
187 AvailableTime []AvailableTime `json:"available_time,omitempty"`
188 AvailableDayTime []AvailableDayTime `json:"available_day_time,omitempty"`
189}
190
191type DeliveryPurposeCategory string
192
193func (e DeliveryPurposeCategory) Ptr() *DeliveryPurposeCategory {
194 return &e
195}
196
197const (
198 DELIVERYPURPOSECATEGORY_OFF_LINE_PAY DeliveryPurposeCategory = "OFF_LINE_PAY"
199 DELIVERYPURPOSECATEGORY_JUMP_MINI_APP DeliveryPurposeCategory = "JUMP_MINI_APP"
200)
201
202type FullSendRule struct {
203 TransactionAmountMinimum *int64 `json:"transaction_amount_minimum,omitempty"`
204 SendContent *SendContentCategory `json:"send_content,omitempty"`
205 AwardType *AwardType `json:"award_type,omitempty"`
206 AwardList []AwardBaseInfo `json:"award_list,omitempty"`
207 MerchantOption *SendMerchantOption `json:"merchant_option,omitempty"`
208 MerchantIdList []string `json:"merchant_id_list,omitempty"`
209}
210
211type DeliveryUserCategory string
212
213func (e DeliveryUserCategory) Ptr() *DeliveryUserCategory {
214 return &e
215}
216
217const (
218 DELIVERYUSERCATEGORY_DELIVERY_ALL_PERSON DeliveryUserCategory = "DELIVERY_ALL_PERSON"
219 DELIVERYUSERCATEGORY_DELIVERY_MEMBER_PERSON DeliveryUserCategory = "DELIVERY_MEMBER_PERSON"
220)
221
222type PaymentMode struct {
223 PaymentSceneList []PaymentScene `json:"payment_scene_list,omitempty"`
224}
225
226type PaymentMethodInfo struct {
227 PaymentMethod *PaymentMethodCategory `json:"payment_method,omitempty"`
228 BankAbbreviation *string `json:"bank_abbreviation,omitempty"`
229}
230
231type AvailableTime struct {
232 BeginTime *string `json:"begin_time,omitempty"`
233 EndTime *string `json:"end_time,omitempty"`
234}
235
236type AvailableDayTime struct {
237 BeginDayTime *string `json:"begin_day_time,omitempty"`
238 EndDayTime *string `json:"end_day_time,omitempty"`
239}
240
241type SendContentCategory string
242
243func (e SendContentCategory) Ptr() *SendContentCategory {
244 return &e
245}
246
247const (
248 SENDCONTENTCATEGORY_SINGLE_COUPON SendContentCategory = "SINGLE_COUPON"
249 SENDCONTENTCATEGORY_GIFT_PACKAGE SendContentCategory = "GIFT_PACKAGE"
250)
251
252type AwardType string
253
254func (e AwardType) Ptr() *AwardType {
255 return &e
256}
257
258const (
259 AWARDTYPE_BUSIFAVOR AwardType = "BUSIFAVOR"
260)
261
262type AwardBaseInfo struct {
263 StockId *string `json:"stock_id,omitempty"`
264 OriginalImageUrl *string `json:"original_image_url,omitempty"`
265 ThumbnailUrl *string `json:"thumbnail_url,omitempty"`
266}
267
268type SendMerchantOption string
269
270func (e SendMerchantOption) Ptr() *SendMerchantOption {
271 return &e
272}
273
274const (
275 SENDMERCHANTOPTION_IN_SEVICE_COUPON_MERCHANT SendMerchantOption = "IN_SEVICE_COUPON_MERCHANT"
276 SENDMERCHANTOPTION_MANUAL_INPUT_MERCHANT SendMerchantOption = "MANUAL_INPUT_MERCHANT"
277)
278
279type PaymentScene string
280
281func (e PaymentScene) Ptr() *PaymentScene {
282 return &e
283}
284
285const (
286 PAYMENTSCENE_APP_SCENE PaymentScene = "APP_SCENE"
287 PAYMENTSCENE_SWING_CARD_SCENE PaymentScene = "SWING_CARD_SCENE"
288 PAYMENTSCENE_NO_SECRET_SCENE PaymentScene = "NO_SECRET_SCENE"
289 PAYMENTSCENE_MINIAPP_SCENE PaymentScene = "MINIAPP_SCENE"
290 PAYMENTSCENE_FACE_PAY_SCENE PaymentScene = "FACE_PAY_SCENE"
291 PAYMENTSCENE_OTHER_SCENE PaymentScene = "OTHER_SCENE"
292)
293
294type PaymentMethodCategory string
295
296func (e PaymentMethodCategory) Ptr() *PaymentMethodCategory {
297 return &e
298}
299
300const (
301 PAYMENTMETHODCATEGORY_CFT PaymentMethodCategory = "CFT"
302 PAYMENTMETHODCATEGORY_SPECIFIC_BANK_CARD PaymentMethodCategory = "SPECIFIC_BANK_CARD"
303)
304