1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-10 07:42:26 +08:00

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

* 添加TODO:待完善接口

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

* fix PKG.DEV

* 增加一个 SetRedisPool 方法

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

* fix 开放平台服务端处理
This commit is contained in:
silenceper
2020-06-05 14:21:49 +08:00
committed by GitHub
parent 5d9705ddc8
commit 3d7d60644f
2 changed files with 23 additions and 5 deletions

View File

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

View File

@@ -1,6 +1,9 @@
package openplatform package openplatform
import ( import (
"net/http"
"github.com/silenceper/wechat/v2/officialaccount/server"
"github.com/silenceper/wechat/v2/openplatform/account" "github.com/silenceper/wechat/v2/openplatform/account"
"github.com/silenceper/wechat/v2/openplatform/config" "github.com/silenceper/wechat/v2/openplatform/config"
"github.com/silenceper/wechat/v2/openplatform/context" "github.com/silenceper/wechat/v2/openplatform/context"
@@ -24,6 +27,12 @@ func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
return &OpenPlatform{ctx} 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 公众号代处理 //GetOfficialAccount 公众号代处理
func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount { func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount {
return officialaccount.NewOfficialAccount(openPlatform.Context, appID) return officialaccount.NewOfficialAccount(openPlatform.Context, appID)