package wechat import ( "encoding/xml" "git.chuangxin1.com/cx/myth" ) // PayConfig WeChat pay configure type PayConfig struct { AppID string `json:"appid"` MchID string `json:"mchid"` Key string `json:"key"` AppSecret string `json:"appsecret"` SSLCert string `json:"sslcert"` SSLKey string `json:"sslkey"` ContractID string `json:"contractid"` NotifyURL string `json:"notify_url"` } // PayUnifiedOrder https://api.mch.weixin.qq.com/pay/unifiedorder type PayUnifiedOrder struct { XMLName xml.Name `xml:"xml"` AppID string `xml:"appid"` MchID string `xml:"mch_id"` Body string `xml:"body"` NonceStr string `xml:"nonce_str"` NotifyURL string `xml:"notify_url"` TradeType string `xml:"trade_type"` OpenID string `xml:"openid"` SpbillCreateIP string `xml:"spbill_create_ip"` TimeStart string `xml:"time_start"` TotalFee int `xml:"total_fee"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` Sign string `xml:"sign"` } // PayOrderQuery https://api.mch.weixin.qq.com/pay/orderquery type PayOrderQuery struct { XMLName xml.Name `xml:"xml"` AppID string `xml:"appid"` MchID string `xml:"mch_id"` NonceStr string `xml:"nonce_str"` TransactionID string `xml:"transaction_id,omitempty"` OutTradeNo string `xml:"out_trade_no,omitempty"` Sign string `xml:"sign"` } // PayReply pay reply type PayReply struct { XMLName xml.Name `xml:"xml" json:"_,omitempty"` 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"` PrePayID string `xml:"prepay_id"` TradeType string `xml:"trade_type"` URL string `xml:"code_url"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` OpenID string `xml:"openid"` Attach string `xml:"attach"` IsSubscribe string `xml:"is_subscribe"` BankType string `xml:"bank_type"` CashFee string `xml:"cash_fee"` FeeType string `xml:"fee_type"` OutTradeNo string `xml:"out_trade_no"` TimeEnd string `xml:"time_end"` TotalFee string `xml:"total_fee"` TradeState string `xml:"trade_state"` TradeStateDesc string `xml:"trade_state_desc"` TransactionID string `xml:"transaction_id"` ContractID string `form:"contract_id" xml:"contract_id"` } // PayQuery order query 订单查询 func PayQuery(cpyid int, config PayConfig, order PayOrderQuery) (reply PayReply, err error) { m := make(map[string]interface{}) m["appid"] = order.AppID m["mch_id"] = order.MchID m["out_trade_no"] = order.OutTradeNo m["nonce_str"] = order.NonceStr //m["transaction_id"] = order.TransactionID order.Sign = Sign(m, config.Key) var msg myth.HTTPMessage msg, err = postXML(PayHost+`/pay/orderquery`, order) if err == nil { err = msg.XML(&reply) } return }