Ver Fonte

wxcontext

yaotian há 8 anos atrás
pai
commit
30c1c76578

+ 2 - 2
examples/beego/beego.go

@@ -6,13 +6,13 @@ import (
 	"github.com/astaxie/beego"
 	"github.com/astaxie/beego/context"
 	"github.com/yaotian/gowechat"
-	gcontext "github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/mp/message"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 func hello(ctx *context.Context) {
 	//配置微信参数
-	config := gcontext.Config{
+	config := wxcontext.Config{
 		AppID:          "your app id",
 		AppSecret:      "your app secret",
 		Token:          "your token",

+ 2 - 2
examples/gin/gin.go

@@ -5,8 +5,8 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/yaotian/gowechat"
-	gcontext "github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/mp/message"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 func main() {
@@ -19,7 +19,7 @@ func main() {
 func hello(c *gin.Context) {
 
 	//配置微信参数
-	config := gcontext.Config{
+	config := wxcontext.Config{
 		AppID:          "your app id",
 		AppSecret:      "your app secret",
 		Token:          "your token",

+ 2 - 2
examples/http/http.go

@@ -5,14 +5,14 @@ import (
 	"net/http"
 
 	"github.com/yaotian/gowechat"
-	gcontext "github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/mp/message"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 func hello(rw http.ResponseWriter, req *http.Request) {
 
 	//配置微信参数
-	config := gcontext.Config{
+	config := wxcontext.Config{
 		AppID:          "your app id",
 		AppSecret:      "your app secret",
 		Token:          "your token",

+ 2 - 2
mch/base/base.go

@@ -7,12 +7,12 @@ import (
 	"io/ioutil"
 	"net/http"
 
-	"github.com/yaotian/gowechat/context"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 //MchBase base mch
 type MchBase struct {
-	*context.Context
+	*wxcontext.Context
 }
 
 //PostXML postXML

+ 1 - 1
mch/pay/pay.go

@@ -2,7 +2,7 @@ package pay
 
 import (
 	"github.com/yaotian/gowechat/mch/base"
-	"github.com/yaotian/gowechat/context"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 //Pay pay

+ 2 - 2
mch/paytool/cash_coupon.go

@@ -2,7 +2,7 @@ package paytool
 
 import (
 	"github.com/yaotian/gowechat/mch/base"
-	"github.com/yaotian/gowechat/context"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 //PayTool pay tool
@@ -11,7 +11,7 @@ type PayTool struct {
 }
 
 //NewPayTool 实例化
-func NewPayTool(context *context.Context) *PayTool {
+func NewPayTool(context *wxcontext.Context) *PayTool {
 	payT := new(PayTool)
 	payT.Context = context
 	return payT

+ 2 - 2
mp/base/base.go

@@ -6,13 +6,13 @@ import (
 	"net/http"
 	"strings"
 
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 //MpBase 微信公众平台,基本类
 type MpBase struct {
-	*context.Context
+	*wxcontext.Context
 }
 
 //HTTPGetWithAccessToken 微信公众平台中,自动加上access_token变量的GET调用,

+ 3 - 3
mp/jssdk/jssdk.go

@@ -5,15 +5,15 @@ import (
 	"fmt"
 	"time"
 
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
 
 // Js struct
 type Js struct {
-	*context.Context
+	*wxcontext.Context
 }
 
 // Config 返回给用户jssdk配置信息
@@ -33,7 +33,7 @@ type resTicket struct {
 }
 
 //NewJs init
-func NewJs(context *context.Context) *Js {
+func NewJs(context *wxcontext.Context) *Js {
 	js := new(Js)
 	js.Context = context
 	return js

+ 1 - 1
mp/material/material.go

@@ -5,7 +5,7 @@ import (
 	"errors"
 	"fmt"
 
-	"github.com/yaotian/gowechat/context"
+	"github.com/yaotian/gowechat/wxcontext"
 	"github.com/yaotian/gowechat/util"
 )
 

+ 2 - 2
mp/menu/menu.go

@@ -5,8 +5,8 @@ import (
 	"fmt"
 
 	"github.com/yaotian/gowechat/mp/base"
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 const (
@@ -113,7 +113,7 @@ type MatchRule struct {
 }
 
 //NewMenu 实例
-func NewMenu(context *context.Context) *Menu {
+func NewMenu(context *wxcontext.Context) *Menu {
 	menu := new(Menu)
 	menu.Context = context
 	return menu

+ 3 - 3
mp/oauth/oauth.go

@@ -6,8 +6,8 @@ import (
 	"net/http"
 	"net/url"
 
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 const (
@@ -20,11 +20,11 @@ const (
 
 //Oauth 保存用户授权信息
 type Oauth struct {
-	*context.Context
+	*wxcontext.Context
 }
 
 //NewOauth 实例化授权信息
-func NewOauth(context *context.Context) *Oauth {
+func NewOauth(context *wxcontext.Context) *Oauth {
 	auth := new(Oauth)
 	auth.Context = context
 	return auth

+ 3 - 3
mp/server/server.go

@@ -10,14 +10,14 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/mp/message"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 //Server struct
 type Server struct {
-	*context.Context
+	*wxcontext.Context
 
 	openID string
 
@@ -35,7 +35,7 @@ type Server struct {
 }
 
 //NewServer init
-func NewServer(context *context.Context) *Server {
+func NewServer(context *wxcontext.Context) *Server {
 	srv := new(Server)
 	srv.Context = context
 	return srv

+ 3 - 3
mp/template/template.go

@@ -4,8 +4,8 @@ import (
 	"encoding/json"
 	"fmt"
 
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 const (
@@ -14,11 +14,11 @@ const (
 
 //Template 模板消息
 type Template struct {
-	*context.Context
+	*wxcontext.Context
 }
 
 //NewTemplate 实例化
-func NewTemplate(context *context.Context) *Template {
+func NewTemplate(context *wxcontext.Context) *Template {
 	tpl := new(Template)
 	tpl.Context = context
 	return tpl

+ 2 - 2
mp/user/user.go

@@ -5,8 +5,8 @@ import (
 	"fmt"
 
 	"github.com/yaotian/gowechat/mp/base"
-	"github.com/yaotian/gowechat/context"
 	"github.com/yaotian/gowechat/util"
+	"github.com/yaotian/gowechat/wxcontext"
 )
 
 const (
@@ -19,7 +19,7 @@ type User struct {
 }
 
 //NewUser 实例化
-func NewUser(context *context.Context) *User {
+func NewUser(context *wxcontext.Context) *User {
 	user := new(User)
 	user.Context = context
 	return user

+ 23 - 3
wechat.go

@@ -1,3 +1,5 @@
+//GoWechat
+//
 package gowechat
 
 import (
@@ -5,7 +7,7 @@ import (
 	"sync"
 
 	"github.com/astaxie/beego/cache"
-	"github.com/yaotian/gowechat/context"
+	"github.com/yaotian/gowechat/wxcontext"
 	"github.com/yaotian/gowechat/util"
 )
 
@@ -64,6 +66,15 @@ func (wc *Wechat) Mp() (mp *MpMgr, err error) {
 
 //checkCfgBase 检查配置基本信息
 func (wc *Wechat) checkCfgBase() (err error) {
+	if wc.Context.AppID == "" {
+		return fmt.Errorf("%s", "配置中没有AppID")
+	}
+	if wc.Context.AppSecret == "" {
+		return fmt.Errorf("%s", "配置中没有AppSecret")
+	}
+	if wc.Context.Token == "" {
+		return fmt.Errorf("%s", "配置中没有Token")
+	}
 	return
 }
 
@@ -72,8 +83,17 @@ func (wc *Wechat) checkCfgMch() (err error) {
 	if err != nil {
 		return
 	}
-	if wc.Context.MchID == "" || wc.Context.MchAPIKey == "" {
-		return fmt.Errorf("%s", "配置中没有MchID或者MchAPIKey")
+	if wc.Context.MchID == "" {
+		return fmt.Errorf("%s", "配置中没有MchID")
+	}
+	if wc.Context.MchAPIKey == "" {
+		return fmt.Errorf("%s", "配置中没有MchAPIKey")
+	}
+	if wc.Context.SslCertFilePath == "" || wc.Context.SslCertContent == "" {
+		return fmt.Errorf("%s", "配置中没有SslCert")
+	}
+	if wc.Context.SslKeyFilePath == "" || wc.Context.SslKeyContent == "" {
+		return fmt.Errorf("%s", "配置中没有SslKey")
 	}
 	return
 }

+ 1 - 1
context/access_token.go

@@ -1,4 +1,4 @@
-package context
+package wxcontext
 
 import (
 	"encoding/json"

+ 1 - 1
context/config.go

@@ -1,4 +1,4 @@
-package context
+package wxcontext
 
 import "github.com/astaxie/beego/cache"
 

+ 1 - 1
context/context.go

@@ -1,4 +1,4 @@
-package context
+package wxcontext
 
 import (
 	"net/http"

+ 1 - 1
context/render.go

@@ -1,4 +1,4 @@
-package context
+package wxcontext
 
 import (
 	"encoding/xml"