mp

package
v0.0.0-...-49a96a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: MIT Imports: 22 Imported by: 4

Documentation

Overview

WeiXin.go

注意其与autoreply.go共用一些相同的数据类定义,如: Article, Music, 以及一些常量.

推广支持

Index

Constants

View Source
const (

	// media types
	MediaTypeImage = "image"
	MediaTypeVoice = "voice"
	MediaTypeVideo = "video"
	MediaTypeThumb = "thumb"
)
View Source
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"
)
View Source
const (

	// button types
	ButtonTypeClick = "click"
	ButtonTypeView  = "view"
)

Variables

This section is empty.

Functions

func GenHttpRouteKey

func GenHttpRouteKey(msgType string, msgEvent string) string

func PKCS7Pad

func PKCS7Pad(message []byte, blocksize int) (padded []byte)

from github.com/vgorin/cryptogo

func PadLength

func PadLength(slice_length, blocksize int) (padlen int)

PadLength calculates padding length, from github.com/vgorin/cryptogo

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 CDATAText

type CDATAText struct {
	Text string `xml:",innerxml"`
}

type Customservice

type Customservice struct {
	KF_account string `json:kf_account,omitempty`
}

用指定客服帐号发消息给客户.

type EncryptResponseBody

type EncryptResponseBody struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      CDATAText
	MsgSignature CDATAText
	TimeStamp    string
	Nonce        CDATAText
}

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_List

type KF_List struct {
	response.Response
	KF_list []KF_Info `json:"kf_list"`
}

type KF_Online_Info

type KF_Online_Info struct {
	KF_account string `json:"kf_account"`
	KF_id      int    `json:"kf_id"`

	AutoAccept   int `json:"auto_accept"`
	AcceptedCase int `json:"accepted_case"`
	// contains filtered or unexported fields
}

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 Menu struct {
	Buttons []MenuButton `json:"button,omitempty"`
}

自定义菜单

type MenuButton struct {
	Name       string       `json:"name"`
	Type       string       `json:"type,omitempty"`
	Key        string       `json:"key,omitempty"`
	Url        string       `json:"url,omitempty"`
	MediaId    string       `json:"media_id,omitempty"`
	SubButtons []MenuButton `json:"sub_button,omitempty"`
}

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 Online_KF_List struct {
	response.Response
	// contains filtered or unexported fields
}

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 New

func New(token string, appid string, secret string, currentEncodingAESKey string, lastEncodingAESKey string) *WeiXin

func (*WeiXin) AddKFAccount

func (wx *WeiXin) AddKFAccount(kf_account string, nickname string, password string) error

客服帐号管理

func (*WeiXin) AddTemplate2MyMP

func (wx *WeiXin) AddTemplate2MyMP(templateIdShort string) (string, error)

从行业模板库选择模板添加到账号后台, 并返回模板id.

templateIdShort: 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式.

func (*WeiXin) CreateMenu

func (wx *WeiXin) CreateMenu(menu *Menu) error

自定义菜单

func (*WeiXin) CreateQRCode

func (wx *WeiXin) CreateQRCode(sceneId int64) (*response.Response, error)

二维码 创建永久二维码

func (*WeiXin) CreateQRLimitCode

func (wx *WeiXin) CreateQRLimitCode(sceneId int64, expireSeconds int64) (*response.Response, error)

创建临时二维码

func (*WeiXin) CreateUserGroup

func (wx *WeiXin) CreateUserGroup(groupName string) (*UserGroup, error)

用户管理 1. 创建分组 一个公众账号,最多支持创建100个分组。

func (*WeiXin) DeleteGroup

func (wx *WeiXin) DeleteGroup(groupId string) error

7.删除分组

func (*WeiXin) DeleteKFAccount

func (wx *WeiXin) DeleteKFAccount(kf_account string, nickname string, password string) error

func (*WeiXin) DeleteMassMessage

func (wx *WeiXin) DeleteMassMessage(msgId string) (err error)

删除群发

func (*WeiXin) DeleteMenu

func (wx *WeiXin) DeleteMenu() error

func (*WeiXin) DeletePermanentMaterial

func (wx *WeiXin) DeletePermanentMaterial(permanent_mediaId string) error

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) GetAppId

func (wx *WeiXin) GetAppId() string

func (*WeiXin) GetAppSecret

func (wx *WeiXin) GetAppSecret() string

func (*WeiXin) GetGroupList

func (wx *WeiXin) GetGroupList() ([]UserGroup, error)

2. 获取分组列表

func (*WeiXin) GetKFList

func (wx *WeiXin) GetKFList() (*KF_List, error)

获取客服列表

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) GetMenu

func (wx *WeiXin) GetMenu() (*Menu, error)

func (*WeiXin) GetOnlineKFList

func (wx *WeiXin) GetOnlineKFList() (*Online_KF_List, error)

获取在线客服列表

func (*WeiXin) GetQRCodeURL

func (wx *WeiXin) GetQRCodeURL(ticket string) string

二维码图片的url

func (*WeiXin) GetToken

func (wx *WeiXin) GetToken() string

func (*WeiXin) GetUserInfo

func (wx *WeiXin) GetUserInfo(openId string, lang string) (*UserInfo, error)

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 (wx *WeiXin) LongURL2ShortURL(longURL string) (string, error)

长链接转为短链接

func (*WeiXin) MakeEncryptResponse

func (wx *WeiXin) MakeEncryptResponse(replyMsg []byte, timestamp, nonce string) ([]byte, error)

func (*WeiXin) ModifyGroupName

func (wx *WeiXin) ModifyGroupName(groupId string, newName string) error

4. 修改分组名

func (*WeiXin) ModifyKFAccount

func (wx *WeiXin) ModifyKFAccount(kf_account string, nickname string, password string) error

func (*WeiXin) ModifyPermanentNews

func (wx *WeiXin) ModifyPermanentNews(mediaId string, index int, articles *PermanentNews) error

7.修改永久图文素材

func (*WeiXin) MoveUser2Group

func (wx *WeiXin) MoveUser2Group(openId string, groupId string) error

5. 移动用户分组

func (*WeiXin) MoveUsers2Group

func (wx *WeiXin) MoveUsers2Group(openId []string, groupId string) error

6. 批量移动用户分组 openid个数<=50

func (*WeiXin) PostImage

func (wx *WeiXin) PostImage(touser string, mediaId string, kf_account string) error

func (*WeiXin) PostMusic

func (wx *WeiXin) PostMusic(touser string, music *Music, kf_account string) error

func (*WeiXin) PostNews

func (wx *WeiXin) PostNews(touser string, articles []Article, kf_account string) error

func (*WeiXin) PostText

func (wx *WeiXin) PostText(touser string, text string, kf_account string) error

客服接口 - 发送消息

func (*WeiXin) PostVideo

func (wx *WeiXin) PostVideo(touser string, mediaId string, thumbMediaId string, title string, description string, kf_account string) error

func (*WeiXin) PostVoice

func (wx *WeiXin) PostVoice(touser string, mediaId string, kf_account string) error

func (*WeiXin) PreviewImage

func (wx *WeiXin) PreviewImage(toUser string, mediaId string) (msgid string, err error)

func (*WeiXin) PreviewNews

func (wx *WeiXin) PreviewNews(toUser string, mediaId string) (msgid string, err error)

func (*WeiXin) PreviewText

func (wx *WeiXin) PreviewText(toUser string, content string) (msgid string, err error)

预览消息发送接口

func (*WeiXin) PreviewVideo

func (wx *WeiXin) PreviewVideo(toUser string, mediaId string) (msgid string, err error)

func (*WeiXin) PreviewVoice

func (wx *WeiXin) PreviewVoice(toUser string, mediaId string) (msgid string, err error)

func (*WeiXin) PreviewWXCard

func (wx *WeiXin) PreviewWXCard(toUser string, cardId string, cardExt string) (msgid string, err error)

func (*WeiXin) QueryMassMsgStatus

func (wx *WeiXin) QueryMassMsgStatus(msgId string) (*response.Response, error)

查询群发消息发送状态

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 (wx *WeiXin) ReplyVideo(mediaId string, title string, description string, originMsg *request.WeiXinRequest) string

func (*WeiXin) ReplyVoice

func (wx *WeiXin) ReplyVoice(mediaId string, originMsg *request.WeiXinRequest) string

func (*WeiXin) SendAll

func (wx *WeiXin) SendAll(url string, msg interface{}) (msgid string, err error)

基础发送接口

func (*WeiXin) SendImageByGroupID

func (wx *WeiXin) SendImageByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)

func (*WeiXin) SendImageByOpenIDs

func (wx *WeiXin) SendImageByOpenIDs(toUser []string, mediaId string) (msgid string, err error)

func (*WeiXin) SendNewsByGroupID

func (wx *WeiXin) SendNewsByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)

func (*WeiXin) SendNewsByOpenIDs

func (wx *WeiXin) SendNewsByOpenIDs(toUser []string, mediaId string) (msgid string, err error)

根据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 (wx *WeiXin) SendTextByOpenIDs(toUser []string, content string) (msgid string, err error)

func (*WeiXin) SendVideoByGroupID

func (wx *WeiXin) SendVideoByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)

func (*WeiXin) SendVideoByOpenIDs

func (wx *WeiXin) SendVideoByOpenIDs(toUser []string, mediaId string, title string, description string) (msgid string, err error)

func (*WeiXin) SendVoiceByGroupID

func (wx *WeiXin) SendVoiceByGroupID(groupId string, mediaId string, is_to_all bool) (msgid string, err error)

func (*WeiXin) SendVoiceByOpenIDs

func (wx *WeiXin) SendVoiceByOpenIDs(toUser []string, mediaId string) (msgid string, err error)

func (*WeiXin) SendWXCardByGroupID

func (wx *WeiXin) SendWXCardByGroupID(groupId string, cardId string, is_to_all bool) (msgid string, err error)

func (*WeiXin) SendWXCardByOpenIDs

func (wx *WeiXin) SendWXCardByOpenIDs(toUser []string, cardId string) (msgid string, err error)

func (*WeiXin) ServeHTTP

func (wx *WeiXin) ServeHTTP(w http.ResponseWriter, r *http.Request)

route http request to specified handler

func (*WeiXin) SetIndustry

func (wx *WeiXin) SetIndustry(industryId ...int64) error

模板消息 1. 设定行业

func (*WeiXin) TransferCustomerService

func (wx *WeiXin) TransferCustomerService(kfId string, originMsg *request.WeiXinRequest) string

发送到多客服

func (*WeiXin) UpdateRemark

func (wx *WeiXin) UpdateRemark(openId string, remark string) error

8.设置用户备注名

func (*WeiXin) UploadKFHeadImg

func (wx *WeiXin) UploadKFHeadImg(kf_account string, filename string, reader io.Reader) (string, error)

设置客服帐号的头像

func (*WeiXin) UploadNews

func (wx *WeiXin) UploadNews(news []MPNews) (string, error)

上传图文素材,为高级群发接口

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打开文件时,扩展名必须为小写,否则找到不文件.

func (*WeiXin) UploadVideoForMass

func (wx *WeiXin) UploadVideoForMass(mediaId string, title string, description string) (string, error)

func (*WeiXin) VerifyUserInWhichGroup

func (wx *WeiXin) VerifyUserInWhichGroup(openId string) (string, error)

3. 查询用户所在分组id

Directories

Path Synopsis
皆引自https://github.com/chanxuehong/wechat/blob/master/mp/user/oauth2/oauth2.go 感谢前辈
皆引自https://github.com/chanxuehong/wechat/blob/master/mp/user/oauth2/oauth2.go 感谢前辈
weixin.go
weixin.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL