yaotian 8 سال پیش
والد
کامیت
33a2c57a6c
5فایلهای تغییر یافته به همراه62 افزوده شده و 17 حذف شده
  1. 1 0
      docs/REAME.md
  2. 24 0
      mch/pay/helper.go
  3. 30 17
      mch/pay/pay.go
  4. 1 0
      mp/README.md
  5. 6 0
      wechat.go

+ 1 - 0
docs/REAME.md

@@ -0,0 +1 @@
+read me

+ 24 - 0
mch/pay/helper.go

@@ -0,0 +1,24 @@
+package pay
+
+import "fmt"
+
+const (
+	ReturnCodeSuccess = "SUCCESS"
+	ReturnCodeFail    = "FAIL"
+)
+
+const (
+	ResultCodeSuccess = "SUCCESS"
+	ResultCodeFail    = "FAIL"
+)
+
+//Error error
+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"`
+}
+
+func (e *Error) Error() string {
+	return fmt.Sprintf("return_code: %q, return_msg: %q", e.ReturnCode, e.ReturnMsg)
+}

+ 30 - 17
mch/pay/pay.go

@@ -11,29 +11,42 @@ import (
 	"github.com/yaotian/gowechat/server/context"
 	"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
 //PostXML postXML

+ 1 - 0
mp/README.md

@@ -1,2 +1,3 @@
 # 微信公众平台(订阅号,服务号) 
 # 微信公众平台(订阅号,服务号) 
 
 
+[官方文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432)

+ 6 - 0
wechat.go

@@ -5,6 +5,7 @@ import (
 	"sync"
 	"sync"
 
 
 	"github.com/astaxie/beego/cache"
 	"github.com/astaxie/beego/cache"
+	"github.com/yaotian/gowechat/mch/pay"
 	"github.com/yaotian/gowechat/mp/jssdk"
 	"github.com/yaotian/gowechat/mp/jssdk"
 	"github.com/yaotian/gowechat/mp/material"
 	"github.com/yaotian/gowechat/mp/material"
 	"github.com/yaotian/gowechat/mp/menu"
 	"github.com/yaotian/gowechat/mp/menu"
@@ -117,3 +118,8 @@ func (wc *Wechat) GetUser() *user.User {
 func (wc *Wechat) GetTemplate() *template.Template {
 func (wc *Wechat) GetTemplate() *template.Template {
 	return template.NewTemplate(wc.Context)
 	return template.NewTemplate(wc.Context)
 }
 }
+
+//GetPay get pay
+func (wc *Wechat) GetPay() *pay.Pay {
+	return pay.NewPay(wc.Context)
+}