wechat

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

README

wechat

微信 Go SDK

除支付(v2)外,JSON结果均以 gjson.Result 返回,理论上支持所有 JSON API

👉 支持
  • 支付
  • 公众号
  • 小程序
  • 企业微信

注意:

  1. 支付(v3),记得自动加载平台证书 !!!
  2. 小程序,记得自动加载AccessToken !!!
  3. 公众号,记得自动加载AccessToken !!!

Documentation

Index

Constants

View Source
const (
	HeaderRequestID             = "Request-ID"
	HeaderPayNonce              = "Wechatpay-Nonce"
	HeaderPayTimestamp          = "Wechatpay-Timestamp"
	HeaderPaySerial             = "Wechatpay-Serial"
	HeaderPaySignature          = "Wechatpay-Signature"
	HeaderMPAppID               = "Wechatmp-Appid"
	HeaderMPTimestamp           = "Wechatmp-TimeStamp"
	HeaderMPSerial              = "Wechatmp-Serial"
	HeaderMPSignature           = "Wechatmp-Signature"
	HeaderMPSerialDeprecated    = "Wechatmp-Serial-Deprecated"
	HeaderMPSignatureDeprecated = "Wechatmp-Signature-Deprecated"
)
View Source
const (
	ResultSuccess = "SUCCESS"
	ResultFail    = "FAIL"
	ResultNull    = "RESULT NULL" // 查询结果为空
)

支付v2返回结果

View Source
const (
	SystemError        = "SYSTEMERROR"           // 系统繁忙,请稍后再试
	ParamError         = "PARAM_ERROR"           // 参数错误
	SignError          = "SIGNERROR"             // 签名错误
	LackParams         = "LACK_PARAMS"           // 缺少参数
	NotUTF8            = "NOT_UTF8"              // 编码格式错误
	NoAuth             = "NOAUTH"                // 商户无权限
	NotFound           = "NOT_FOUND"             // 数据不存在
	NotEnough          = "NOTENOUGH"             // 余额不足
	NotSupportCard     = "NOTSUPORTCARD"         // 不支持的卡类型
	UserPaying         = "USERPAYING"            // 用户支付中,需要输入密码
	AppIDNotExist      = "APPID_NOT_EXIST"       // APPID不存在
	MchIDNotExist      = "MCHID_NOT_EXIST"       // MCHID不存在
	AppIDMchIDNotMatch = "APPID_MCHID_NOT_MATCH" // appid和mch_id不匹配
	AuthCodeExpire     = "AUTHCODEEXPIRE"        // 二维码已过期,请用户在微信上刷新后再试
	AuthCodeError      = "AUTH_CODE_ERROR"       // 付款码参数错误
	AuthCodeInvalid    = "AUTH_CODE_INVALID"     // 付款码检验错误
	BankError          = "BANKERROR"             // 银行系统异常
	OrderNotExist      = "ORDERNOTEXIST"         // 订单不存在
	OrderPaid          = "ORDERPAID"             // 订单已支付
	OrderClosed        = "ORDERCLOSED"           // 订单已关闭
	OrderReversed      = "ORDERREVERSED"         // 订单已撤销
	RefundNotExist     = "REFUNDNOTEXIST"        // 退款不存在
	BuyerMismatch      = "BUYER_MISMATCH"        // 支付账号错误
	OutTradeNoUsed     = "OUT_TRADE_NO_USED"     // 商户订单号重复
	XmlFormatError     = "XML_FORMAT_ERROR"      // XML格式错误
	RequestPostMethod  = "REQUIRE_POST_METHOD"   // 请使用post方法
	PostDataEmpty      = "POST_DATA_EMPTY"       // post数据为空
	InvalidRequest     = "INVALID_REQUEST"       // 无效请求
	TradeError         = "TRADE_ERROR"           // 交易错误
	URLFormatError     = "URLFORMATERROR"        // URL格式错误
)

支付v2错误码

View Source
const AccessToken = "access_token"

Variables

This section is empty.

Functions

func DecodeBytesToUint32

func DecodeBytesToUint32(b []byte) uint32

DecodeBytesToUint32 从 4 字节的网络字节序里解析出整数 uint32

func EncodeUint32ToBytes

func EncodeUint32ToBytes(i uint32) []byte

EncodeUint32ToBytes 把整数 uint32 格式化成 4 字节的网络字节序

func EventDecrypt

func EventDecrypt(receiveID, encodingAESKey, cipherText string) ([]byte, error)

EventDecrypt 事件消息解密

[参考](https://developer.work.weixin.qq.com/document/path/90968)

func EventEncrypt

func EventEncrypt(receiveID, encodingAESKey, nonce string, plainText []byte) (*crypts.CipherText, error)

EventEncrypt 时间消息加密

[参考](https://developer.work.weixin.qq.com/document/path/90968)

func SignWithSHA1

func SignWithSHA1(token string, items ...string) string

SignWithSHA1 事件消息sha1签名

func ValueToXML

func ValueToXML(vals V) (string, error)

ValueToXML value to xml

Types

type APIResult

type APIResult struct {
	Code int // HTTP状态码
	Body gjson.Result
}

APIResult API结果 (支付v3)

type AuthScope

type AuthScope string

AuthScope 网页授权作用域

const (
	SnsapiBase        AuthScope = "snsapi_base"        // 静默授权,可获取基础信息
	SnsapiUser        AuthScope = "snsapi_userinfo"    // 手动授权(公众号),可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息
	SnsapiPrivateInfo AuthScope = "snsapi_privateinfo" // 手动授权(企业微信),可获取成员的详细信息,包含头像、二维码等敏感信息
)

type Corp

type Corp struct {
	// contains filtered or unexported fields
}

Corp 企业微信(企业内部开发)

func NewCorp

func NewCorp(corpid, secret string, options ...CorpOption) *Corp

NewCorp 生成一个企业微信(企业内部开发)实例

func (*Corp) AccessToken

func (c *Corp) AccessToken(ctx context.Context) (gjson.Result, error)

AccessToken 获取接口调用凭据

func (*Corp) AutoLoadAccessToken

func (c *Corp) AutoLoadAccessToken(fn func(ctx context.Context, c *Corp) (string, error), interval time.Duration) error

AutoLoadAccessToken 自动加载AccessToken

func (*Corp) CorpID

func (c *Corp) CorpID() string

AppID 返回AppID

func (*Corp) DecodeEventMsg

func (c *Corp) DecodeEventMsg(encrypt string) ([]byte, error)

DecodeEventMsg 事件消息解密

使用包体内的 Encrypt 字段
[参考](https://developer.work.weixin.qq.com/document/path/96211)

func (*Corp) EncodeEventReply

func (c *Corp) EncodeEventReply(msg V) (V, error)

EncodeEventReply 事件回复加密

[参考](https://developer.work.weixin.qq.com/document/path/96211)

func (*Corp) GetBuffer

func (c *Corp) GetBuffer(ctx context.Context, path string, query url.Values) ([]byte, error)

GetBuffer GET请求获取buffer (如:获取媒体资源)

func (*Corp) GetJSON

func (c *Corp) GetJSON(ctx context.Context, path string, query url.Values) (gjson.Result, error)

GetJSON GET请求JSON数据

func (*Corp) OAuthURL

func (c *Corp) OAuthURL(scope AuthScope, redirectURI, state, agentID string) string

OAuthURL 生成网页授权URL

[参考](https://developer.work.weixin.qq.com/document/path/91022)

func (*Corp) PostBuffer

func (c *Corp) PostBuffer(ctx context.Context, path string, params X) ([]byte, error)

PostBuffer POST请求获取buffer (如:获取二维码)

func (*Corp) PostJSON

func (c *Corp) PostJSON(ctx context.Context, path string, params X) (gjson.Result, error)

PostJSON POST请求JSON数据

func (*Corp) Secret

func (c *Corp) Secret() string

Secret 返回Secret

func (*Corp) Upload

func (c *Corp) Upload(ctx context.Context, reqPath, fieldName, filePath string, formData Form, query url.Values) (gjson.Result, error)

Upload 上传媒体资源

func (*Corp) UploadWithReader

func (c *Corp) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, formData Form, query url.Values) (gjson.Result, error)

UploadWithReader 上传媒体资源

func (*Corp) VerifyEventMsg

func (c *Corp) VerifyEventMsg(signature string, items ...string) error

VerifyEventMsg 验证事件消息

[服务器URL验证]
URL参数中的 msg_signature、timestamp、nonce、echostr
注意:验证成功后,需将 echostr 解密,然后返回 msg 字段值

[事件消息验证]
URL参数中的 msg_signature、timestamp、nonce 和包体内的 Encrypt 字段

[参考](https://developer.work.weixin.qq.com/document/path/90930)

type CorpOption

type CorpOption func(c *Corp)

CorpOption 企业微信设置项

func WithCorpClient

func WithCorpClient(cli *http.Client) CorpOption

WithCorpClient 设置企业微信请求的 HTTP Client

func WithCorpLogger

func WithCorpLogger(fn func(ctx context.Context, err error, data map[string]string)) CorpOption

WithCorpLogger 设置企业微信日志记录

func WithCorpSrvCfg

func WithCorpSrvCfg(token, aeskey string) CorpOption

WithCorpSrvCfg 设置企业微信服务器配置

[参考](https://developer.work.weixin.qq.com/document/path/90968)

type DownloadResult

type DownloadResult struct {
	HashType  string
	HashValue string
	Buffer    []byte
}

DownloadResult 资源下载结果 (支付v3)

type Form

type Form map[string]string

type MPOption

type MPOption func(mp *MiniProgram)

MPOption 小程序设置项

func WithMPAesKey

func WithMPAesKey(serialNO, key string) MPOption

WithMPAesKey 设置小程序 AES-GCM 加密Key

func WithMPClient

func WithMPClient(cli *http.Client) MPOption

WithMPClient 设置小程序请求的 HTTP Client

func WithMPLogger

func WithMPLogger(fn func(ctx context.Context, err error, data map[string]string)) MPOption

WithMPLogger 设置小程序日志记录

func WithMPPrivateKey

func WithMPPrivateKey(key *crypts.PrivateKey) MPOption

WithMPPrivateKey 设置小程序RSA私钥

func WithMPPublicKey

func WithMPPublicKey(serialNO string, key *crypts.PublicKey) MPOption

WithMPPublicKey 设置小程序平台RSA公钥

func WithMPSrvCfg

func WithMPSrvCfg(token, aeskey string) MPOption

WithMPSrvCfg 设置小程序服务器配置

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

type MiniProgram

type MiniProgram struct {
	// contains filtered or unexported fields
}

MiniProgram 小程序

func NewMiniProgram

func NewMiniProgram(appid, secret string, options ...MPOption) *MiniProgram

NewMiniProgram 生成一个小程序实例

func (*MiniProgram) AccessToken

func (mp *MiniProgram) AccessToken(ctx context.Context) (gjson.Result, error)

AccessToken 获取接口调用凭据

func (*MiniProgram) AppID

func (mp *MiniProgram) AppID() string

AppID 返回appid

func (*MiniProgram) AutoLoadAccessToken

func (mp *MiniProgram) AutoLoadAccessToken(interval time.Duration) error

AutoLoadAccessToken 自动加载AccessToken(使用StableAccessToken接口)

func (*MiniProgram) Code2Session

func (mp *MiniProgram) Code2Session(ctx context.Context, code string) (gjson.Result, error)

Code2Session 通过临时登录凭证code完成登录流程

func (*MiniProgram) CustomAccessTokenLoad

func (mp *MiniProgram) CustomAccessTokenLoad(fn func(ctx context.Context, mp *MiniProgram) (string, error), interval time.Duration) error

CustomAccessTokenLoad 自定义加载AccessToken

func (*MiniProgram) DecodeEncryptData

func (mp *MiniProgram) DecodeEncryptData(sessionKey, iv, encryptData string) ([]byte, error)

DecodeEncryptData 解析加密数据,如:授权的用户信息和手机号

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html)

func (*MiniProgram) DecodeEventMsg

func (mp *MiniProgram) DecodeEventMsg(encrypt string) ([]byte, error)

DecodeEventMsg 事件消息解密

使用包体内的 Encrypt 字段
根据配置的数据格式,解析 XML/JSON
[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

func (*MiniProgram) EncodeEventReply

func (mp *MiniProgram) EncodeEventReply(msg V) (V, error)

EncodeEventReply 事件回复加密

根据配置的数据格式,输出 XML/JSON
[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

func (*MiniProgram) GetBuffer

func (mp *MiniProgram) GetBuffer(ctx context.Context, path string, query url.Values) ([]byte, error)

GetBuffer GET请求获取buffer (如:获取媒体资源)

func (*MiniProgram) GetJSON

func (mp *MiniProgram) GetJSON(ctx context.Context, path string, query url.Values) (gjson.Result, error)

GetJSON GET请求JSON数据

func (*MiniProgram) PostBuffer

func (mp *MiniProgram) PostBuffer(ctx context.Context, path string, params X) ([]byte, error)

PostBuffer POST请求获取buffer (如:获取二维码)

func (*MiniProgram) PostJSON

func (mp *MiniProgram) PostJSON(ctx context.Context, path string, params X) (gjson.Result, error)

PostJSON POST请求JSON数据

func (*MiniProgram) SafePostBuffer

func (mp *MiniProgram) SafePostBuffer(ctx context.Context, path string, params X) ([]byte, error)

SafePostBuffer POST请求获取buffer (如:获取二维码)

[安全鉴权模式](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html)
[支持的API](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc)

func (*MiniProgram) SafePostJSON

func (mp *MiniProgram) SafePostJSON(ctx context.Context, path string, params X) (gjson.Result, error)

SafePostJSON POST请求JSON数据

[安全鉴权模式](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html)
[支持的API](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc)

func (*MiniProgram) Secret

func (mp *MiniProgram) Secret() string

Secret 返回secret

func (*MiniProgram) StableAccessToken

func (mp *MiniProgram) StableAccessToken(ctx context.Context, forceRefresh bool) (gjson.Result, error)

StableAccessToken 获取稳定版接口调用凭据

有两种调用模式:
[普通模式] access_token有效期内重复调用该接口不会更新access_token,绝大部分场景下使用该模式;
[强制刷新模式] 会导致上次获取的access_token失效,并返回新的access_token

func (*MiniProgram) Upload

func (mp *MiniProgram) Upload(ctx context.Context, reqPath, fieldName, filePath string, formData Form, query url.Values) (gjson.Result, error)

Upload 上传媒体资源

func (*MiniProgram) UploadWithReader

func (mp *MiniProgram) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, formData Form, query url.Values) (gjson.Result, error)

UploadWithReader 上传媒体资源

func (*MiniProgram) VerifyEventMsg

func (mp *MiniProgram) VerifyEventMsg(signature string, items ...string) error

VerifyEventMsg 验证事件消息

[服务器URL验证]
URL参数中的 signature、timestamp、nonce
注意:验证成功后,原样返回 echostr 字段值

[事件消息验证]
[明文模式] URL参数中的 signature、timestamp、nonce
[安全模式] URL参数中的 msg_signature、timestamp、nonce 和包体内的 Encrypt 字段

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

type OAOption

type OAOption func(oa *OfficialAccount)

OAOption 公众号设置项

func WithOAClient

func WithOAClient(cli *http.Client) OAOption

WithOAClient 设置公众号请求的 HTTP Client

func WithOALogger

func WithOALogger(fn func(ctx context.Context, err error, data map[string]string)) OAOption

WithOALogger 设置公众号日志记录

func WithOASrvCfg

func WithOASrvCfg(token, aeskey string) OAOption

WithOASrvCfg 设置公众号服务器配置

[参考](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html)

type OfficialAccount

type OfficialAccount struct {
	// contains filtered or unexported fields
}

OfficialAccount 微信公众号

func NewOfficialAccount

func NewOfficialAccount(appid, secret string, options ...OAOption) *OfficialAccount

NewOfficialAccount 生成一个公众号实例

func (*OfficialAccount) AccessToken

func (oa *OfficialAccount) AccessToken(ctx context.Context) (gjson.Result, error)

AccessToken 获取接口调用凭据

func (*OfficialAccount) AppID

func (oa *OfficialAccount) AppID() string

AppID returns appid

func (*OfficialAccount) AutoLoadAccessToken

func (oa *OfficialAccount) AutoLoadAccessToken(interval time.Duration) error

AutoLoadAccessToken 自动加载AccessToken(使用StableAccessToken接口)

func (*OfficialAccount) Code2OAuthToken

func (oa *OfficialAccount) Code2OAuthToken(ctx context.Context, code string) (gjson.Result, error)

Code2OAuthToken 获取网页授权Token

func (*OfficialAccount) CustomAccessTokenLoad

func (oa *OfficialAccount) CustomAccessTokenLoad(fn func(ctx context.Context, oa *OfficialAccount) (string, error), interval time.Duration) error

CustomAccessTokenLoad 自定义加载AccessToken

func (*OfficialAccount) DecodeEventMsg

func (oa *OfficialAccount) DecodeEventMsg(encrypt string) ([]byte, error)

DecodeEventMsg 事件消息解密

使用包体内的 Encrypt 字段
根据配置的数据格式,解析 XML/JSON
[参考](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Message_encryption_and_decryption_instructions.html)

func (*OfficialAccount) EncodeEventReply

func (oa *OfficialAccount) EncodeEventReply(msg V) (V, error)

EncodeEventReply 事件回复加密

根据配置的数据格式,输出 XML/JSON
[参考](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Message_encryption_and_decryption_instructions.html)

func (*OfficialAccount) GetBuffer

func (oa *OfficialAccount) GetBuffer(ctx context.Context, path string, query url.Values) ([]byte, error)

GetBuffer GET请求获取buffer (如:获取媒体资源)

func (*OfficialAccount) GetJSON

func (oa *OfficialAccount) GetJSON(ctx context.Context, path string, query url.Values) (gjson.Result, error)

GetJSON GET请求JSON数据

func (*OfficialAccount) OAuth2URL

func (oa *OfficialAccount) OAuth2URL(scope AuthScope, redirectURI, state string) string

OAuth2URL 生成网页授权URL

[参考](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)

func (*OfficialAccount) PostBuffer

func (oa *OfficialAccount) PostBuffer(ctx context.Context, path string, params X) ([]byte, error)

PostBuffer POST请求获取buffer (如:获取二维码)

func (*OfficialAccount) PostJSON

func (oa *OfficialAccount) PostJSON(ctx context.Context, path string, params X) (gjson.Result, error)

PostJSON POST请求JSON数据

func (*OfficialAccount) RefreshOAuthToken

func (oa *OfficialAccount) RefreshOAuthToken(ctx context.Context, refreshToken string) (gjson.Result, error)

RefreshOAuthToken 刷新网页授权Token

func (*OfficialAccount) Secret

func (oa *OfficialAccount) Secret() string

Secret returns app secret

func (*OfficialAccount) StableAccessToken

func (oa *OfficialAccount) StableAccessToken(ctx context.Context, forceRefresh bool) (gjson.Result, error)

StableAccessToken 获取稳定版接口调用凭据

有两种调用模式:
[普通模式] access_token 有效期内重复调用该接口不会更新 access_token,绝大部分场景下使用该模式;
[强制刷新模式] 会导致上次获取的 access_token 失效,并返回新的 access_token

func (*OfficialAccount) SubscribeMsgAuthURL

func (oa *OfficialAccount) SubscribeMsgAuthURL(scene, templateID, redirectURL, reserved string) string

SubscribeMsgAuthURL 公众号一次性订阅消息授权URL

[参考](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/One-time_subscription_info.html)

func (*OfficialAccount) Upload

func (oa *OfficialAccount) Upload(ctx context.Context, reqPath, fieldName, filePath string, formData Form, query url.Values) (gjson.Result, error)

Upload 上传媒体资源

func (*OfficialAccount) UploadWithReader

func (oa *OfficialAccount) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, formData Form, query url.Values) (gjson.Result, error)

UploadWithReader 上传媒体资源

func (*OfficialAccount) VerifyEventMsg

func (oa *OfficialAccount) VerifyEventMsg(signature string, items ...string) error

VerifyEventMsg 验证事件消息

[服务器URL验证]
   URL参数中的 signature、timestamp、nonce
   注意:验证成功后,原样返回 echostr 字段值
[参考](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html)

[事件消息验证]
[明文模式] URL参数中的 signature、timestamp、nonce
[安全模式] URL参数中的 msg_signature、timestamp、nonce 和 包体内的 Encrypt 字段
[参考](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Message_encryption_and_decryption_instructions.html)

type Pay

type Pay struct {
	// contains filtered or unexported fields
}

Pay 微信支付

func NewPay

func NewPay(mchid, apikey string, options ...PayOption) *Pay

NewPay 生成一个微信支付实例

func (*Pay) APPAPI

func (p *Pay) APPAPI(appid, prepayID string) V

APPAPI 用于APP拉起支付

func (*Pay) ApiKey

func (p *Pay) ApiKey() string

ApiKey 返回apikey

func (*Pay) DecryptRefund

func (p *Pay) DecryptRefund(encrypt string) (V, error)

DecryptRefund 退款结果通知解密

func (*Pay) JSAPI

func (p *Pay) JSAPI(appid, prepayID string) V

JSAPI 用于JS拉起支付

func (*Pay) MchID

func (p *Pay) MchID() string

MchID 返回mchid

func (*Pay) MinipRedpackJSAPI

func (p *Pay) MinipRedpackJSAPI(appid, pkg string) V

MinipRedpackJSAPI 小程序领取红包

func (*Pay) PostBuffer

func (p *Pay) PostBuffer(ctx context.Context, path string, params V) ([]byte, error)

PostBuffer POST请求获取buffer (无证书请求,如:下载交易订单)

func (*Pay) PostTLSXML

func (p *Pay) PostTLSXML(ctx context.Context, path string, params V) (V, error)

PostTLSXML POST请求XML数据 (带证书请求)

func (*Pay) PostTlsBuffer

func (p *Pay) PostTlsBuffer(ctx context.Context, path string, params V) ([]byte, error)

PostBuffer POST请求获取buffer (带证书请求,如:下载资金账单)

func (*Pay) PostXML

func (p *Pay) PostXML(ctx context.Context, path string, params V) (V, error)

PostXML POST请求XML数据 (无证书请求)

func (*Pay) Sign

func (p *Pay) Sign(v V) string

func (*Pay) Verify

func (p *Pay) Verify(v V) error

type PayOption

type PayOption func(p *Pay)

PayOption 微信支付设置项

func WithPayCert

func WithPayCert(cert tls.Certificate) PayOption

WithPayTLSCert 设置支付TLS证书

func WithPayClient

func WithPayClient(cli *http.Client) PayOption

WithPayClient 设置支付无证书 HTTP Client

func WithPayLogger

func WithPayLogger(fn func(ctx context.Context, err error, data map[string]string)) PayOption

WithPayLogger 设置支付日志记录

func WithPayTlsClient

func WithPayTlsClient(cli *http.Client) PayOption

WithPayTlsClient 设置支付带证书 HTTP Client

type PayV3

type PayV3 struct {
	// contains filtered or unexported fields
}

PayV3 微信支付V3

func NewPayV3

func NewPayV3(mchid, apikey string, options ...PayV3Option) *PayV3

NewPayV3 生成一个微信支付(v3)实例

func (*PayV3) APPAPI

func (p *PayV3) APPAPI(appid, prepayID string) (V, error)

APPAPI 用于APP拉起支付

func (*PayV3) ApiKey

func (p *PayV3) ApiKey() string

ApiKey 返回apikey

func (*PayV3) Authorization

func (p *PayV3) Authorization(method, path string, query url.Values, body string) (string, error)

Authorization 生成签名并返回 HTTP Authorization

func (*PayV3) AutoLoadCerts

func (p *PayV3) AutoLoadCerts(interval time.Duration) error

AutoLoadCerts 自动加载平台证书

func (*PayV3) Download

func (p *PayV3) Download(ctx context.Context, downloadURL string, w io.Writer) error

Download 下载资源 (需先获取download_url)

func (*PayV3) GetJSON

func (p *PayV3) GetJSON(ctx context.Context, path string, query url.Values) (*APIResult, error)

GetJSON GET请求JSON数据

func (*PayV3) JSAPI

func (p *PayV3) JSAPI(appid, prepayID string) (V, error)

JSAPI 用于JS拉起支付

func (*PayV3) MchID

func (p *PayV3) MchID() string

MchID 返回mchid

func (*PayV3) PostJSON

func (p *PayV3) PostJSON(ctx context.Context, path string, params X) (*APIResult, error)

PostJSON POST请求JSON数据

func (*PayV3) Upload

func (p *PayV3) Upload(ctx context.Context, reqPath, fieldName, filePath, metadata string, query url.Values) (*APIResult, error)

Upload 上传资源

func (*PayV3) UploadWithReader

func (p *PayV3) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, metadata string, query url.Values) (*APIResult, error)

UploadWithReader 上传资源

func (*PayV3) Verify

func (p *PayV3) Verify(ctx context.Context, header http.Header, body []byte) error

Verify 验证微信签名

type PayV3Option

type PayV3Option func(p *PayV3)

PayV3Option 微信支付(v3)设置项

func WithPayV3Client

func WithPayV3Client(cli *http.Client) PayV3Option

WithPayV3Client 设置支付(v3)请求的 HTTP Client

func WithPayV3Logger

func WithPayV3Logger(fn func(ctx context.Context, err error, data map[string]string)) PayV3Option

WithPayV3Logger 设置支付(v3)日志记录

func WithPayV3PrivateKey

func WithPayV3PrivateKey(serialNO string, key *crypts.PrivateKey) PayV3Option

WithPayV3PrivateKey 设置支付(v3)商户RSA私钥

type SafeMode

type SafeMode struct {
	// contains filtered or unexported fields
}

SafeMode 安全鉴权模式配置

type ServerConfig

type ServerConfig struct {
	// contains filtered or unexported fields
}

ServerConfig 服务器配置

type SignAlgo

type SignAlgo string

SignAlgo 签名算法

const (
	SignMD5        SignAlgo = "MD5"
	SignHMacSHA256 SignAlgo = "HMAC-SHA256"
)

type V

type V = values.V

func EventReply

func EventReply(receiveID, token, encodingAESKey string, msg V) (V, error)

func XMLToValue

func XMLToValue(b []byte) (V, error)

XMLToValue xml to value

type X

type X map[string]any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳