|
|
@@ -11,29 +11,42 @@ import (
|
|
|
"github.com/yaotian/gowechat/server/context"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- ReturnCodeSuccess = "SUCCESS"
|
|
|
- ReturnCodeFail = "FAIL"
|
|
|
-)
|
|
|
+//Pay pay
|
|
|
+type Pay struct {
|
|
|
+ *context.Context
|
|
|
+}
|
|
|
|
|
|
-const (
|
|
|
- ResultCodeSuccess = "SUCCESS"
|
|
|
- ResultCodeFail = "FAIL"
|
|
|
-)
|
|
|
+//NewPay 实例化
|
|
|
+func NewPay(context *context.Context) *Pay {
|
|
|
+ pay := new(Pay)
|
|
|
+ pay.Context = context
|
|
|
+ return pay
|
|
|
+}
|
|
|
|
|
|
-type Error struct {
|
|
|
- XMLName struct{} `xml:"xml" json:"-"`
|
|
|
- ReturnCode string `xml:"return_code" json:"return_code"`
|
|
|
- ReturnMsg string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
|
|
|
+// UnifiedOrder 统一下单.
|
|
|
+func (c *Pay) UnifiedOrder(req map[string]string) (resp map[string]string, err error) {
|
|
|
+ return c.PostXML("https://api.mch.weixin.qq.com/pay/unifiedorder", req, false)
|
|
|
}
|
|
|
|
|
|
-func (e *Error) Error() string {
|
|
|
- return fmt.Sprintf("return_code: %q, return_msg: %q", e.ReturnCode, e.ReturnMsg)
|
|
|
+// 查询订单.
|
|
|
+func (c *Pay) OrderQuery(req map[string]string) (resp map[string]string, err error) {
|
|
|
+ return c.PostXML("https://api.mch.weixin.qq.com/pay/orderquery", req, false)
|
|
|
}
|
|
|
|
|
|
-//Pay pay
|
|
|
-type Pay struct {
|
|
|
- *context.Context
|
|
|
+// 关闭订单.
|
|
|
+func (c *Pay) CloseOrder(req map[string]string) (resp map[string]string, err error) {
|
|
|
+ return c.PostXML("https://api.mch.weixin.qq.com/pay/closeorder", req, false)
|
|
|
+}
|
|
|
+
|
|
|
+// 申请退款.
|
|
|
+// NOTE: 请求需要双向证书.
|
|
|
+func (c *Pay) Refund(req map[string]string) (resp map[string]string, err error) {
|
|
|
+ return c.PostXML("https://api.mch.weixin.qq.com/secapi/pay/refund", req, true)
|
|
|
+}
|
|
|
+
|
|
|
+// 查询退款.
|
|
|
+func (c *Pay) RefundQuery(req map[string]string) (resp map[string]string, err error) {
|
|
|
+ return c.PostXML("https://api.mch.weixin.qq.com/pay/refundquery", req, false)
|
|
|
}
|
|
|
|
|
|
//PostXML postXML
|