Documentation ¶
Index ¶
- Constants
- func NewNonceString() string
- func NewTimestampString() string
- func Sign(param map[string]string, key string) string
- func SortAndConcat(param map[string]string) string
- func ToMap(in interface{}) (map[string]string, error)
- func ToXmlString(param map[string]string) string
- type AppTrans
- type PaymentRequest
- type PlaceOrderResult
- type QueryOrderResult
- type WxConfig
Constants ¶
const ChinaTimeZoneOffset = 8 * 60 * 60 //Beijing(UTC+8:00)
Variables ¶
This section is empty.
Functions ¶
func NewNonceString ¶
func NewNonceString() string
NewNonceString return random string in 32 characters
func Sign ¶
Sign the parameter in form of map[string]string with app key. Empty string and "sign" key is excluded before sign. Please refer to http://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=4_3
func SortAndConcat ¶
SortAndConcat sort the map by key in ASCII order, and concat it in form of "k1=v1&k2=2"
func ToXmlString ¶
ToXmlString convert the map[string]string to xml string
Types ¶
type AppTrans ¶
type AppTrans struct {
Config *WxConfig
}
AppTrans is abstact of Transaction handler. With AppTrans, we can get prepay id
func NewAppTrans ¶
Initialized the AppTrans with specific config
func (*AppTrans) NewPaymentRequest ¶
func (this *AppTrans) NewPaymentRequest(prepayId string) PaymentRequest
NewPaymentRequest build the payment request structure for app to start a payment. Return stuct of PaymentRequest, please refer to http://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_12&index=2
func (*AppTrans) Query ¶
func (this *AppTrans) Query(transId string) (QueryOrderResult, error)
Query the order from weixin pay server by transaction id of weixin pay
func (*AppTrans) Submit ¶
func (this *AppTrans) Submit(orderId string, amount float64, desc string, clientIp string) (string, error)
Submit the order to weixin pay and return the prepay id if success, Prepay id is used for app to start a payment If fail, error is not nil, check error for more information
type PaymentRequest ¶
type PlaceOrderResult ¶
type PlaceOrderResult struct { XMLName xml.Name `xml:"xml"` ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` AppId string `xml:"appid"` MchId string `xml:"mch_id"` DeviceInfo string `xml:"device_info"` NonceStr string `xml:"nonce_str"` Sign string `xml:"sign"` ResultCode string `xml:"result_code"` ErrCode string `xml:"err_code"` ErrCodeDesc string `xml:"err_code_des"` TradeType string `xml:"trade_type"` PrepayId string `xml:"prepay_id"` CodeUrl string `xml:"code_url"` }
PlaceOrderResult represent place order reponse message from weixin pay. For field explanation refer to: http://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_1
func ParsePlaceOrderResult ¶
func ParsePlaceOrderResult(resp []byte) (PlaceOrderResult, error)
Parse the reponse message from weixin pay to struct of PlaceOrderResult
func (*PlaceOrderResult) ToMap ¶
func (this *PlaceOrderResult) ToMap() map[string]string
type QueryOrderResult ¶
type QueryOrderResult struct { XMLName xml.Name `xml:"xml"` ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` AppId string `xml:"appid"` MchId string `xml:"mch_id"` NonceStr string `xml:"nonce_str"` Sign string `xml:"sign"` ResultCode string `xml:"result_code"` ErrCode string `xml:"err_code"` ErrCodeDesc string `xml:"err_code_des"` DeviceInfo string `xml:"device_info"` OpenId string `xml:"open_id"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` TradeState string `xml:"trade_state"` TradeStateDesc string `xml:"trade_state_desc"` BankType string `xml:"bank_type"` TotalFee string `xml:"total_fee"` FeeType string `xml:"fee_type"` CashFee string `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CouponFee string `xml:"coupon_fee"` CouponCount string `xml:"coupon_count"` TransactionId string `xml:"transaction_id"` OrderId string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` }
QueryOrder Result represent query response message from weixin pay Refer to http://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_2&index=4
func ParseQueryOrderResult ¶
func ParseQueryOrderResult(resp []byte) (QueryOrderResult, error)
func (*QueryOrderResult) ToMap ¶
func (this *QueryOrderResult) ToMap() map[string]string