certificates

package
v0.0.0-...-b47993a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Certificate

type Certificate struct {
	// 证书序列号
	SerialNo *string `json:"serial_no"`
	// 证书有效期开始时间
	EffectiveTime *time.Time `json:"effective_time"`
	// 证书过期时间
	ExpireTime *time.Time `json:"expire_time"`
	// 为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密
	EncryptCertificate *EncryptCertificate `json:"encrypt_certificate"`
}

Certificate 微信支付平台证书信息

func (Certificate) Clone

func (o Certificate) Clone() *Certificate

func (Certificate) MarshalJSON

func (o Certificate) MarshalJSON() ([]byte, error)

func (Certificate) String

func (o Certificate) String() string

type CertificatesApiService

type CertificatesApiService services.Service

func (*CertificatesApiService) DownloadCertificates

func (a *CertificatesApiService) DownloadCertificates(ctx context.Context) (resp *DownloadCertificatesResponse, result *core.APIResult, err error)

DownloadCertificates 获取平台证书列表

获取商户当前可用的平台证书列表。微信支付提供该接口,帮助商户后台系统实现平台证书的平滑更换。

Example
package main

import (
	"context"
	"log"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/option"
	"github.com/wechatpay-apiv3/wechatpay-go/services/certificates"
	"github.com/wechatpay-apiv3/wechatpay-go/utils"
)

func main() {
	var (
		mchID                      string = "190000****"                               // 商户号
		mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
		mchAPIv3Key                string = "2ab9****************************"         // 商户APIv3密钥
	)

	// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
	mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
	if err != nil {
		log.Print("load merchant private key error")
	}

	ctx := context.Background()
	// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
	opts := []core.ClientOption{
		option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
	}
	client, err := core.NewClient(ctx, opts...)
	if err != nil {
		log.Printf("new wechat pay client err:%s", err)
	}

	svc := certificates.CertificatesApiService{Client: client}
	resp, result, err := svc.DownloadCertificates(ctx)

	if err != nil {
		// 处理错误
		log.Printf("call DownloadCertificates err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}
Output:

type DownloadCertificatesResponse

type DownloadCertificatesResponse struct {
	// 平台证书列表
	Data []Certificate `json:"data,omitempty"`
}

DownloadCertificatesResponse

func (DownloadCertificatesResponse) Clone

func (DownloadCertificatesResponse) MarshalJSON

func (o DownloadCertificatesResponse) MarshalJSON() ([]byte, error)

func (DownloadCertificatesResponse) String

type EncryptCertificate

type EncryptCertificate struct {
	// 加密所使用的算法,目前可能取值仅为 AEAD_AES_256_GCM
	Algorithm *string `json:"algorithm"`
	// 加密所使用的随机字符串
	Nonce *string `json:"nonce"`
	// 附加数据包(可能为空)
	AssociatedData *string `json:"associated_data"`
	// 证书内容密文,解密后会获得证书完整内容
	Ciphertext *string `json:"ciphertext"`
}

EncryptCertificate 为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密

func (EncryptCertificate) Clone

func (EncryptCertificate) MarshalJSON

func (o EncryptCertificate) MarshalJSON() ([]byte, error)

func (EncryptCertificate) String

func (o EncryptCertificate) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL