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"` } // FormPayNotify notify type FormPayNotify struct { XMLName xml.Name `xml:"xml" json:"_,omitempty"` AppID string `form:"appid" xml:"appid"` Attach string `form:"attach" xml:"attach"` BankType string `form:"bank_type" xml:"bank_type"` CashFee int `form:"cash_fee" xml:"cash_fee"` FeeType string `form:"fee_type" xml:"fee_type"` MchID string `form:"mch_id" xml:"mch_id"` IsSubscribe string `form:"is_subscribe" xml:"is_subscribe"` NonceStr string `form:"nonce_str" xml:"nonce_str"` OpenID string `form:"openid" xml:"openid"` OutTradeNo string `form:"out_trade_no" xml:"out_trade_no"` ResultCode string `form:"result_code" xml:"result_code"` ReturnMsg string `form:"return_msg" xml:"return_msg"` ReturnCode string `form:"return_code" xml:"return_code"` ErrCodeDes string `form:"err_code_des" xml:"err_code_des"` ErrCode string `form:"err_code" xml:"err_code"` Sign string `form:"sign" xml:"sign"` TimeEnd string `form:"time_end" xml:"time_end"` TotalFee int `form:"total_fee" xml:"total_fee"` TradeType string `form:"trade_type" xml:"trade_type"` TransactionID string `form:"transaction_id" xml:"transaction_id"` ContractID string `form:"contract_id" xml:"contract_id"` } // 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 }