|
| 1 | +// Copyright 2020 FastWeGo |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +// Package customer_message 客服消息 |
| 16 | +package customer_message |
| 17 | + |
| 18 | +import ( |
| 19 | +"bytes" |
| 20 | +"net/url" |
| 21 | + |
| 22 | +"github.com/fastwego/miniprogram" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | +apiGetTempMedia = "/cgi-bin/media/get" |
| 27 | +apiSend = "/cgi-bin/message/custom/send" |
| 28 | +apiSetTyping = "/cgi-bin/message/custom/typing" |
| 29 | +apiUploadTempMedia = "/cgi-bin/media/upload" |
| 30 | +) |
| 31 | + |
| 32 | +/* |
| 33 | +获取客服消息内的临时素材。即下载临时的多媒体文件。目前小程序仅支持下载图片文件。 |
| 34 | +
|
| 35 | +
|
| 36 | +
|
| 37 | +See: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.getTempMedia.html |
| 38 | +
|
| 39 | +GET https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID |
| 40 | +*/ |
| 41 | +func GetTempMedia(ctx *miniprogram.Miniprogram, params url.Values) (resp []byte, err error) { |
| 42 | +return ctx.Client.HTTPGet(apiGetTempMedia + "?" + params.Encode()) |
| 43 | +} |
| 44 | + |
| 45 | +/* |
| 46 | +发送客服消息给用户。详细规则见 发送客服消息 |
| 47 | +
|
| 48 | +
|
| 49 | +
|
| 50 | +See: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.send.html |
| 51 | +
|
| 52 | +POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN |
| 53 | +*/ |
| 54 | +func Send(ctx *miniprogram.Miniprogram, payload []byte) (resp []byte, err error) { |
| 55 | +return ctx.Client.HTTPPost(apiSend, bytes.NewReader(payload), "application/json;charset=utf-8") |
| 56 | +} |
| 57 | + |
| 58 | +/* |
| 59 | +下发客服当前输入状态给用户。详见 客服消息输入状态 |
| 60 | +
|
| 61 | +
|
| 62 | +
|
| 63 | +See: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.setTyping.html |
| 64 | +
|
| 65 | +POST https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN |
| 66 | +*/ |
| 67 | +func SetTyping(ctx *miniprogram.Miniprogram, payload []byte) (resp []byte, err error) { |
| 68 | +return ctx.Client.HTTPPost(apiSetTyping, bytes.NewReader(payload), "application/json;charset=utf-8") |
| 69 | +} |
| 70 | + |
| 71 | +/* |
| 72 | +把媒体文件上传到微信服务器。目前仅支持图片。用于发送客服消息或被动回复用户消息。 |
| 73 | +
|
| 74 | +
|
| 75 | +
|
| 76 | +See: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.uploadTempMedia.html |
| 77 | +
|
| 78 | +POST https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE |
| 79 | +*/ |
| 80 | +func UploadTempMedia(ctx *miniprogram.Miniprogram, payload []byte, params url.Values) (resp []byte, err error) { |
| 81 | +return ctx.Client.HTTPPost(apiUploadTempMedia+"?"+params.Encode(), bytes.NewReader(payload), "application/json;charset=utf-8") |
| 82 | +} |
0 commit comments