Documentation ¶
Overview ¶
WeiXin.go
注意其与autoreply.go共用一些相同的数据类定义,如: Article, Music, 以及一些常量.
推广支持
Index ¶
- Constants
- func GenHttpRouteKey(msgType string, msgEvent string) string
- func PKCS7Pad(message []byte, blocksize int) (padded []byte)
- func PadLength(slice_length, blocksize int) (padlen int)
- type Article
- type CDATAText
- type Customservice
- type EncryptResponseBody
- type EncryptedRequestHttpBody
- type KF_Info
- type KF_List
- type KF_Online_Info
- type MPNews
- type MaterialList
- type MaterialsCount
- type Menu
- type MenuButton
- type Music
- type Online_KF_List
- type PermanentNews
- type PermanentNews_Video
- type QrCode
- type RequestHandlerFunc
- type TemplateMessage
- type UserGroup
- type UserInfo
- type UserListResult
- type WeiXin
- func (wx *WeiXin) AddKFAccount(kf_account string, nickname string, password string) error
- func (wx *WeiXin) AddTemplate2MyMP(templateIdShort string) (string, error)
- func (wx *WeiXin) CreateMenu(menu *Menu) error
- func (wx *WeiXin) CreateQRCode(sceneId int64) (*response.Response, error)
- func (wx *WeiXin) CreateQRLimitCode(sceneId int64, expireSeconds int64) (*response.Response, error)
- func (wx *WeiXin) CreateUserGroup(groupName string) (*UserGroup, error)
- func (wx *WeiXin) DeleteGroup(groupId string) error
- func (wx *WeiXin) DeleteKFAccount(kf_account string, nickname string, password string) error
- func (wx *WeiXin) DeleteMassMessage(msgId string) (err error)
- func (wx *WeiXin) DeleteMenu() error
- func (wx *WeiXin) DeletePermanentMaterial(permanent_mediaId string) error
- func (wx *WeiXin) DownloadPermanentMaterial(mediaId string, writer io.Writer) (*PermanentNews_Video, error)
- func (wx *WeiXin) DownloadTmpMedia(mediaId string, mediaType string, writer io.Writer) ([]byte, error)
- func (wx *WeiXin) GetAppId() string
- func (wx *WeiXin) GetAppSecret() string
- func (wx *WeiXin) GetGroupList() ([]UserGroup, error)
- func (wx *WeiXin) GetKFList() (*KF_List, error)
- func (wx *WeiXin) GetMaterialCount() (*MaterialsCount, error)
- func (wx *WeiXin) GetMaterialsList(mediaType string, offset, count int) (*MaterialList, error)
- func (wx *WeiXin) GetMenu() (*Menu, error)
- func (wx *WeiXin) GetOnlineKFList() (*Online_KF_List, error)
- func (wx *WeiXin) GetQRCodeURL(ticket string) string
- func (wx *WeiXin) GetToken() string
- func (wx *WeiXin) GetUserInfo(openId string, lang string) (*UserInfo, error)
- func (wx *WeiXin) GetUserList(nextOpenId string) (*UserListResult, error)
- func (wx *WeiXin) HandleFunc(pattern string, handler RequestHandlerFunc)
- func (wx *WeiXin) LongURL2ShortURL(longURL string) (string, error)
- func (wx *WeiXin) MakeEncryptResponse(replyMsg []byte, timestamp, nonce string) ([]byte, error)
- func (wx *WeiXin) ModifyGroupName(groupId string, newName string) error
- func (wx *WeiXin) ModifyKFAccount(kf_account string, nickname string, password string) error
- func (wx *WeiXin) ModifyPermanentNews(mediaId string, index int, articles *PermanentNews) error
- func (wx *WeiXin) MoveUser2Group(openId string, groupId string) error
- func (wx *WeiXin) MoveUsers2Group(openId []string, groupId string) error
- func (wx *WeiXin) PostImage(touser string, mediaId string, kf_account string) error
- func (wx *WeiXin) PostMusic(touser string, music *Music, kf_account string) error
- func (wx *WeiXin) PostNews(touser string, articles []Article, kf_account string) error
- func (wx *WeiXin) PostText(touser string, text string, kf_account string) error
- func (wx *WeiXin) PostVideo(touser string, mediaId string, thumbMediaId string, title string, ...) error
- func (wx *WeiXin) PostVoice(touser string, mediaId string, kf_account string) error
- func (wx *WeiXin) PreviewImage(toUser string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) PreviewNews(toUser string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) PreviewText(toUser string, content string) (msgid string, err error)
- func (wx *WeiXin) PreviewVideo(toUser string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) PreviewVoice(toUser string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) PreviewWXCard(toUser string, cardId string, cardExt string) (msgid string, err error)
- func (wx *WeiXin) QueryMassMsgStatus(msgId string) (*response.Response, error)
- func (wx *WeiXin) ReplyImage(mediaId string, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) ReplyMusic(m *Music, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) ReplyNews(articles []Article, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) ReplyText(text string, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) ReplyVideo(mediaId string, title string, description string, ...) string
- func (wx *WeiXin) ReplyVoice(mediaId string, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) SendAll(url string, msg interface{}) (msgid string, err error)
- func (wx *WeiXin) SendImageByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendImageByOpenIDs(toUser []string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) SendNewsByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendNewsByOpenIDs(toUser []string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) SendTemplateMessage(msg *TemplateMessage) (int, error)
- func (wx *WeiXin) SendTextByGroupID(groupId string, content string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendTextByOpenIDs(toUser []string, content string) (msgid string, err error)
- func (wx *WeiXin) SendVideoByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendVideoByOpenIDs(toUser []string, mediaId string, title string, description string) (msgid string, err error)
- func (wx *WeiXin) SendVoiceByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendVoiceByOpenIDs(toUser []string, mediaId string) (msgid string, err error)
- func (wx *WeiXin) SendWXCardByGroupID(groupId string, cardId string, is_to_all bool) (msgid string, err error)
- func (wx *WeiXin) SendWXCardByOpenIDs(toUser []string, cardId string) (msgid string, err error)
- func (wx *WeiXin) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (wx *WeiXin) SetIndustry(industryId ...int64) error
- func (wx *WeiXin) TransferCustomerService(kfId string, originMsg *request.WeiXinRequest) string
- func (wx *WeiXin) UpdateRemark(openId string, remark string) error
- func (wx *WeiXin) UploadKFHeadImg(kf_account string, filename string, reader io.Reader) (string, error)
- func (wx *WeiXin) UploadNews(news []MPNews) (string, error)
- func (wx *WeiXin) UploadPermanentNews(news []PermanentNews) (string, error)
- func (wx *WeiXin) UploadPermanentNoVideoMaterial(mediaType string, filename string, reader io.Reader) (string, error)
- func (wx *WeiXin) UploadPermanentVideoMaterial(filename string, title string, introduction string, reader io.Reader) (string, error)
- func (wx *WeiXin) UploadTmpMedia(mediaType string, filename string, reader io.Reader) (string, error)
- func (wx *WeiXin) UploadVideoForMass(mediaId string, title string, description string) (string, error)
- func (wx *WeiXin) VerifyUserInWhichGroup(openId string) (string, error)
Constants ¶
const ( // media types MediaTypeImage = "image" MediaTypeVoice = "voice" MediaTypeVideo = "video" MediaTypeThumb = "thumb" )
const ( // request message types MsgTypeText = "text" MsgTypeImage = "image" MsgTypeVoice = "voice" MsgTypeShortVideo = "shortvideo" MsgTypeVideo = "video" MsgTypeLocation = "location" MsgTypeLink = "link" MsgTypeEvent = "event" // event types EventSubscribe = "subscribe" EventUnsubscribe = "unsubscribe" EventScan = "SCAN" EventLocation = "LOCATION" EventClick = "CLICK" EventView = "VIEW" )
const ( // button types ButtonTypeClick = "click" ButtonTypeView = "view" )
Variables ¶
This section is empty.
Functions ¶
func GenHttpRouteKey ¶
Types ¶
type Article ¶
type Article struct { Title string `json:"title"` Description string `json:"description"` PicUrl string `json:"picurl"` Url string `json:"url"` }
Use to reply news message
type Customservice ¶
type Customservice struct {
KF_account string `json:kf_account,omitempty`
}
用指定客服帐号发消息给客户.
type EncryptResponseBody ¶
type EncryptedRequestHttpBody ¶
type EncryptedRequestHttpBody struct { XMLName struct{} `xml:"xml" json:"-"` ToUserName string `xml:"ToUserName" json:"ToUserName"` EncryptedMsg string `xml:"Encrypt" json:"Encrypt"` }
安全模式, 微信服务器推送过来的 http body
type KF_Info ¶
type KF_Info struct { KF_account string `json:"kf_account"` KF_nick string `json:"kf_nick"` KF_id int `json:"kf_id"` KF_headimgurl string `json:"kf_headimgurl"` }
客服信息
type KF_Online_Info ¶
type MPNews ¶
type MPNews struct { Title string `json:"title"` ThumbMediaId string `json:"thumb_media_id"` Author string `json:"author,omitempty"` Digest string `json:"digest,omitempty"` ShowCoverPic int8 `json:"show_cover_pic"` Content string `json:"content"` ContentSourceUrl string `json:"content_source_url,omitempty"` }
高级群发接口 - 图文素材
type MaterialList ¶
type MaterialList struct { TotalCount uint `json:"total_count"` ItemCount uint `json:"item_count"` Item []struct { MediaId string `json:"media_id"` UpdateTime int64 `json:"update_time"` Name string `json:"name,omitempty"` Content struct { NewsItem []struct { Title string `json:"title,omitempty"` ThumbMediaId string `json:"thumb_media_id,omitempty"` ShowCoverPic int8 `json:"show_cover_pic"` Author string `json:"author,omitempty"` Digest string `json:"digest,omitempty"` Content string `json:"content"` Url string `json:"url,omitempty"` ContentSourceUrl string `json:"content_source_url,omitempty"` } `json:"news_item,omitempty"` } `json:"content,omitempty"` } `json:"item,omitempty"` }
素材列表
type MaterialsCount ¶
type MaterialsCount struct { VoiceCount uint32 `json:"voice_count"` VideoCount uint32 `json:"video_count"` ImageCount uint32 `json:"image_count"` NewsCount uint32 `json:"news_count"` }
素材数
type MenuButton ¶
type Music ¶
type Music struct { Title string `json:"title"` Description string `json:"description"` MusicUrl string `json:"musicurl"` HQMusicUrl string `json:"hqmusicurl"` ThumbMediaId string `json:"thumb_media_id"` }
Use to reply music message
type Online_KF_List ¶
type PermanentNews ¶
type PermanentNews struct { Title string `json:"title"` ThumbMediaId string `json:"thumb_media_id"` Author string `json:"author,omitempty"` Digest string `json:"digest,omitempty"` ShowCoverPic int8 `json:"show_cover_pic"` Content string `json:"content"` ContentSourceUrl string `json:"content_source_url,omitempty"` }
永久图文素材
type PermanentNews_Video ¶
type PermanentNews_Video struct { News_Item []PermanentNews `json:"news_item,omitempty"` //for video Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` DownUrl string `json:"down_url,omitempty"` }
用于下载永久图文和视频素材
type QrCode ¶
type QrCode struct { ExpireSeconds int64 `json:"expire_seconds,omitempty"` ActionName string `json:"action_name"` ActionInfo struct { Scene struct { SceneId int64 `json:"scene_id"` } `json:"scene"` } `json:"action_info"` }
二维码
type RequestHandlerFunc ¶
type RequestHandlerFunc func(wx *WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string)
http request handler.
type TemplateMessage ¶
type TemplateMessage struct { ToUser string `json:"touser"` // 必须, 接受者OpenID TemplateId string `json:"template_id"` // 必须, 模版ID URL string `json:"url,omitempty"` // 可选, 用户点击后跳转的URL,该URL必须处于开发者在公众平台网站中设置的域中 TopColor string `json:"topcolor,omitempty"` // 可选, 整个消息的颜色, 可以不设置 // 必须, JSON 格式的 []byte, 满足特定的模板需求 RawJSONData json.RawMessage `json:"data"` }
模板消息
type UserGroup ¶
type UserGroup struct { Id int64 `json:"id"` // 分组id, 由微信分配 Name string `json:"name"` // 分组名字, UTF8编码 UserCount int `json:"count"` // 分组内用户数量 }
用户分组
type UserInfo ¶
type UserInfo struct { Subscribe int8 `json:"subscribe"` //0:未关注该公众号,拉取不到其余信息; 1:为已关注. OpenId string `json:"openid"` // 用户的标识,对当前公众号唯一 Nickname string `json:"nickname"` // 用户的昵称 Sex int `json:"sex"` // 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 Language string `json:"language"` // 用户的语言,zh_CN,zh_TW,en City string `json:"city"` // 用户所在城市 Province string `json:"province"` // 用户所在省份 Country string `json:"country"` // 用户所在国家 // 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像), // 用户没有头像时该项为空 HeadImageURL string `json:"headimgurl,omitempty"` // 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间 SubscribeTime int64 `json:"subscribe_time"` // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。 UnionId string `json:"unionid,omitempty"` // 备注名 Remark string `json:"remark,omitempty"` // 组id Groupid string `json:"groupid,omitempty"` }
用户基本信息, 非OAuth
type UserListResult ¶
type UserListResult struct { TotalCount int `json:"total"` // 关注该公众账号的总用户数 GotCount int `json:"count"` // 拉取的OPENID个数,最大值为10000 Data struct { OpenId []string `json:"openid,omitempty"` } `json:"data"` // 列表数据,OPENID的列表 // 拉取列表的后一个用户的OPENID, 如果 next_openid == "" 则表示没有了用户数据 NextOpenId string `json:"next_openid"` }
获取关注者列表返回的数据结构
type WeiXin ¶
type WeiXin struct {
// contains filtered or unexported fields
}
func (*WeiXin) AddKFAccount ¶
客服帐号管理
func (*WeiXin) AddTemplate2MyMP ¶
从行业模板库选择模板添加到账号后台, 并返回模板id.
templateIdShort: 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式.
func (*WeiXin) CreateQRCode ¶
二维码 创建永久二维码
func (*WeiXin) CreateQRLimitCode ¶
创建临时二维码
func (*WeiXin) CreateUserGroup ¶
用户管理 1. 创建分组 一个公众账号,最多支持创建100个分组。
func (*WeiXin) DeleteKFAccount ¶
func (*WeiXin) DeleteMassMessage ¶
删除群发
func (*WeiXin) DeleteMenu ¶
func (*WeiXin) DeletePermanentMaterial ¶
7.删除永久素材
func (*WeiXin) DownloadPermanentMaterial ¶
func (wx *WeiXin) DownloadPermanentMaterial(mediaId string, writer io.Writer) (*PermanentNews_Video, error)
3. 获取永久素材 注意: 图文, 视频, 这两种类型只会返回json串, 其它类型素材则以文件流形式直接写入io.Writer.
func (*WeiXin) DownloadTmpMedia ¶
func (wx *WeiXin) DownloadTmpMedia(mediaId string, mediaType string, writer io.Writer) ([]byte, error)
2.获取临时素材 os.Create中须指定形如: xxx.jpg的文件.
func (*WeiXin) GetAppSecret ¶
func (*WeiXin) GetMaterialCount ¶
func (wx *WeiXin) GetMaterialCount() (*MaterialsCount, error)
素材总数
func (*WeiXin) GetMaterialsList ¶
func (wx *WeiXin) GetMaterialsList(mediaType string, offset, count int) (*MaterialList, error)
获取素材列表
func (*WeiXin) GetOnlineKFList ¶
func (wx *WeiXin) GetOnlineKFList() (*Online_KF_List, error)
获取在线客服列表
func (*WeiXin) GetUserInfo ¶
9.获取用户基本信息 lang = ["zh_CN", "zh_TW", "en"]
func (*WeiXin) GetUserList ¶
func (wx *WeiXin) GetUserList(nextOpenId string) (*UserListResult, error)
func (*WeiXin) HandleFunc ¶
func (wx *WeiXin) HandleFunc(pattern string, handler RequestHandlerFunc)
register request handler
func (*WeiXin) LongURL2ShortURL ¶
长链接转为短链接
func (*WeiXin) MakeEncryptResponse ¶
func (*WeiXin) ModifyGroupName ¶
4. 修改分组名
func (*WeiXin) ModifyKFAccount ¶
func (*WeiXin) ModifyPermanentNews ¶
func (wx *WeiXin) ModifyPermanentNews(mediaId string, index int, articles *PermanentNews) error
7.修改永久图文素材
func (*WeiXin) MoveUser2Group ¶
5. 移动用户分组
func (*WeiXin) MoveUsers2Group ¶
6. 批量移动用户分组 openid个数<=50
func (*WeiXin) PreviewImage ¶
func (*WeiXin) PreviewNews ¶
func (*WeiXin) PreviewText ¶
预览消息发送接口
func (*WeiXin) PreviewVideo ¶
func (*WeiXin) PreviewVoice ¶
func (*WeiXin) PreviewWXCard ¶
func (*WeiXin) QueryMassMsgStatus ¶
查询群发消息发送状态
func (*WeiXin) ReplyImage ¶
func (wx *WeiXin) ReplyImage(mediaId string, originMsg *request.WeiXinRequest) string
func (*WeiXin) ReplyMusic ¶
func (wx *WeiXin) ReplyMusic(m *Music, originMsg *request.WeiXinRequest) string
func (*WeiXin) ReplyNews ¶
func (wx *WeiXin) ReplyNews(articles []Article, originMsg *request.WeiXinRequest) string
func (*WeiXin) ReplyText ¶
func (wx *WeiXin) ReplyText(text string, originMsg *request.WeiXinRequest) string
to reply normal weixin msg start
func (*WeiXin) ReplyVideo ¶
func (*WeiXin) ReplyVoice ¶
func (wx *WeiXin) ReplyVoice(mediaId string, originMsg *request.WeiXinRequest) string
func (*WeiXin) SendImageByGroupID ¶
func (*WeiXin) SendImageByOpenIDs ¶
func (*WeiXin) SendNewsByGroupID ¶
func (*WeiXin) SendNewsByOpenIDs ¶
根据OpenID列表群发[订阅号不可用, 服务号认证后可用]
func (*WeiXin) SendTemplateMessage ¶
func (wx *WeiXin) SendTemplateMessage(msg *TemplateMessage) (int, error)
发送模板消息
func (*WeiXin) SendTextByGroupID ¶
func (wx *WeiXin) SendTextByGroupID(groupId string, content string, is_to_all bool) (msgid string, err error)
根据分组群发消息
func (*WeiXin) SendTextByOpenIDs ¶
func (*WeiXin) SendVideoByGroupID ¶
func (*WeiXin) SendVideoByOpenIDs ¶
func (*WeiXin) SendVoiceByGroupID ¶
func (*WeiXin) SendVoiceByOpenIDs ¶
func (*WeiXin) SendWXCardByGroupID ¶
func (*WeiXin) SendWXCardByOpenIDs ¶
func (*WeiXin) ServeHTTP ¶
func (wx *WeiXin) ServeHTTP(w http.ResponseWriter, r *http.Request)
route http request to specified handler
func (*WeiXin) TransferCustomerService ¶
func (wx *WeiXin) TransferCustomerService(kfId string, originMsg *request.WeiXinRequest) string
发送到多客服
func (*WeiXin) UpdateRemark ¶
8.设置用户备注名
func (*WeiXin) UploadKFHeadImg ¶
func (wx *WeiXin) UploadKFHeadImg(kf_account string, filename string, reader io.Reader) (string, error)
设置客服帐号的头像
func (*WeiXin) UploadNews ¶
上传图文素材,为高级群发接口
func (*WeiXin) UploadPermanentNews ¶
func (wx *WeiXin) UploadPermanentNews(news []PermanentNews) (string, error)
4.新增永久图文素村
func (*WeiXin) UploadPermanentNoVideoMaterial ¶
func (wx *WeiXin) UploadPermanentNoVideoMaterial(mediaType string, filename string, reader io.Reader) (string, error)
6.上传非视频类永久素材
func (*WeiXin) UploadPermanentVideoMaterial ¶
func (wx *WeiXin) UploadPermanentVideoMaterial(filename string, title string, introduction string, reader io.Reader) (string, error)
5.新增永久视频素材
func (*WeiXin) UploadTmpMedia ¶
func (wx *WeiXin) UploadTmpMedia(mediaType string, filename string, reader io.Reader) (string, error)
素村管理 1上传临时素材, 3 days 参数filename必须形如: xxx.jpg等, 扩展名必须为小写. os.Open打开文件时,扩展名必须为小写,否则找到不文件.