Browse Source

开发平台,将GetServer单独提取 (#273)

* 添加TODO:待完善接口

* 【模板消息】将message.DataItem改为message.TemplateDataItem

* fix PKG.DEV

* 增加一个 SetRedisPool 方法

* fix:模板消息推送增加一个TemplateMsgID

* fix 开放平台服务端处理
silenceper 6 years ago
parent
commit
3d7d60644f
2 changed files with 23 additions and 5 deletions
  1. 14 5
      openplatform/README.md
  2. 9 0
      openplatform/openplatform.go

+ 14 - 5
openplatform/README.md

@@ -5,6 +5,7 @@
 
 ## 快速入门
 
+### 服务端处理
 ```go
 wc := wechat.NewWechat()
 memory := cache.NewMemory()
@@ -16,13 +17,10 @@ cfg := &openplatform.Config{
     Cache: memory,
 }
 
-//授权的第三方公众号的appID
-appID := "xxx"
-openPlatform := wc.GetOpenPlatform(cfg)
-officialAccount := openPlatform.GetOfficialAccount(appID)
 
+openPlatform := wc.GetOpenPlatform(cfg)
 // 传入request和responseWriter
-server := officialAccount.GetServer(req, rw)
+server := openPlatform.GetServer(req, rw)
 //设置接收消息的处理方法
 server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
     if msg.InfoType == message.InfoTypeVerifyTicket {
@@ -51,4 +49,15 @@ if err != nil {
 }
 //发送回复的消息
 server.Send()
+
+
 ```
+### 待授权处理消息
+```go
+
+//授权的第三方公众号的appID
+appID := "xxx"
+openPlatform := wc.GetOpenPlatform(cfg)
+openPlatform.GetOfficialAccount(appID)
+
+```

+ 9 - 0
openplatform/openplatform.go

@@ -1,6 +1,9 @@
 package openplatform
 
 import (
+	"net/http"
+
+	"github.com/silenceper/wechat/v2/officialaccount/server"
 	"github.com/silenceper/wechat/v2/openplatform/account"
 	"github.com/silenceper/wechat/v2/openplatform/config"
 	"github.com/silenceper/wechat/v2/openplatform/context"
@@ -24,6 +27,12 @@ func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
 	return &OpenPlatform{ctx}
 }
 
+//GetServer get server
+func (openPlatform *OpenPlatform) GetServer(req *http.Request, writer http.ResponseWriter) *server.Server {
+	off := officialaccount.NewOfficialAccount(openPlatform.Context, "")
+	return off.GetServer(req, writer)
+}
+
 //GetOfficialAccount 公众号代处理
 func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount {
 	return officialaccount.NewOfficialAccount(openPlatform.Context, appID)