1package main
2import (
3 "context"
4 "log"
5 "github.com/wechatpay-apiv3/wechatpay-go/core"
6 "github.com/wechatpay-apiv3/wechatpay-go/core/option"
7 "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
8 "github.com/wechatpay-apiv3/wechatpay-go/utils"
9)
10func main() {
11 var (
12 mchID string = "190000****"
13 mchCertificateSerialNumber string = "3775B6A45ACD588826D15E583A95F5DD********"
14 mchAPIv3Key string = "2ab9****************************"
15 )
16
17 mchPrivateKey, err: = utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
18 if err != nil {
19 log.Fatal("load merchant private key error")
20 }
21 ctx: = context.Background()
22
23 opts: = [] core.ClientOption {
24 option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
25 }
26 client, err: = core.NewClient(ctx, opts...)
27 if err != nil {
28 log.Fatalf("new wechat pay client err:%s", err)
29 }
30
31 svc := native.NativeApiService{Client: client}
32
33 resp, result, err: = svc.Prepay(ctx,
34 native.PrepayRequest {
35 Appid: core.String("wxd678efh567hg6787"),
36 Mchid: core.String("1900009191"),
37 Description: core.String("Image形象店-深圳腾大-QQ公仔"),
38 OutTradeNo: core.String("1217752501201407033233368018"),
39 Attach: core.String("自定义数据说明"),
40 NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
41 Amount: & native.Amount {
42 Total: core.Int64(100),
43 },
44 },
45 )
46
47 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
48}