Documentation ¶
Index ¶
- type Amount
- type BillResponse
- type CloseOrderRequest
- type CloseRequest
- type Detail
- type GoodsDetail
- type JsapiApiService
- func (a *JsapiApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (result *core.APIResult, err error)
- func (a *JsapiApiService) DownloadURL(ctx context.Context, bill BillResponse) (resp []byte, result *core.APIResult, err error)
- func (a *JsapiApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error)
- func (a *JsapiApiService) PrepayWithRequestPayment(ctx context.Context, req PrepayRequest) (resp *PrepayWithRequestPaymentResponse, result *core.APIResult, err error)
- func (a *JsapiApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *payments.Transaction, result *core.APIResult, err error)
- func (a *JsapiApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *payments.Transaction, result *core.APIResult, err error)
- func (a *JsapiApiService) TradeBill(ctx context.Context, req TradeBillRequest) (resp *BillResponse, result *core.APIResult, err error)
- type Payer
- type PrepayRequest
- type PrepayResponse
- type PrepayWithRequestPaymentResponse
- type QueryOrderByIdRequest
- type QueryOrderByOutTradeNoRequest
- type SceneInfo
- type SettleInfo
- type StoreInfo
- type TradeBillRequest
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Amount ¶
type Amount struct { // 订单总金额,单位为分 Total *int64 `json:"total"` // CNY:人民币,境内商户号仅支持人民币。 Currency *string `json:"currency,omitempty"` }
Amount
func (Amount) MarshalJSON ¶
type BillResponse ¶
type BillResponse struct { // 哈希类型 // 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性。 HashType *string `json:"hash_type"` // 哈希值 // 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性。 HashValue *string `json:"hash_value"` // 账单下载地址 // 供下一步请求账单文件的下载地址,该地址30s内有效。 DownloadURL *string `json:"download_url"` }
func (BillResponse) Clone ¶
func (r BillResponse) Clone() *BillResponse
func (BillResponse) MarshalJSON ¶
func (r BillResponse) MarshalJSON() ([]byte, error)
func (BillResponse) String ¶
func (r BillResponse) String() string
type CloseOrderRequest ¶
type CloseOrderRequest struct { OutTradeNo *string `json:"out_trade_no"` // 直连商户号 Mchid *string `json:"mchid"` }
CloseOrderRequest
func (CloseOrderRequest) Clone ¶
func (o CloseOrderRequest) Clone() *CloseOrderRequest
func (CloseOrderRequest) MarshalJSON ¶
func (o CloseOrderRequest) MarshalJSON() ([]byte, error)
func (CloseOrderRequest) String ¶
func (o CloseOrderRequest) String() string
type CloseRequest ¶
type CloseRequest struct { // 直连商户号 Mchid *string `json:"mchid"` }
CloseRequest
func (CloseRequest) Clone ¶
func (o CloseRequest) Clone() *CloseRequest
func (CloseRequest) MarshalJSON ¶
func (o CloseRequest) MarshalJSON() ([]byte, error)
func (CloseRequest) String ¶
func (o CloseRequest) String() string
type Detail ¶
type Detail struct { // 1.商户侧一张小票订单可能被分多次支付,订单原价用于记录整张小票的交易金额。 2.当订单原价与支付金额不相等,则不享受优惠。 3.该字段主要用于防止同一张小票分多次支付,以享受多次优惠的情况,正常支付订单不必上传此参数。 CostPrice *int64 `json:"cost_price,omitempty"` // 商家小票ID。 InvoiceId *string `json:"invoice_id,omitempty"` GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"` }
Detail 优惠功能
func (Detail) MarshalJSON ¶
type GoodsDetail ¶
type GoodsDetail struct { // 由半角的大小写字母、数字、中划线、下划线中的一种或几种组成。 MerchantGoodsId *string `json:"merchant_goods_id"` // 微信支付定义的统一商品编号(没有可不传)。 WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"` // 商品的实际名称。 GoodsName *string `json:"goods_name,omitempty"` // 用户购买的数量。 Quantity *int64 `json:"quantity"` // 商品单价,单位为分。 UnitPrice *int64 `json:"unit_price"` }
GoodsDetail
func (GoodsDetail) Clone ¶
func (o GoodsDetail) Clone() *GoodsDetail
func (GoodsDetail) MarshalJSON ¶
func (o GoodsDetail) MarshalJSON() ([]byte, error)
func (GoodsDetail) String ¶
func (o GoodsDetail) String() string
type JsapiApiService ¶
func (*JsapiApiService) CloseOrder ¶
func (a *JsapiApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (result *core.APIResult, err error)
CloseOrder 关闭订单
以下情况需要调用关单接口: 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。
Example ¶
package main import ( "context" "log" "gitee.com/eden-w2w/wechatpay-go/core" "gitee.com/eden-w2w/wechatpay-go/core/option" "gitee.com/eden-w2w/wechatpay-go/services/payments/jsapi" "gitee.com/eden-w2w/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 := jsapi.JsapiApiService{Client: client} result, err := svc.CloseOrder(ctx, jsapi.CloseOrderRequest{ OutTradeNo: core.String("OutTradeNo_example"), Mchid: core.String("1230000109"), }, ) if err != nil { // 处理错误 log.Printf("call CloseOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d", result.Response.StatusCode) } }
Output:
func (*JsapiApiService) DownloadURL ¶
func (a *JsapiApiService) DownloadURL(ctx context.Context, bill BillResponse) ( resp []byte, result *core.APIResult, err error, )
func (*JsapiApiService) Prepay ¶
func (a *JsapiApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error)
Prepay JSAPI支付下单
商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。
Example ¶
package main import ( "context" "log" "time" "gitee.com/eden-w2w/wechatpay-go/core" "gitee.com/eden-w2w/wechatpay-go/core/option" "gitee.com/eden-w2w/wechatpay-go/services/payments/jsapi" "gitee.com/eden-w2w/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 := jsapi.JsapiApiService{Client: client} resp, result, err := svc.Prepay(ctx, jsapi.PrepayRequest{ Appid: core.String("wxd678efh567hg6787"), Mchid: core.String("1230000109"), Description: core.String("Image形象店-深圳腾大-QQ公仔"), OutTradeNo: core.String("1217752501201407033233368018"), TimeExpire: core.Time(time.Now()), Attach: core.String("自定义数据说明"), NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"), GoodsTag: core.String("WXG"), LimitPay: []string{"LimitPay_example"}, SupportFapiao: core.Bool(false), Amount: &jsapi.Amount{ Currency: core.String("CNY"), Total: core.Int64(100), }, Payer: &jsapi.Payer{ Openid: core.String("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"), }, Detail: &jsapi.Detail{ CostPrice: core.Int64(608800), GoodsDetail: []jsapi.GoodsDetail{jsapi.GoodsDetail{ GoodsName: core.String("iPhoneX 256G"), MerchantGoodsId: core.String("ABC"), Quantity: core.Int64(1), UnitPrice: core.Int64(828800), WechatpayGoodsId: core.String("1001"), }}, InvoiceId: core.String("wx123"), }, SceneInfo: &jsapi.SceneInfo{ DeviceId: core.String("013467007045764"), PayerClientIp: core.String("14.23.150.211"), StoreInfo: &jsapi.StoreInfo{ Address: core.String("广东省深圳市南山区科技中一道10000号"), AreaCode: core.String("440305"), Id: core.String("0001"), Name: core.String("腾讯大厦分店"), }, }, SettleInfo: &jsapi.SettleInfo{ ProfitSharing: core.Bool(false), }, }, ) if err != nil { // 处理错误 log.Printf("call Prepay err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*JsapiApiService) PrepayWithRequestPayment ¶
func (a *JsapiApiService) PrepayWithRequestPayment( ctx context.Context, req PrepayRequest, ) (resp *PrepayWithRequestPaymentResponse, result *core.APIResult, err error)
PrepayWithRequestPayment Jsapi支付下单,并返回调起支付的请求参数
func (*JsapiApiService) QueryOrderById ¶
func (a *JsapiApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *payments.Transaction, result *core.APIResult, err error)
QueryOrderById 微信支付订单号查询订单
商户可以通过查询订单接口主动查询订单状态
Example ¶
package main import ( "context" "log" "gitee.com/eden-w2w/wechatpay-go/core" "gitee.com/eden-w2w/wechatpay-go/core/option" "gitee.com/eden-w2w/wechatpay-go/services/payments/jsapi" "gitee.com/eden-w2w/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 := jsapi.JsapiApiService{Client: client} resp, result, err := svc.QueryOrderById(ctx, jsapi.QueryOrderByIdRequest{ TransactionId: core.String("TransactionId_example"), Mchid: core.String("Mchid_example"), }, ) if err != nil { // 处理错误 log.Printf("call QueryOrderById err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*JsapiApiService) QueryOrderByOutTradeNo ¶
func (a *JsapiApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *payments.Transaction, result *core.APIResult, err error)
QueryOrderByOutTradeNo 商户订单号查询订单
商户可以通过查询订单接口主动查询订单状态
Example ¶
package main import ( "context" "log" "gitee.com/eden-w2w/wechatpay-go/core" "gitee.com/eden-w2w/wechatpay-go/core/option" "gitee.com/eden-w2w/wechatpay-go/services/payments/jsapi" "gitee.com/eden-w2w/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 := jsapi.JsapiApiService{Client: client} resp, result, err := svc.QueryOrderByOutTradeNo(ctx, jsapi.QueryOrderByOutTradeNoRequest{ OutTradeNo: core.String("OutTradeNo_example"), Mchid: core.String("Mchid_example"), }, ) if err != nil { // 处理错误 log.Printf("call QueryOrderByOutTradeNo err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*JsapiApiService) TradeBill ¶
func (a *JsapiApiService) TradeBill(ctx context.Context, req TradeBillRequest) ( resp *BillResponse, result *core.APIResult, err error, )
type Payer ¶
type Payer struct { // 用户在商户appid下的唯一标识。 Openid *string `json:"openid,omitempty"` }
Payer
func (Payer) MarshalJSON ¶
type PrepayRequest ¶
type PrepayRequest struct { // 公众号ID Appid *string `json:"appid"` // 直连商户号 Mchid *string `json:"mchid"` // 商品描述 Description *string `json:"description"` // 商户订单号 OutTradeNo *string `json:"out_trade_no"` // 订单失效时间,格式为rfc3339格式 TimeExpire *time.Time `json:"time_expire,omitempty"` // 附加数据 Attach *string `json:"attach,omitempty"` // 有效性:1. HTTPS;2. 不允许携带查询串。 NotifyUrl *string `json:"notify_url"` // 商品标记,代金券或立减优惠功能的参数。 GoodsTag *string `json:"goods_tag,omitempty"` // 指定支付方式 LimitPay []string `json:"limit_pay,omitempty"` // 传入true时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效。 SupportFapiao *bool `json:"support_fapiao,omitempty"` Amount *Amount `json:"amount"` Payer *Payer `json:"payer"` Detail *Detail `json:"detail,omitempty"` SceneInfo *SceneInfo `json:"scene_info,omitempty"` SettleInfo *SettleInfo `json:"settle_info,omitempty"` }
PrepayRequest
func (PrepayRequest) Clone ¶
func (o PrepayRequest) Clone() *PrepayRequest
func (PrepayRequest) MarshalJSON ¶
func (o PrepayRequest) MarshalJSON() ([]byte, error)
func (PrepayRequest) String ¶
func (o PrepayRequest) String() string
type PrepayResponse ¶
type PrepayResponse struct { // 预支付交易会话标识 PrepayId *string `json:"prepay_id"` }
PrepayResponse
func (PrepayResponse) Clone ¶
func (o PrepayResponse) Clone() *PrepayResponse
func (PrepayResponse) MarshalJSON ¶
func (o PrepayResponse) MarshalJSON() ([]byte, error)
func (PrepayResponse) String ¶
func (o PrepayResponse) String() string
type PrepayWithRequestPaymentResponse ¶
type PrepayWithRequestPaymentResponse struct { // 预支付交易会话标识 PrepayId *string `json:"prepay_id"` // revive:disable-line:var-naming // 应用ID Appid *string `json:"appId"` // 时间戳 TimeStamp *string `json:"timeStamp"` // 随机字符串 NonceStr *string `json:"nonceStr"` // 订单详情扩展字符串 Package *string `json:"package"` // 签名方式 SignType *string `json:"signType"` // 签名 PaySign *string `json:"paySign"` }
PrepayWithRequestPaymentResponse 预下单ID,并包含了调起支付的请求参数
func (PrepayWithRequestPaymentResponse) String ¶
func (o PrepayWithRequestPaymentResponse) String() string
type QueryOrderByIdRequest ¶
type QueryOrderByIdRequest struct { TransactionId *string `json:"transaction_id"` // 直连商户号 Mchid *string `json:"mchid"` }
QueryOrderByIdRequest
func (QueryOrderByIdRequest) Clone ¶
func (o QueryOrderByIdRequest) Clone() *QueryOrderByIdRequest
func (QueryOrderByIdRequest) MarshalJSON ¶
func (o QueryOrderByIdRequest) MarshalJSON() ([]byte, error)
func (QueryOrderByIdRequest) String ¶
func (o QueryOrderByIdRequest) String() string
type QueryOrderByOutTradeNoRequest ¶
type QueryOrderByOutTradeNoRequest struct { OutTradeNo *string `json:"out_trade_no"` // 直连商户号 Mchid *string `json:"mchid"` }
QueryOrderByOutTradeNoRequest
func (QueryOrderByOutTradeNoRequest) Clone ¶
func (o QueryOrderByOutTradeNoRequest) Clone() *QueryOrderByOutTradeNoRequest
func (QueryOrderByOutTradeNoRequest) MarshalJSON ¶
func (o QueryOrderByOutTradeNoRequest) MarshalJSON() ([]byte, error)
func (QueryOrderByOutTradeNoRequest) String ¶
func (o QueryOrderByOutTradeNoRequest) String() string
type SceneInfo ¶
type SceneInfo struct { // 用户终端IP PayerClientIp *string `json:"payer_client_ip"` // 商户端设备号 DeviceId *string `json:"device_id,omitempty"` StoreInfo *StoreInfo `json:"store_info,omitempty"` }
SceneInfo 支付场景描述
func (SceneInfo) MarshalJSON ¶
type SettleInfo ¶
type SettleInfo struct { // 是否指定分账 ProfitSharing *bool `json:"profit_sharing,omitempty"` }
SettleInfo
func (SettleInfo) Clone ¶
func (o SettleInfo) Clone() *SettleInfo
func (SettleInfo) MarshalJSON ¶
func (o SettleInfo) MarshalJSON() ([]byte, error)
func (SettleInfo) String ¶
func (o SettleInfo) String() string
type StoreInfo ¶
type StoreInfo struct { // 商户侧门店编号 Id *string `json:"id"` // 商户侧门店名称 Name *string `json:"name,omitempty"` // 地区编码,详细请见微信支付提供的文档 AreaCode *string `json:"area_code,omitempty"` // 详细的商户门店地址 Address *string `json:"address,omitempty"` }
StoreInfo 商户门店信息
func (StoreInfo) MarshalJSON ¶
type TradeBillRequest ¶
type TradeBillRequest struct { // 账单日期 // 格式YYYY-MM-DD 仅支持三个月内的账单下载申请 BillDate *string `json:"bill_date"` // 账单类型 不填则默认是ALL // ALL:返回当日所有订单信息(不含充值退款订单) // SUCCESS:返回当日成功支付的订单(不含充值退款订单) // REFUND:返回当日退款订单(不含充值退款订单) BillType *string `json:"bill_type,omitempty"` // 压缩类型 不填则默认是数据流 // GZIP:返回格式为.gzip的压缩包账单 TarType *string `json:"tar_type,omitempty"` }
TradeBillRequest 申请交易账单请求
func (TradeBillRequest) Clone ¶
func (r TradeBillRequest) Clone() *TradeBillRequest
func (TradeBillRequest) MarshalJSON ¶
func (r TradeBillRequest) MarshalJSON() ([]byte, error)
func (TradeBillRequest) String ¶
func (r TradeBillRequest) String() string