Documentation
¶
Overview ¶
基础通讯业务实现 sam
Index ¶
- Constants
- Variables
- func MapToXML(params Params) string
- type AppPayResp
- 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) 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 TradeType
- type WxAPI
- func (m *WxAPI) AppTrade(body, outTradeNo string, totalFee int, clientIP string) (ret *AppPayResp, 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, err error)
- func (m *WxAPI) UnifiedOrder(body string, outTradeNo string, totalFee int, openID string, clientIP string, ...) (Params, error)
- type WxConfig
Constants ¶
View Source
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 ¶
View Source
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 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) 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 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) 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 ¶
OrderQuery 订单查询 返回是否成功,和错误信息
type WxConfig ¶
type WxConfig struct { AppId string //传入的appID MchId string //分配的mchID APIKey string //分配的apiKey ServerIP string //服务器IP NotifyURL string //异步通知地址 OrderTime int //订单有效分钟数 // contains filtered or unexported fields }
WxConfig WxConfig
func NewWxConfig ¶
NewWxConfig 一个新的配置信息 也可以自己组装
func (*WxConfig) SetCertData ¶
SetCertData 设置证书
Click to show internal directories.
Click to hide internal directories.