视频一区二区三区自拍_千金肉奴隷1985未删减版在线观看_国产成人黄色视频在线播放_少女免费播放片高清在线观看_国产精品v欧美精品v

使用 Go SDK 快速開始

更新時(shí)間:2023.08.17

在本教程中,你將簡要了解微信支付的 Go SDK。在學(xué)習(xí)過程中,你將

  • 掌握如何安裝 Go SDK
  • 了解請求微信支付需要哪些密鑰和證書
  • 了解如何使用 Go SDK 請求微信支付

# 環(huán)境要求

  • Go 1.16+

# 安裝

使用 Go Modules (opens new window) 安裝最新版本 SDK:

1go get github.com/wechatpay-apiv3/wechatpay-go

你可以在 GitHub 找到 Go SDK (opens new window) 的源代碼、使用說明和最新版本信息。

# 必需的證書和密鑰

運(yùn)行 SDK 必需以下的證書和密鑰:

# 發(fā)起請求

以 Native 支付為例,向微信支付發(fā)起你的第一個(gè)請求。

1package main
2
3import (
4 "context"
5 "log"
6
7 "github.com/wechatpay-apiv3/wechatpay-go/core"
8 "github.com/wechatpay-apiv3/wechatpay-go/core/option"
9 "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
10 "github.com/wechatpay-apiv3/wechatpay-go/utils"
11)
12
13func main() {
14 var (
15 mchID string = "190000****" // 商戶號(hào)
16 mchCertificateSerialNumber string = "3775B6A45ACD588826D15E583A95F5DD********" // 商戶證書序列號(hào)
17 mchAPIv3Key string = "2ab9****************************" // 商戶APIv3密鑰
18 )
19
20 // 使用 utils 提供的函數(shù)從本地文件中加載商戶私鑰,商戶私鑰會(huì)用來生成請求的簽名
21 mchPrivateKey, err: = utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
22 if err != nil {
23 log.Fatal("load merchant private key error")
24 }
25
26 ctx: = context.Background()
27 // 使用商戶私鑰等初始化 client,并使它具有自動(dòng)定時(shí)獲取微信支付平臺(tái)證書的能力
28 opts: = [] core.ClientOption {
29 option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
30 }
31 client, err: = core.NewClient(ctx, opts...)
32 if err != nil {
33 log.Fatalf("new wechat pay client err:%s", err)
34 }
35
36 // 以 Native 支付為例
37 svc := native.NativeApiService{Client: client}
38 // 發(fā)送請求
39 resp, result, err: = svc.Prepay(ctx,
40 native.PrepayRequest {
41 Appid: core.String("wxd678efh567hg6787"),
42 Mchid: core.String("1900009191"),
43 Description: core.String("Image形象店-深圳騰大-QQ公仔"),
44 OutTradeNo: core.String("1217752501201407033233368018"),
45 Attach: core.String("自定義數(shù)據(jù)說明"),
46 NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
47 Amount: & native.Amount {
48 Total: core.Int64(100),
49 },
50 },
51 )
52 // 使用微信掃描 resp.code_url 對(duì)應(yīng)的二維碼,即可體驗(yàn)Native支付
53 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
54}

# 聯(lián)系 SDK 團(tuán)隊(duì)獲取幫助

# 接下來閱讀

通過這個(gè)快速介紹,你已經(jīng)安裝了 Go SDK 并學(xué)習(xí)了一些基礎(chǔ)知識(shí)。接下來,你可以閱讀具體的產(chǎn)品文檔,學(xué)習(xí)如何接入微信支付。