From 3d7d60644fc7a04e4f6f4e57150b6d774cc9e37a Mon Sep 17 00:00:00 2001 From: silenceper Date: Fri, 5 Jun 2020 14:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=B9=B3=E5=8F=B0=EF=BC=8C?= =?UTF-8?q?=E5=B0=86GetServer=E5=8D=95=E7=8B=AC=E6=8F=90=E5=8F=96=20(#273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加TODO:待完善接口 * 【模板消息】将message.DataItem改为message.TemplateDataItem * fix PKG.DEV * 增加一个 SetRedisPool 方法 * fix:模板消息推送增加一个TemplateMsgID * fix 开放平台服务端处理 --- openplatform/README.md | 19 ++++++++++++++----- openplatform/openplatform.go | 9 +++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/openplatform/README.md b/openplatform/README.md index 6bc1dd7..52252fa 100644 --- a/openplatform/README.md +++ b/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) + +``` \ No newline at end of file diff --git a/openplatform/openplatform.go b/openplatform/openplatform.go index c05b0b4..b0497f7 100644 --- a/openplatform/openplatform.go +++ b/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)