123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package core_test
- import (
- "context"
- "crypto/rsa"
- "crypto/x509"
- "encoding/json"
- "log"
- "mime/multipart"
- "net/http"
- "git.nanodreamtech.com/sg/wechatpay-go/core"
- "git.nanodreamtech.com/sg/wechatpay-go/core/auth"
- "git.nanodreamtech.com/sg/wechatpay-go/core/cipher"
- "git.nanodreamtech.com/sg/wechatpay-go/core/consts"
- "git.nanodreamtech.com/sg/wechatpay-go/core/option"
- )
- func ExampleNewClient_default() {
-
- var (
- mchID string
- mchCertificateSerialNumber string
- mchPrivateKey *rsa.PrivateKey
- wechatPayCertificateList []*x509.Certificate
- customHTTPClient *http.Client
- )
- client, err := core.NewClient(
- context.Background(),
-
- option.WithWechatPayAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, wechatPayCertificateList),
-
- option.WithHTTPClient(customHTTPClient),
- )
- if err != nil {
- log.Printf("new wechat pay client err:%s", err.Error())
- return
- }
-
- _ = client
- }
- func ExampleNewClient_auto_update_certificate() {
-
- var (
- mchID string
- mchCertificateSerialNumber string
- mchPrivateKey *rsa.PrivateKey
- mchAPIv3Key string
- )
- client, err := core.NewClient(
- context.Background(),
-
- option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
- )
- if err != nil {
- log.Printf("new wechat pay client err:%s", err.Error())
- return
- }
-
- _ = client
- }
- func ExampleNewClient_fully_customized() {
- var (
- signer auth.Signer
- verifier auth.Verifier
- encryptor cipher.Encryptor
- decryptor cipher.Decryptor
- customHTTPClient *http.Client
- )
- client, err := core.NewClient(
- context.Background(),
-
- option.WithSigner(signer),
-
- option.WithVerifier(verifier),
-
- option.WithWechatPayCipher(encryptor, decryptor),
-
- option.WithHTTPClient(customHTTPClient),
- )
- if err != nil {
- log.Printf("new wechat pay client err:%s", err.Error())
- return
- }
-
- _ = client
- }
- func ExampleCreateFormField() {
- var w multipart.Writer
- meta := map[string]string{
- "filename": "sample.jpg",
- "sha256": "5944758444f0af3bc843e39b611a6b0c8c38cca44af653cd461b5765b71dc3f8",
- }
- metaBytes, err := json.Marshal(meta)
- if err != nil {
-
- return
- }
- err = core.CreateFormField(&w, "meta", consts.ApplicationJSON, metaBytes)
- if err != nil {
-
- }
- }
- func ExampleCreateFormFile() {
- var w multipart.Writer
- var fileContent []byte
- err := core.CreateFormFile(&w, "sample.jpg", consts.ImageJPG, fileContent)
- if err != nil {
-
- }
- }
|