wxpay

package module
v0.0.7 Latest Latest
Warning

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

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

README

微信相关接口(简易版)

微信V2版本支付(JSAPI支付,Native支付,APP支付,H5支付,小程序支付)、小程序登录、生成小程序二维码

安装

启用 Go module
go get github.com/Caiqm/wxpay-v2
import wxpay "github.com/Caiqm/wxpay-v2"

如何使用

// 实例化微信支付
var client, err = wxpay.New(appID, Secret)
关于密钥(Secret)

密钥是微信应用的唯一凭证密钥,即 AppSecret,获取方式同 appid

加载支持配置

// 加载支付接口链接,商户号ID与支付密钥
client.LoadOptionFunc(WithPayHost(), WithMchInformation(mchId, mchSecret))

// 或者一开始就加载支付接口链接,商户号ID与支付密钥
var client, err = wxpay.New(appID, Secret, WithPayHost(), WithMchInformation(mchId, mchSecret))
关于加载支持配置

系统内置了几种可支付的配置

// 设置请求链接,可自定义请求接口,传入host字符串
WithApiHost(HOST)

// 设置小程序登录链接
WithJsCodeHost()

// 设置支付请求链接
WithPayHost()

// 设置申请退款请求链接
WithRefundHost()

// 设置商户号信息,传入商户号ID与支付密钥
WithMchInformation(mchId, mchSecret)

// 也可自定义传入配置,返回以下类型即可
type OptionFunc func(c *Client)

小程序登录

// 小程序登录code2Session
func TestClient_Code2Session(t *testing.T) {
	t.Log("========== Code2Session ==========")
	client.LoadOptionFunc(WithJsCodeHost())
	var p Code2Session
	p.JsCode = "" // 前端获取的code值
	r, err := client.Code2Session(p)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(r)
}

小程序支付

// 小程序支付
func TestClient_TradeApplet(t *testing.T) {
	t.Log("========== TradeApplet ==========")
	client.LoadOptionFunc(WithPayHost(), WithMchInformation(mchId, mchSecret))
	var p TradeApplet
	p.Body = "支付测试"
	p.OutTradeNo = "TEST2023112717521212345678"
	p.TotalFee = "1"
	p.SpbillCreateIp = ""
	p.OpenId = ""
	p.NotifyUrl = "https://www.weixin.qq.com/wxpay/pay.php"
	r, err := client.TradeApplet(p)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(r)
}

Documentation

Index

Constants

View Source
const (
	ReturnCodeSuccess ReturnCode = "SUCCESS" // 支付接口调用成功
	ErrCodeSuccess    ErrCode    = 0         // 小程序接口调用成功
)

Variables

View Source
var (
	ErrWxNullParams         = errors.New("wxpay: param is null")
	ErrWxReturnCodeNotFound = errors.New("wxpay: return_code not found")
	ErrWxPemKeyNotFound     = errors.New("wxpay: wxpay pem or key cert not found")
)

Functions

This section is empty.

Types

type AppletError

type AppletError struct {
	Errcode ErrCode `json:"errcode"` // 错误信息
	Errmsg  string  `json:"errmsg"`  // 错误码
}

AppletError 小程序错误

func (AppletError) Error

func (e AppletError) Error() string

func (AppletError) IsFailure

func (e AppletError) IsFailure() bool

func (AppletError) IsSuccess

func (e AppletError) IsSuccess() bool

type AuxParam

type AuxParam struct {
}

func (AuxParam) NeedAppId

func (aux AuxParam) NeedAppId() bool

func (AuxParam) NeedSecret

func (aux AuxParam) NeedSecret() bool

func (AuxParam) NeedSign

func (aux AuxParam) NeedSign() bool

func (AuxParam) NeedTlsCert

func (aux AuxParam) NeedTlsCert() bool

func (AuxParam) NeedVerify

func (aux AuxParam) NeedVerify() bool

func (AuxParam) ReturnType

func (aux AuxParam) ReturnType() string

type Client

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

func New

func New(appId, secret string, opts ...OptionFunc) (nClient *Client, err error)

初始化

func (*Client) LoadAppCertPemKeyFromFile

func (c *Client) LoadAppCertPemKeyFromFile(pemCertPath, keyCertPath string) (err error)

加载证书文件

func (*Client) LoadOptionFunc

func (c *Client) LoadOptionFunc(opts ...OptionFunc)

加载接口链接

func (*Client) LoadTlsCertConfig

func (c *Client) LoadTlsCertConfig() (tlsConfig *tls.Config, err error)

加载证书tls配置

func (*Client) OnReceivedData

func (c *Client) OnReceivedData(fn func(method string, data []byte))

返回内容

func (*Client) TradeApp

func (c *Client) TradeApp(param TradeApp) (result *TradeAppRsp, err error)

TradeApp APP统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 POST https://api.mch.weixin.qq.com/pay/unifiedorder

func (*Client) TradeApplet

func (c *Client) TradeApplet(param TradeApplet) (result TradeAppletPayRsp, err error)

TradeApplet 小程序统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1 POST https://api.mch.weixin.qq.com/pay/unifiedorder

func (*Client) TradeJSAPI

func (c *Client) TradeJSAPI(param TradeJSAPI) (result *TradeJSAPIRsp, err error)

TradeJSAPI 微信内H5统一下单 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1 POST https://api.mch.weixin.qq.com/pay/unifiedorder

func (*Client) TradeNative

func (c *Client) TradeNative(param TradeNative) (result *TradeNativeRsp, err error)

TradeNative Native统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1 POST https://api.mch.weixin.qq.com/pay/unifiedorder

func (*Client) URLValues

func (c *Client) URLValues(param Param) (value url.Values, err error)

请求参数

func (*Client) VerifySign

func (c *Client) VerifySign(values url.Values) (err error)

验证签名

type Code2Session

type Code2Session struct {
	AuxParam
	GrantType string `json:"grant_type"`
	JsCode    string `json:"js_code"`
}

Code2Session 小程序登录 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html

func (Code2Session) NeedSecret

func (a Code2Session) NeedSecret() bool

func (Code2Session) NeedSign

func (a Code2Session) NeedSign() bool

func (Code2Session) NeedVerify

func (a Code2Session) NeedVerify() bool

type Code2SessionRsp

type Code2SessionRsp struct {
	AppletError
	OpenId     string `json:"openid"`      // 用户唯一标识
	SessionKey string `json:"session_key"` // 会话密钥
	UnionId    string `json:"unionid"`     // 用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台账号下会返回
}

Code2SessionRsp 小程序登录返回参数 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html

type CreateQRCode

type CreateQRCode struct {
	Qrcode
	Path  string `json:"path"`  // 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar",即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:"bar"}。scancode_time为系统保留参数,不允许配置。
	Width int    `json:"width"` // 二维码的宽度,单位 px。最小 280px,最大 1280px;默认是430
}

CreateQRCode 获取小程序二维码 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/createQRCode.html 获取小程序二维码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制,详见获取二维码。

type ErrCode

type ErrCode int32

ErrCode 微信小程序接口响应错误码

func (ErrCode) IsFailure

func (c ErrCode) IsFailure() bool

func (ErrCode) IsSuccess

func (c ErrCode) IsSuccess() bool

type GetAccessToken

type GetAccessToken struct {
	AuxParam
	GrantType string `json:"grant_type"`
}

GetAccessToken 接口调用凭据 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html

func (GetAccessToken) NeedSecret

func (a GetAccessToken) NeedSecret() bool

func (GetAccessToken) NeedSign

func (a GetAccessToken) NeedSign() bool

func (GetAccessToken) NeedVerify

func (a GetAccessToken) NeedVerify() bool

type GetAccessTokenRsp

type GetAccessTokenRsp struct {
	AppletError
	AccessToken string `json:"access_token"` // 获取到的凭证
	ExpiresIn   int    `json:"expires_in"`   // 凭证有效时间,单位:秒。目前是7200秒之内的值
}

GetAccessTokenRsp 接口调用凭据响应参数

type GetPhoneNumber

type GetPhoneNumber struct {
	AuxParam
	Code   string `json:"code"`             // 手机号获取凭证
	Openid string `json:"openid,omitempty"` // 用户OPENID
}

GetPhoneNumber 获取手机号 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html

func (GetPhoneNumber) NeedAppId

func (pn GetPhoneNumber) NeedAppId() bool

func (GetPhoneNumber) NeedSign

func (pn GetPhoneNumber) NeedSign() bool

func (GetPhoneNumber) NeedVerify

func (pn GetPhoneNumber) NeedVerify() bool

func (GetPhoneNumber) ReturnType added in v0.0.7

func (pn GetPhoneNumber) ReturnType() string

type GetPhoneNumberRsp

type GetPhoneNumberRsp struct {
	AppletError
	PhoneInfo PhoneNumberInfo `json:"phone_info"` // 用户手机号信息
}

GetPhoneNumberRsp 获取手机号响应参数

type GetQRCode

type GetQRCode struct {
	Qrcode
	Path       string    `json:"path"`                 // 扫码进入的小程序页面路径,最大长度 1024 个字符,不能为空,scancode_time为系统保留参数,不允许配置;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar",即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:"bar"}。
	Width      int       `json:"width"`                // 二维码的宽度,单位 px。默认值为430,最小 280px,最大 1280px
	AutoColor  bool      `json:"auto_color"`           // 默认值false;自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
	LineColor  LineColor `json:"line_color,omitempty"` // 默认值{"r":0,"g":0,"b":0} ;auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示
	IsHyaline  bool      `json:"is_hyaline"`           // 默认是false,是否需要透明底色,为 true 时,生成透明底色的小程序
	EnvVersion string    `json:"env_version"`          // 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
}

GetQRCode 获取小程序码 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getQRCode.html 该接口用于获取小程序码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制。

type GetWxACodeUnLimit

type GetWxACodeUnLimit struct {
	Qrcode
	Page       string    `json:"page"`                 // 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
	Scene      string    `json:"scene"`                // 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
	CheckPath  bool      `json:"check_path"`           // 默认是true,检查page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在, 但page 有数量上限(60000个)请勿滥用。
	EnvVersion string    `json:"env_version"`          // 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
	Width      int       `json:"width"`                // 默认430,二维码的宽度,单位 px,最小 280px,最大 1280px
	AutoColor  bool      `json:"auto_color"`           // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
	LineColor  LineColor `json:"line_color,omitempty"` // 二维码线条颜色,默认为黑色
	IsHyaline  bool      `json:"is_hyaline"`           // 默认是false,是否需要透明底色,为 true 时,生成透明底色的小程序
}

GetWxACodeUnLimit 获取不限制的小程序码 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html 该接口用于获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制。

type LineColor

type LineColor struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

type OptionFunc

type OptionFunc func(c *Client)

func WithApiHost

func WithApiHost(host string) OptionFunc

设置请求链接

func WithJsCodeHost

func WithJsCodeHost() OptionFunc

设置小程序登录链接

func WithMchInformation

func WithMchInformation(id, secret string) OptionFunc

设置商户号信息

func WithPayHost

func WithPayHost() OptionFunc

设置支付请求链接

func WithRefundHost

func WithRefundHost() OptionFunc

设置申请退款请求链接

type Param

type Param interface {
	// NeedAppId 是否需要APPID,有的借口不需要APPID,比如:小程序二维码接口
	NeedAppId() bool

	// NeedSecret 是否需要密钥,有的借口不需要密钥,比如:支付接口,小程序获取手机号接口
	NeedSecret() bool

	// NeedSign 是否需要签名,有的接口不需要签名,比如:小程序登录与获取手机号接口
	NeedSign() bool

	// NeedVerify 是否对微信接口返回的数据进行签名验证, 为了安全建议都需要对签名进行验证,本方法存在是因为部分接口不支持签名验证。
	NeedVerify() bool

	// NeedTlsCert 是否需要证书,有的接口需要,比如:申请退款接口、提现到零钱用户接口
	NeedTlsCert() bool

	// ReturnType 返回类型,v2版本的接口都是xml的,为兼容小程序接口需要切换json
	ReturnType() string
}

type PayError

type PayError struct {
	ReturnCode ReturnCode `json:"return_code" xml:"return_code"`   // 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断
	ReturnMsg  string     `json:"return_msg" xml:"return_msg"`     // 返回信息,如非空,为错误原因
	ErrCode    string     `json:"err_code" xml:"err_code"`         // 错误代码
	ErrCodeDes string     `json:"err_code_des" xml:"err_code_des"` // 错误信息描述
	ResultCode string     `json:"result_code" xml:"result_code"`   // 业务结果,SUCCESS/FAIL
}

PayError 支付错误类

func (PayError) Error

func (e PayError) Error() string

func (PayError) IsFailure

func (e PayError) IsFailure() bool

func (PayError) IsSuccess

func (e PayError) IsSuccess() bool

type PhoneNumberInfo

type PhoneNumberInfo struct {
	PhoneNumber     string     `json:"phoneNumber"`     // 用户绑定的手机号(国外手机号会有区号)
	PurePhoneNumber string     `json:"purePhoneNumber"` // 没有区号的手机号
	CountryCode     string     `json:"countryCode"`     // 区号
	Watermark       WatermarkS `json:"watermark"`       // 数据水印
}

type Qrcode

type Qrcode struct {
	AuxParam
}

func (Qrcode) NeedAppId

func (g Qrcode) NeedAppId() bool

func (Qrcode) NeedSign

func (g Qrcode) NeedSign() bool

func (Qrcode) NeedVerify

func (g Qrcode) NeedVerify() bool

func (Qrcode) ReturnType

func (g Qrcode) ReturnType() string

type QrcodeRsp

type QrcodeRsp struct {
	AppletError
	Buffer []byte `json:"buffer"` // 二维码二进制
}

type ReturnCode

type ReturnCode string

ReturnCode 微信支付接口响应错误码

func (ReturnCode) IsFailure

func (c ReturnCode) IsFailure() bool

func (ReturnCode) IsSuccess

func (c ReturnCode) IsSuccess() bool

type SceneInfo

type SceneInfo struct {
	H5Info struct {
		Type        string `json:"type"`
		WapURL      string `json:"wap_url,omitempty"`
		WapName     string `json:"wap_name,omitempty"`
		AppName     string `json:"app_name,omitempty"`
		BundleId    string `json:"bundle_id,omitempty"`
		PackageName string `json:"package_name,omitempty"`
	} `json:"h5_info,omitempty"`
	StoreInfo struct {
		ID       string `json:"id"`
		Name     string `json:"name"`
		AreaCode string `json:"area_code"`
		Address  string `json:"address"`
	} `json:"store_info,omitempty"`
}

type Trade

type Trade struct {
	AuxParam
	NotifyUrl string `xml:"notify_url" json:"notify_url"` // 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http。
	// 必填,主要参数
	Body           string `xml:"body" json:"body"`                         // 商品描述交易字段格式根据不同的应用场景按照以下格式: APP——需传入应用市场上的APP名字-实际商品名称,天天爱消除-游戏充值。
	OutTradeNo     string `xml:"out_trade_no" json:"out_trade_no"`         // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。
	TotalFee       string `xml:"total_fee" json:"total_fee"`               // 订单总金额,单位为分
	SpbillCreateIp string `xml:"spbill_create_ip" json:"spbill_create_ip"` // 支持IPV4和IPV6两种格式的IP地址。调用微信支付API的机器IP
	TradeType      string `xml:"trade_type" json:"trade_type"`             // 支付类型
	// 选填,额外参数
	Attach        string `xml:"attach,omitempty" json:"attach,omitempty"`                 // 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
	DeviceInfo    string `xml:"device_info,omitempty" json:"device_info,omitempty"`       // 自定义参数,可以为终端设备号(门店号或收银设备ID),PC网页或公众号内支付可以传"WEB"
	Detail        string `xml:"detail,omitempty" json:"detail,omitempty"`                 // 商品详细描述,对于使用单品优惠的商户,该字段必须按照规范上传
	FeeType       string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`             // 标价币种,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	TimeStart     string `xml:"time_start,omitempty" json:"time_start,omitempty"`         // 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
	TimeExpire    string `xml:"time_expire,omitempty" json:"time_expire,omitempty"`       // 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。
	GoodsTag      string `xml:"goods_tag,omitempty" json:"goods_tag,omitempty"`           // 订单优惠标记,使用代金券或立减优惠功能时需要的参数
	ProductId     string `xml:"product_id,omitempty" json:"product_id,omitempty"`         // 商品ID,trade_type=NATIVE时,此参数必传。此参数为二维码中包含的商品ID,商户自行定义。
	LimitPay      string `xml:"limit_pay,omitempty" json:"limit_pay,omitempty"`           // 指定支付方式,上传此参数no_credit--可限制用户不能使用信用卡支付
	Receipt       string `xml:"receipt,omitempty" json:"receipt,omitempty"`               // 电子发票入口开放标识,Y,传入Y时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效
	ProfitSharing string `xml:"profit_sharing,omitempty" json:"profit_sharing,omitempty"` // 是否需要分账,Y-是,需要分账 N-否,不分账 字母要求大写,不传默认不分账
	SceneInfo     string `xml:"scene_info,omitempty" json:"scene_info,omitempty"`         // 场景信息,WAP支付必填,该字段常用于线下活动时的场景信息上报,支持上报实际门店信息,商户也可以按需求自己上报相关信息。该字段为JSON对象数据,对象格式为{"store_info":{"id": "门店ID","name": "名称","area_code": "编码","address": "地址" }}
}

请求参数

type TradeApp

type TradeApp struct {
	Trade
}

TradeApp APP统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1

func (TradeApp) ReturnType

func (t TradeApp) ReturnType() string

type TradeAppRsp

type TradeAppRsp struct {
	TradeResponse
}

TradeAppRsp APP统一下单接口响应参数

type TradeApplet

type TradeApplet struct {
	Trade
	OpenId string `xml:"openid" json:"openid"` // trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。
}

TradeApplet 小程序统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1

func (TradeApplet) ReturnType

func (t TradeApplet) ReturnType() string

type TradeAppletPayRsp added in v0.0.6

type TradeAppletPayRsp struct {
	AppID     string `json:"appId"`
	Timestamp string `json:"timeStamp"`
	NonceStr  string `json:"nonceStr"`
	Package   string `json:"package"`
	SignType  string `json:"signType"`
	PaySign   string `json:"paySign"`
}

type TradeAppletRsp

type TradeAppletRsp struct {
	TradeResponse
	CodeUrl string `xml:"code_url,omitempty" json:"code_url"` // trade_type=NATIVE时有返回,此url用于生成支付二维码,然后提供给用户进行扫码支付。注意:code_url的值并非固定,使用时按照URL格式转成二维码即可。时效性为2小时
}

TradeAppletRsp 小程序统一下单响应参数

type TradeCloseOrder

type TradeCloseOrder struct {
	AuxParam
	OutTradeNo string `xml:"out_trade_no" json:"out_trade_no"` // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一
}

TradeCloseOrder 关闭订单 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3

func (TradeCloseOrder) ReturnType

func (t TradeCloseOrder) ReturnType() string

type TradeCloseOrderRsp

type TradeCloseOrderRsp struct {
	PayError
	AppID     string `xml:"appid" json:"appid"`           // 微信分配的公众账号ID
	MchID     string `xml:"mch_id" json:"mch_id"`         // 微信支付分配的商户号
	NonceStr  string `xml:"nonce_str" json:"nonce_str"`   // 随机字符串,不长于32位
	Sign      string `xml:"sign" json:"sign"`             // 签名
	ResultMsg string `xml:"result_msg" json:"result_msg"` // 对业务结果的补充说明
}

TradeCloseOrderRsp 关闭订单响应参数

type TradeJSAPI

type TradeJSAPI struct {
	Trade
	OpenId string `xml:"openid" json:"openid"` // trade_type=JSAPI时(即JSAPI支付),此参数必传,此参数为微信用户在商户对应appid下的唯一标识。openid如何获取
}

TradeJSAPI 微信内H5统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1

func (TradeJSAPI) ReturnType

func (t TradeJSAPI) ReturnType() string

type TradeJSAPIRsp

type TradeJSAPIRsp struct {
	TradeResponse
	CodeUrl string `xml:"code_url,omitempty" json:"code_url"` // trade_type=NATIVE时有返回,此url用于生成支付二维码,然后提供给用户进行扫码支付。注意:code_url的值并非固定,使用时按照URL格式转成二维码即可。时效性为2小时
}

TradeJSAPIRsp TradeJSAPI 微信内H5统一下单响应参数

type TradeNative

type TradeNative struct {
	Trade
}

TradeNative Native统一下单接口 https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1

func (TradeNative) ReturnType

func (t TradeNative) ReturnType() string

type TradeNativeRsp

type TradeNativeRsp struct {
	TradeResponse
	CodeUrl string `xml:"code_url" json:"code_url"` // trade_type=NATIVE时有返回,此url用于生成支付二维码,然后提供给用户进行扫码支付。注意:code_url的值并非固定,使用时按照URL格式转成二维码即可。时效性为2小时
}

TradeNativeRsp Native统一下单接口响应参数

type TradeOrderQuery

type TradeOrderQuery struct {
	AuxParam
	OutTradeNo    string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`     // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。
	TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"` // 微信的订单号,建议优先使用
}

TradeOrderQuery 查询订单 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_2

func (TradeOrderQuery) ReturnType

func (t TradeOrderQuery) ReturnType() string

type TradeOrderQueryRsp

type TradeOrderQueryRsp struct {
	PayError
	DeviceInfo         string `xml:"device_info" json:"device_info"`                             // 微信支付分配的终端设备号
	OpenId             string `xml:"openid" json:"openid"`                                       // 用户在商户appid下的唯一标识
	IsSubscribe        string `xml:"is_subscribe" json:"is_subscribe"`                           // 已废弃,默认统一返回N
	TradeType          string `xml:"trade_type" json:"trade_type"`                               // 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,MICROPAY
	TradeState         string `xml:"trade_state" json:"trade_state"`                             // SUCCESS--支付成功 REFUND--转入退款 NOTPAY--未支付 CLOSED--已关闭 REVOKED--已撤销(刷卡支付) USERPAYING--用户支付中 PAYERROR--支付失败(其他原因,如银行返回失败) ACCEPT--已接收,等待扣款
	BankType           string `xml:"bank_type" json:"bank_type"`                                 // 银行类型,采用字符串类型的银行标识
	TotalFee           int    `xml:"total_fee" json:"total_fee"`                                 // 订单总金额,单位为分
	SettlementTotalFee int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee"` // 当订单使用了免充值型优惠券后返回该参数,应结订单金额=订单金额-免充值优惠券金额。
	FeeType            string `xml:"fee_type" json:"fee_type"`                                   // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFee            int    `xml:"cash_fee,omitempty" json:"cash_fee"`                         // 现金支付金额订单现金支付金额
	CashFeeType        string `xml:"cash_fee_type,omitempty" json:"cash_fee_type"`               // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CouponFee          int    `xml:"coupon_fee,omitempty" json:"coupon_fee"`                     // “代金券”金额<=订单金额,订单金额-“代金券”金额=现金支付金额
	CouponCount        int    `xml:"coupon_count,omitempty" json:"coupon_count"`                 // 代金券使用数量
	CouponType0        string `xml:"coupon_type_0,omitempty" json:"coupon_type_0"`               // CASH:充值代金券 NO_CASH:非充值优惠券 开通免充值券功能,并且订单使用了优惠券后有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0
	CouponId0          string `xml:"coupon_id_0,omitempty" json:"coupon_id_0"`                   // 代金券ID, $n为下标,从0开始编号
	CouponFee0         string `xml:"coupon_fee_0,omitempty" json:"coupon_fee_0"`                 // 单个代金券支付金额, $n为下标,从0开始编号
	TransactionId      string `xml:"transaction_id" json:"transaction_id"`                       // 微信支付订单号
	OutTradeNo         string `xml:"out_trade_no" json:"out_trade_no"`                           // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一
	Attach             string `xml:"attach" json:"attach"`                                       // 附加数据,原样返回
	TimeEnd            string `xml:"time_end" json:"time_end"`                                   // 订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010
	TradeStateDesc     string `xml:"trade_state_desc" json:"trade_state_desc"`                   // 对当前查询订单状态的描述和下一步操作的指引
}

TradeOrderQueryRsp 查询订单响应参数

type TradeRefund

type TradeRefund struct {
	AuxParam
	OutTradeNo    string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`       // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id > out_trade_no
	TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`   // 微信生成的订单号,在支付通知中有返回
	OutRefundNo   string `xml:"out_refund_no" json:"out_refund_no"`                         // 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	TotalFee      string `xml:"total_fee" json:"total_fee"`                                 // 订单总金额,单位为分,只能为整数
	RefundFee     string `xml:"refund_fee" json:"refund_fee"`                               // 退款总金额,订单总金额,单位为分,只能为整数
	RefundFeeType string `xml:"refund_fee_type,omitempty" json:"refund_fee_type,omitempty"` // 退款货币类型,需与支付一致,或者不填。符合ISO 4217标准的三位字母代码,默认人民币:CNY
	RefundDesc    string `xml:"refund_desc" json:"refund_desc"`                             // 退款原因,若商户传入,会在下发给用户的退款消息中体现退款原因
	RefundAccount string `xml:"refund_account,omitempty" json:"refund_account,omitempty"`   // 退款资金来源,仅针对老资金流商户使用 REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款) REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款
	NotifyUrl     string `xml:"notify_url,omitempty" json:"notify_url,omitempty"`           // 异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数 公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
}

TradeRefund 申请退款 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4

func (TradeRefund) NeedTlsCert

func (t TradeRefund) NeedTlsCert() bool

func (TradeRefund) ReturnType

func (t TradeRefund) ReturnType() string

type TradeRefundQuery

type TradeRefundQuery struct {
	AuxParam
	TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"` // 微信订单号查询的优先级是: refund_id > out_refund_no > transaction_id > out_trade_no
	OutTradeNo    string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`     // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。
	OutRefundNo   string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`   // 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	RefundId      string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`           // 微信生成的退款单号,在申请退款接口有返回
	Offset        string `xml:"offset,omitempty" json:"offset,omitempty"`                 // 偏移量,当部分退款次数超过10次时可使用,表示返回的查询结果从这个偏移量开始取记录
}

TradeRefundQuery 查询退款 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_5

func (TradeRefundQuery) ReturnType

func (t TradeRefundQuery) ReturnType() string

type TradeRefundQueryRsp

type TradeRefundQueryRsp struct {
	PayError
	AppID                string `xml:"appid" json:"appid"`                                               // 微信分配的公众账号ID(企业号corpid即为此appid)
	MchID                string `xml:"mch_id" json:"mch_id"`                                             // 微信支付分配的商户号
	NonceStr             string `xml:"nonce_str" json:"nonce_str"`                                       // 随机字符串,不长于32位
	Sign                 string `xml:"sign" json:"sign"`                                                 // 签名
	TotalRefundCount     int    `xml:"total_refund_count" json:"total_refund_count"`                     // 订单总共已发生的部分退款次数,当请求参数传入offset后有返回
	TransactionId        string `xml:"transaction_id" json:"transaction_id"`                             // 微信订单号
	OutTradeNo           string `xml:"out_trade_no" json:"out_trade_no"`                                 // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。
	TotalFee             int    `xml:"total_fee" json:"total_fee"`                                       // 订单总金额,单位为分,只能为整数
	SettlementTotalFee   int    `xml:"settlement_total_fee" json:"settlement_total_fee"`                 // 应结订单金额,当订单使用了免充值型优惠券后返回该参数,应结订单金额=订单金额-免充值优惠券金额。
	FeeType              string `xml:"fee_type" json:"fee_type"`                                         // 货币种类,订单金额货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFee              int    `xml:"cash_fee" json:"cash_fee"`                                         // 现金支付金额,单位为分,只能为整数
	RefundCount          int    `xml:"refund_count" json:"refund_count"`                                 // 当前返回退款笔数
	OutRefundNo0         string `xml:"out_refund_no_0,omitempty" json:"out_refund_no_0"`                 // 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	RefundId0            string `xml:"refund_id_0,omitempty" json:"refund_id_0"`                         // 微信退款单号
	RefundChannel0       string `xml:"refund_channel_0,omitempty" json:"refund_channel_0"`               // 退款渠道 ORIGINAL—原路退款 BALANCE—退回到余额 OTHER_BALANCE—原账户异常退到其他余额账户 OTHER_BANKCARD—原银行卡异常退到其他银行卡
	RefundFee0           int    `xml:"refund_fee_0,omitempty" json:"refund_fee_0"`                       // 申请退款金额,退款总金额,单位为分,可以做部分退款
	RefundFee            int    `xml:"refund_fee" json:"refund_fee"`                                     // 退款总金额,各退款单的退款金额累加
	CouponRefundFee      int    `xml:"coupon_refund_fee" json:"coupon_refund_fee"`                       // 代金券退款总金额,各退款单的代金券退款金额累加
	SettlementRefundFee0 int    `xml:"settlement_refund_fee_0,omitempty" json:"settlement_refund_fee_0"` // 退款金额,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	CouponType00         string `xml:"coupon_type_0_0,omitempty" json:"coupon_type_00"`                  // 代金券类型,CASH--充值代金券 NO_CASH---非充值优惠券 开通免充值券功能,并且订单使用了优惠券后有返回(取值:CASH、NO_CASH)。$n为下标,$m为下标,从0开始编号,举例:coupon_type_$0_$1
	CouponRefundFee0     int    `xml:"coupon_refund_fee_0,omitempty" json:"coupon_refund_fee_0"`         // 总代金券退款金额,代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金
	CouponRefundCount0   int    `xml:"coupon_refund_count_0,omitempty" json:"coupon_refund_count_0"`     // 退款代金券使用数量 ,$n为下标,从0开始编号
	CouponRefundId00     string `xml:"coupon_refund_id_0_0,omitempty" json:"coupon_refund_id_00"`        // 退款代金券ID, $n为下标,$m为下标,从0开始编号
	CouponRefundFee00    int    `xml:"coupon_refund_fee_0_0,omitempty" json:"coupon_refund_fee_00"`      // 单个退款代金券支付金额, $n为下标,$m为下标,从0开始编号
	RefundStatus0        string `xml:"refund_status_0,omitempty" json:"refund_status_0"`                 // 退款状态: SUCCESS—退款成功 REFUNDCLOSE—退款关闭,指商户发起退款失败的情况。 PROCESSING—退款处理中 CHANGE—退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。$n为下标,从0开始编号。
	RefundAccount0       string `xml:"refund_account_0,omitempty" json:"refund_account_0"`               // 退款资金来源,REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款/基本账户 REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款 $n为下标,从0开始编号
	RefundRecvAccout0    string `xml:"refund_recv_accout_0,omitempty" json:"refund_recv_accout_0"`       // 退款入账账户,取当前退款单的退款入账方 1)退回银行卡: {银行名称}{卡类型}{卡尾号} 2)退回支付用户零钱: 支付用户零钱 3)退还商户: 商户基本账户 商户结算银行账户 4)退回支付用户零钱通: 支付用户零钱通
	RefundSuccessTime0   string `xml:"refund_success_time_0,omitempty" json:"refund_success_time_0"`     // 退款成功时间,当退款状态为退款成功时有返回。$n为下标,从0开始编号。
	CashRefundFee        int    `xml:"cash_refund_fee" json:"cash_refund_fee"`                           // 用户退款金额,退款给用户的金额,不包含所有优惠券金额
}

TradeRefundQueryRsp 查询退款响应参数

type TradeRefundRsp

type TradeRefundRsp struct {
	PayError
	AppID               string `xml:"appid" json:"appid"`                                   // 微信分配的公众账号ID
	MchID               string `xml:"mch_id" json:"mch_id"`                                 // 微信支付分配的商户号
	NonceStr            string `xml:"nonce_str" json:"nonce_str"`                           // 随机字符串,不长于32位
	Sign                string `xml:"sign" json:"sign"`                                     // 签名
	TransactionId       string `xml:"transaction_id" json:"transaction_id"`                 // 微信订单号
	OutTradeNo          string `xml:"out_trade_no" json:"out_trade_no"`                     // 商户系统内部订单号,要求32个字符内(最少6个字符),只能是数字、大小写字母_-|*且在同一个商户号下唯一。
	OutRefundNo         string `xml:"out_refund_no" json:"out_refund_no"`                   // 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	RefundId            string `xml:"refund_id" json:"refund_id"`                           // 微信退款单号
	RefundFee           int    `xml:"refund_fee" json:"refund_fee"`                         // 退款总金额,单位为分,可以做部分退款
	SettlementRefundFee int    `xml:"settlement_refund_fee" json:"settlement_refund_fee"`   // 应结退款金额,去掉非充值代金券退款金额后的退款金额,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	TotalFee            int    `xml:"total_fee" json:"total_fee"`                           // 订单总金额,单位为分,只能为整数
	SettlementTotalFee  int    `xml:"settlement_total_fee" json:"settlement_total_fee"`     // 应结订单金额,去掉非充值代金券金额后的订单总金额,应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	FeeType             string `xml:"fee_type" json:"fee_type"`                             // 标价币种,订单金额货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFee             int    `xml:"cash_fee" json:"cash_fee"`                             // 现金支付金额,单位为分,只能为整数
	CashFeeType         string `xml:"cash_fee_type" json:"cash_fee_type"`                   // 现金支付币种,货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashRefundFee       int    `xml:"cash_refund_fee" json:"cash_refund_fee"`               // 现金退款金额,单位为分,只能为整数
	CouponType0         string `xml:"coupon_type_0,omitempty" json:"coupon_type_0"`         // 代金券类型,CASH--充值代金券 NO_CASH---非充值代金券 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_0
	CouponRefundFee     int    `xml:"coupon_refund_fee,omitempty" json:"coupon_refund_fee"` // 代金券退款总金额,代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金
	CouponRefundFee0    int    `xml:"coupon_refund_fee_0" json:"coupon_refund_fee_0"`       // 单个代金券退款金额,代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金
	CouponRefundCount   int    `xml:"coupon_refund_count" json:"coupon_refund_count"`       // 退款代金券使用数量
	CouponRefundId0     string `xml:"coupon_refund_id_0" json:"coupon_refund_id_0"`         // 退款代金券ID, $n为下标,从0开始编号
}

TradeRefundRsp 申请退款响应参数

type TradeResponse

type TradeResponse struct {
	PayError
	AppID      string `xml:"appid" json:"appid"`                       // 调用接口提交的公众账号ID
	MchID      string `xml:"mch_id" json:"mch_id"`                     // 调用接口提交的商户号
	NonceStr   string `xml:"nonce_str" json:"nonce_str"`               // 微信返回的随机字符串
	Sign       string `xml:"sign" json:"sign"`                         // 微信返回的签名
	DeviceInfo string `xml:"device_info,omitempty" json:"device_info"` // 调用接口提交的终端设备号
	TradeType  string `xml:"trade_type" json:"trade_type"`             // 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,,H5支付固定传MWEB
	PrepayId   string `xml:"prepay_id" json:"prepay_id"`               // 微信生成的预支付会话标识,用于后续接口调用中使用,该值有效期为2小时,针对H5支付此参数无特殊用途
}

type TradeSceneInfo

type TradeSceneInfo struct {
	Id       string `json:"id"`        // 门店编号,由商户自定义
	Name     string `json:"name"`      // 门店名称 ,由商户自定义
	AreaCode string `json:"area_code"` // 门店所在地行政区划码
	Address  string `json:"address"`   // 门店详细地址 ,由商户自定义
}

TradeSceneInfo 场景信息

type TradeWap

type TradeWap struct {
	Trade
}

TradeWap H5支付 https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_20&index=1

func (TradeWap) ReturnType

func (t TradeWap) ReturnType() string

type TradeWapRsp

type TradeWapRsp struct {
	TradeResponse
	MWebUrl string `xml:"mweb_url" json:"mweb_url"` // mweb_url为拉起微信支付收银台的中间页面,可通过访问该url来拉起微信客户端,完成支付,mweb_url的有效期为5分钟。
}

TradeWapRsp Native统一下单接口响应参数

type WatermarkS

type WatermarkS struct {
	Timestamp int    `json:"timestamp"` // 用户获取手机号操作的时间戳
	Appid     string `json:"appid"`     // 小程序appid
}

Jump to

Keyboard shortcuts

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