From f8ab59260693c25d9caeb0a7ea892826fcc2e4a3 Mon Sep 17 00:00:00 2001 From: WhisperRain <2516435583@qq.com> Date: Tue, 1 Oct 2019 20:11:57 +0800 Subject: [PATCH 1/8] add(customer message)Add module to send customer message --- message/customer_message.go | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 message/customer_message.go diff --git a/message/customer_message.go b/message/customer_message.go new file mode 100644 index 0000000..e697d13 --- /dev/null +++ b/message/customer_message.go @@ -0,0 +1,160 @@ +package message + +import ( + "encoding/json" + "fmt" + "github.com/silenceper/wechat/util" + "github.com/silenceper/wechat/context" +) + +const ( + customerSendMessage = "https://api.weixin.qq.com/cgi-bin/message/custom/send" +) + +//Manager 消息管理者,可以发送消息 +type Manager struct { + *context.Context +} + +//NewMessageManager 实例化消息管理者 +func NewMessageManager(context *context.Context) *Manager { + return &Manager{ + context, + } +} + +//CustomerMessage 客服消息 +type CustomerMessage struct { + ToUser string `json:"touser"` //接受者OpenID + Msgtype MsgType `json:"msgtype"` //客服消息类型 + Text *MediaText `json:"text,omitempty"` //可选 + Image *MediaResource `json:"image,omitempty"` //可选 + Voice *MediaResource `json:"voice,omitempty"` //可选 + Video *MediaVideo `json:"video,omitempty"` //可选 + Music *MediaMusic `json:"music,omitempty"` //可选 + News *MediaNews `json:"news,omitempty"` //可选 + Mpnews *MediaResource `json:"mpnews,omitempty"` //可选 + Wxcard *MediaWxcard `json:"wxcard,omitempty"` //可选 + Msgmenu *MediaMsgmenu `json:"msgmenu,omitempty"` //可选 + Miniprogrampage *MediaMiniprogrampage `json:"miniprogrampage,omitempty"` //可选 +} + +//NewCustomerTextMessage 文本消息结构体构造方法 +func NewCustomerTextMessage(toUser, text string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeText, + Text: &MediaText{ + text, + }, + } +} + +//NewCustomerImgMessage 图片消息的构造方法 +func NewCustomerImgMessage(toUser, mediaID string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeImage, + Image: &MediaResource{ + mediaID, + }, + } +} + +//NewCustomerVoiceMessage 语音消息的构造方法 +func NewCustomerVoiceMessage(toUser, mediaID string) *CustomerMessage { + return &CustomerMessage{ + ToUser: toUser, + Msgtype: MsgTypeVoice, + Voice: &MediaResource{ + mediaID, + }, + } +} + +//MediaText 文本消息的文字 +type MediaText struct { + Content string `json:"content"` +} + +//MediaResource 消息使用的永久素材id +type MediaResource struct { + MediaID string `json:"media_id"` +} + +//MediaVideo 视频消息包含的内容 +type MediaVideo struct { + MediaID string `json:"media_id"` + ThumbMediaID string `json:"thumb_media_id"` + Title string `json:"title"` + Description string `json:"description"` +} + +//MediaMusic 音乐消息包括的内容 +type MediaMusic struct { + Title string `json:"title"` + Description string `json:"description"` + Musicurl string `json:"musicurl"` + Hqmusicurl string `json:"hqmusicurl"` + ThumbMediaID string `json:"thumb_media_id"` +} + +//MediaNews 图文消息的内容 +type MediaNews struct { + Articles []MediaArticles `json:"articles"` +} + +//MediaArticles 图文消息的内容的文章列表中的单独一条 +type MediaArticles struct { + Title string `json:"title"` + Description string `json:"description"` + URL string `json:"url"` + Picurl string `json:"picurl"` +} + +//MediaMsgmenu 菜单消息的内容 +type MediaMsgmenu struct { + HeadContent string `json:"head_content"` + List []MsgmenuItem `json:"list"` + TailContent string `json:"tail_content"` +} + +//MsgmenuItem 菜单消息的菜单按钮 +type MsgmenuItem struct { + ID string `json:"id"` + Content string `json:"content"` +} + +//MediaWxcard 卡券的id +type MediaWxcard struct { + CardID string `json:"card_id"` +} + +//MediaMiniprogrampage 小程序消息 +type MediaMiniprogrampage struct { + Title string `json:"title"` + Appid string `json:"appid"` + Pagepath string `json:"pagepath"` + ThumbMediaID string `json:"thumb_media_id"` +} + +//Send 发送客服消息 +func (manager *Manager) Send(msg *CustomerMessage) error { + accessToken,err:=manager.Context.GetAccessToken() + if err!=nil { + return err + } + uri := fmt.Sprintf("%s?access_token=%s", customerSendMessage, accessToken) + response, err := util.PostJSON(uri, msg) + var result util.CommonError + err = json.Unmarshal(response, &result) + if err != nil { + return err + } + if result.ErrCode != 0 { + err = fmt.Errorf("customer msg send error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg) + return err + } + + return nil +} From 87470f143d03518f5c467d8b7bc3cb4953077601 Mon Sep 17 00:00:00 2001 From: quxiaolong Date: Tue, 15 Oct 2019 11:54:40 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E7=9B=B8=E5=85=B3=20message=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message/message.go | 8 ++++++++ server/server.go | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/message/message.go b/message/message.go index 366bfe8..8c7ae2a 100644 --- a/message/message.go +++ b/message/message.go @@ -63,6 +63,8 @@ const ( EventLocationSelect = "location_select" //EventTemplateSendJobFinish 发送模板消息推送通知 EventTemplateSendJobFinish = "TEMPLATESENDJOBFINISH" + //EventWxaMediaCheck 异步校验图片/音频是否含有违法违规内容推送事件 + EventWxaMediaCheck = "wxa_media_check" ) const ( @@ -144,6 +146,12 @@ type MixMessage struct { OuterStr string `xml:"OuterStr"` IsRestoreMemberCard int32 `xml:"IsRestoreMemberCard"` UnionID string `xml:"UnionId"` + + // 内容审核相关 + IsRisky bool `xml:"isrisky"` + ExtraInfoJSON string `xml:"extra_info_json"` + TraceID string `xml:"trace_id"` + StatusCode int `xml:"status_code"` } //EventPic 发图事件推送 diff --git a/server/server.go b/server/server.go index ad3c8ca..e4a4979 100644 --- a/server/server.go +++ b/server/server.go @@ -65,7 +65,9 @@ func (srv *Server) Serve() error { } //debug - //fmt.Println("request msg = ", string(srv.requestRawXMLMsg)) + if srv.debug { + fmt.Println("request msg = ", string(srv.requestRawXMLMsg)) + } return srv.buildResponse(response) } From 7bde39a634031dca306d506bbf8e62e92ca7939b Mon Sep 17 00:00:00 2001 From: kaiiak Date: Mon, 28 Oct 2019 00:53:56 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=B0=B8=E4=B9=85=E8=A7=86=E9=A2=91=E7=B4=A0=E6=9D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- material/material.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/material/material.go b/material/material.go index f4f1dfb..cc95d5d 100644 --- a/material/material.go +++ b/material/material.go @@ -138,11 +138,11 @@ func (material *Material) AddVideo(filename, title, introduction string) (mediaI fields := []util.MultipartFormField{ { IsFile: true, - Fieldname: "video", + Fieldname: "media", Filename: filename, }, { - IsFile: true, + IsFile: false, Fieldname: "description", Value: fieldValue, }, From 1fc4cc70ecde3a05c3c059dc83c3795ff9bffd8f Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:45:22 +0800 Subject: [PATCH 4/8] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b6a498a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: https://silenceper.com/img/wechat-pay.jpeg From 55615762eb59d6b94dbe9b03ded51094e9165c4c Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:48:27 +0800 Subject: [PATCH 5/8] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. From 13facb6df82d78a9a590c262aa7598d92fe24fa4 Mon Sep 17 00:00:00 2001 From: silenceper Date: Tue, 5 Nov 2019 14:50:03 +0800 Subject: [PATCH 6/8] Create ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..5d6e38c --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,2 @@ +## 问题及现象 +