Documentation
¶
Overview ¶
基础通讯业务实现 sam
Index ¶
- Constants
- Variables
- func MapToXML(params Params) string
- type AppPayResp
- type AppletPayResp
- type Client
- func (c *Client) AuthCodeToOpenid(params Params) (Params, error)
- func (c *Client) CloseOrder(params Params) (Params, error)
- func (c *Client) DownloadBill(params Params) (Params, error)
- func (c *Client) MicroPay(params Params) (Params, error)
- func (c *Client) Notify(req *http.Request) (Params, error)
- func (c *Client) OrderQuery(params Params) (Params, error)
- func (c *Client) Refund(params Params) (Params, error)
- func (c *Client) RefundNotify(req *http.Request) (Params, error)
- func (c *Client) RefundQuery(params Params) (Params, error)
- func (c *Client) Report(params Params) (Params, error)
- func (c *Client) Reverse(params Params) (Params, error)
- func (c *Client) SetHTTPConnectTimeoutMs(ms int)
- func (c *Client) SetHTTPReadTimeoutMs(ms int)
- func (c *Client) SetSignType(signType string)
- func (c *Client) ShortURL(params Params) (Params, error)
- func (c *Client) Sign(params Params) string
- func (c *Client) UnifiedOrder(params Params) (Params, error)
- func (c *Client) ValidSign(params Params) bool
- type Notifies
- type NotifyRet
- type Params
- type RefundNotifyReqInfo
- type TradeType
- type WxAPI
- func (m *WxAPI) AppTrade(body, outTradeNo string, totalFee int, clientIP string) (ret *AppPayResp, err error)
- func (m *WxAPI) AppletTrade(body, outTradeNo string, totalFee int, openID, clientIP string) (ret *AppletPayResp, err error)
- func (m *WxAPI) H5Trade(body, outTradeNo string, totalFee int, clientIP string) (ret string, err error)
- func (m *WxAPI) JSAPITrade(body, outTradeNo string, totalFee int, openID, clientIP string) (ret string, err error)
- func (m *WxAPI) NativeTrade(body, outTradeNo string, totalFee int) (ret string, err error)
- func (m *WxAPI) Notify(req *http.Request) (ret *NotifyRet, outTradeNo, tradeNo, openID string, err error)
- func (m *WxAPI) OrderQuery(transactionID, outTradeNo string) (state bool, tradeNo string, err error)
- func (m *WxAPI) Refund(transactionID, outTradeNo, outRefundNo, refundDesc string, ...) (refundId string, err error)
- func (m *WxAPI) RefundNotify(req *http.Request) (ret *NotifyRet, outTradeNo, refundStatus, recvName string, err error)
- func (m *WxAPI) RefundQuery(transactionID, outTradeNo, outRefundNo, refundId string) (status string, recvName string, err error)
- func (m *WxAPI) UnifiedOrder(body string, outTradeNo string, totalFee int, openID string, clientIP string, ...) (Params, error)
- type WxConfig
Constants ¶
const ( Fail = "FAIL" Success = "SUCCESS" HMACSHA256 = "HMAC-SHA256" MD5 = "MD5" Sign = "sign" MicroPayUrl = "https://api.mch.weixin.qq.com/pay/micropay" UnifiedOrderUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder" OrderQueryUrl = "https://api.mch.weixin.qq.com/pay/orderquery" ReverseUrl = "https://api.mch.weixin.qq.com/secapi/pay/reverse" CloseOrderUrl = "https://api.mch.weixin.qq.com/pay/closeorder" RefundUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund" RefundQueryUrl = "https://api.mch.weixin.qq.com/pay/refundquery" DownloadBillUrl = "https://api.mch.weixin.qq.com/pay/downloadbill" ReportUrl = "https://api.mch.weixin.qq.com/payitil/report" ShortUrl = "https://api.mch.weixin.qq.com/tools/shorturl" AuthCodeToOpenidUrl = "https://api.mch.weixin.qq.com/tools/authcodetoopenid" SandboxMicroPayUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/micropay" SandboxUnifiedOrderUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder" SandboxOrderQueryUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery" SandboxReverseUrl = "https://api.mch.weixin.qq.com/sandboxnew/secapi/pay/reverse" SandboxCloseOrderUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/closeorder" SandboxRefundUrl = "https://api.mch.weixin.qq.com/sandboxnew/secapi/pay/refund" SandboxRefundQueryUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/refundquery" SandboxDownloadBillUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/downloadbill" SandboxReportUrl = "https://api.mch.weixin.qq.com/sandboxnew/payitil/report" SandboxShortUrl = "https://api.mch.weixin.qq.com/sandboxnew/tools/shorturl" SandboxAuthCodeToOpenidUrl = "https://api.mch.weixin.qq.com/sandboxnew/tools/authcodetoopenid" )
常量
Variables ¶
var ( //RandChar 随机字串 RandChar = []byte("abcdefghijklmnopqrstuvwxyz0123456789") //RandCharLen 随机字串长度 RandCharLen int32 = 36 //TradeNumStr 商户订单号前缀 TradeNumStr = "WX" )
Functions ¶
Types ¶
type AppPayResp ¶
type AppPayResp struct {
AppID string `json:"appid"` //appid
PartnerID string `json:"partnerid"` //商户ID
PrepayID string `json:"prepayid"` //prepayid
Package string `json:"package"` //package
NonceStr string `json:"noncestr"` //随机字串
Timestamp string `json:"timestamp"` //时间
Sign string `json:"sign"` //签名
}
AppPayResp App支付时,返回的结构体 包括prepayID和Sign等其他信息
type AppletPayResp ¶ added in v0.4.2
type AppletPayResp struct {
Timestamp string `json:"timeStamp"` //时间
NonceStr string `json:"nonceStr"` //随机字串
Package string `json:"package"` //package
SignType string `json:"signType"`
Sign string `json:"paySign"` //签名
}
AppletPayResp 微信小程序支付时,返回的结构体 包括prepayID和Sign等其他信息
type Client ¶
type Client struct {
*WxConfig
// contains filtered or unexported fields
}
请求与返回的封装
func (*Client) AuthCodeToOpenid ¶
AuthCodeToOpenid 授权码查询OPENID接口
func (*Client) CloseOrder ¶
CloseOrder 关闭订单
func (*Client) DownloadBill ¶
DownloadBill 对账单下载
func (*Client) OrderQuery ¶
OrderQuery 订单查询
func (*Client) RefundNotify ¶ added in v0.6.8
RefundNotify 退款异步通知处理
func (*Client) RefundQuery ¶
RefundQuery 退款查询
func (*Client) SetHTTPConnectTimeoutMs ¶
SetHTTPConnectTimeoutMs SetHTTPConnectTimeoutMs
func (*Client) SetHTTPReadTimeoutMs ¶
SetHTTPReadTimeoutMs SetHTTPReadTimeoutMs
func (*Client) UnifiedOrder ¶
UnifiedOrder 统一下单
type NotifyRet ¶
type NotifyRet struct {
XMLName xml.Name `xml:"xml"`
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
}
NotifyRet 异步通知的返回值 返回
type RefundNotifyReqInfo ¶ added in v0.6.8
type RefundNotifyReqInfo struct {
TransactionId string `json:"transaction_id"`
OutTradeNo string `json:"out_trade_no"`
RefundId string `json:"refund_id"`
OutRefundNo string `json:"out_refund_no"`
TotalFee int64 `json:"total_fee"`
SettlementTotalFee int64 `json:"settlement_total_fee"` //应结订单金额
RefundFee int64 `json:"refund_fee"` //申请退款金额
SettlementRefundFee int64 `json:"settlement_refund_fee"` //退款金额
RefundStatus string `json:"refund_status"` //退款状态 SUCCESS-退款成功 CHANGE-退款异常 REFUNDCLOSE—退款关闭
RefundRecvAccout string `json:"refund_recv_accout"` //退款入账账户
RefundAccount string `json:"refund_account"` //退款资金来源 REFUND_SOURCE_RECHARGE_FUNDS 可用余额退款/基本账户 REFUND_SOURCE_UNSETTLED_FUNDS 未结算资金退款
RefundRequestSource string `json:"refund_request_source"` //退款发起来源 API接口 VENDOR_PLATFORM商户平台
}
RefundNotifyReqInfo 退款异步通知加密字段
type WxAPI ¶
type WxAPI struct {
Client *Client
}
WxAPI 调用实体
func (*WxAPI) AppTrade ¶
func (m *WxAPI) AppTrade(body, outTradeNo string, totalFee int, clientIP string) (ret *AppPayResp, err error)
AppTrade APP下单
func (*WxAPI) AppletTrade ¶ added in v0.4.2
func (m *WxAPI) AppletTrade(body, outTradeNo string, totalFee int, openID, clientIP string) (ret *AppletPayResp, err error)
AppletTrade 小程序支付 需要传入公众号对应用户的openID
func (*WxAPI) H5Trade ¶
func (m *WxAPI) H5Trade(body, outTradeNo string, totalFee int, clientIP string) (ret string, err error)
H5Trade H5下单
func (*WxAPI) JSAPITrade ¶
func (m *WxAPI) JSAPITrade(body, outTradeNo string, totalFee int, openID, clientIP string) (ret string, err error)
JSAPITrade 公众号支付 需要传入公众号对应用户的openID
func (*WxAPI) NativeTrade ¶
NativeTrade 扫码支付下单 使用时把返回的code_url生成二维码,供前台用户扫码支付
func (*WxAPI) Notify ¶
func (m *WxAPI) Notify(req *http.Request) (ret *NotifyRet, outTradeNo, tradeNo, openID string, err error)
Notify 异步通知 返回异步通知状态信息 调用方拿到返回值后,需要根据 outTradeNo tradeNo openID等值,做进一点检验,如果检验失败,设置ret.ReturnCode="FAIL"; 成功时,需要回写返回值到本地 最后以xml方式输出 ret
func (*WxAPI) OrderQuery ¶
func (m *WxAPI) OrderQuery(transactionID, outTradeNo string) (state bool, tradeNo string, err error)
OrderQuery 订单查询
返回是否成功,和错误信息
func (*WxAPI) Refund ¶ added in v0.6.8
func (m *WxAPI) Refund(transactionID, outTradeNo, outRefundNo, refundDesc string, totalFee, refundFee int) (refundId string, err error)
Refund 申请退款
func (*WxAPI) RefundNotify ¶ added in v0.6.8
func (m *WxAPI) RefundNotify(req *http.Request) (ret *NotifyRet, outTradeNo, refundStatus, recvName string, err error)
RefundNotify 退款异步通知 返回异步通知状态信息 以xml方式输出 ret
type WxConfig ¶
type WxConfig struct {
AppId string //传入的appID
MchId string //分配的mchID
APIKey string //分配的apiKey
ServerIP string //服务器IP
NotifyURL string //异步通知地址
OrderTime int //订单有效分钟数
RefundNotifyUrl string //订单退款异步通知地址
// contains filtered or unexported fields
}
WxConfig WxConfig
func NewWxConfig ¶
func NewWxConfig(appId, mchId, apiKey, serverIP string, isSandbox bool, notifyUrl string, orderTime int) *WxConfig
NewWxConfig 一个新的配置信息 也可以自己组装
func (*WxConfig) SetCertData ¶
SetCertData 设置证书