pub

package
v0.0.0-...-68579e1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CgiBinAccessTokenURL = "https://api.weixin.qq.com/cgi-bin/token"
	CgiBinTicketURL      = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
)

cgi-bin

View Source
const (
	MenuCreateURL            = "https://api.weixin.qq.com/cgi-bin/menu/create"
	MenuAddConditionalURL    = "https://api.weixin.qq.com/cgi-bin/menu/addconditional"
	MenuListURL              = "https://api.weixin.qq.com/cgi-bin/menu/get"
	MenuDeleteURL            = "https://api.weixin.qq.com/cgi-bin/menu/delete"
	MenuDeleteConditionalURL = "https://api.weixin.qq.com/cgi-bin/menu/delconditional"
)

menu

View Source
const (
	SnsCode2Token            = "https://api.weixin.qq.com/sns/oauth2/access_token"
	SnsCheckAccessTokenURL   = "https://api.weixin.qq.com/sns/auth"
	SnsRefreshAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token"
	SnsUserInfoURL           = "https://api.weixin.qq.com/sns/userinfo"
)

sns

View Source
const (
	SubscriberGetURL      = "https://api.weixin.qq.com/cgi-bin/user/info"
	SubscriberBatchGetURL = "https://api.weixin.qq.com/cgi-bin/user/info/batchget"
	SubscriberListURL     = "https://api.weixin.qq.com/cgi-bin/user/get"
)

subscriber

View Source
const DefaultReply = "success"

DefaultReply 公众号默认回复

View Source
const MaxSubscriberListCount = 10000

MaxSubscriberListCount 公众号订阅者列表的最大数目

View Source
const (
	TplMsgSendURL = "https://api.weixin.qq.com/cgi-bin/message/template/send"
)

msg

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token     string `json:"access_token"`
	ExpiresIn int64  `json:"expires_in"`
}

AccessToken wxpub access_token

type Article

type Article struct {
	Title       utils.CDATA `xml:"Title"`       // 图文消息标题
	Description utils.CDATA `xml:"Description"` // 图文消息描述
	PicURL      utils.CDATA `xml:"PicUrl"`      // 图片链接, 支持JPG, PNG格式, 较好的效果为大图360*200, 小图200*200
	URL         utils.CDATA `xml:"Url"`         // 点击图文消息跳转链接
}

Article 公众号图文

type ArticlesReply

type ArticlesReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	ArticleCount int        `xml:"ArticleCount"`  // 图文消息个数, 限制为10条以内
	Articles     []*Article `xml:"Articles>item"` // 多条图文消息信息, 默认第一个item为大图, 注意, 如果图文数超过10, 则将会无响应
}

Articles 公众号图文回复

type AuthToken

type AuthToken struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
	OpenID       string `json:"openid"`
	Scope        string `json:"scope"`
}

AuthToken 公众号授权Token

type Button

type Button interface {
	AddSubButton(btn ...Button)
}

Button 菜单按钮

func ClickButton

func ClickButton(name, key string) Button

ClickButton 点击事件按钮

func GroupButton

func GroupButton(name string) Button

GroupButton 组合按钮

func LocationSelectButton

func LocationSelectButton(name, key string) Button

LocationSelectButton 发送位置按钮

func MPButton

func MPButton(name, appid, pagepath string, url ...string) Button

MPButton 小程序跳转按钮

func MediaButton

func MediaButton(name, mediaID string) Button

MediaButton 图片按钮

func PicPhotoOrAlbum

func PicPhotoOrAlbum(name, key string) Button

PicPhotoOrAlbum 拍照或者相册发图按钮

func PicSysphotoButton

func PicSysphotoButton(name, key string) Button

PicSysphotoButton 系统拍照发图按钮

func PicWeixin

func PicWeixin(name, key string) Button

PicWeixin 微信相册发图按钮

func ScancodePushButton

func ScancodePushButton(name, key string) Button

ScancodePushButton 扫码推事件按钮

func ScancodeWaitMsgButton

func ScancodeWaitMsgButton(name, key string) Button

ScancodeWaitMsgButton 扫码带提示按钮

func ViewButton

func ViewButton(name, url string) Button

ViewButton 跳转URL按钮

func ViewLimitedButton

func ViewLimitedButton(name, mediaID string) Button

ViewLimitedButton 图文消息按钮

type CgiBin

type CgiBin struct {
	// contains filtered or unexported fields
}

CgiBin cgi-bin

func (*CgiBin) GetAccessToken

func (c *CgiBin) GetAccessToken() (*AccessToken, error)

GetAccessToken returns access_token

func (*CgiBin) GetTicket

func (c *CgiBin) GetTicket(accessToken string) (*JSAPITicket, error)

GetTicket returns jsapi ticket

type ConditionalMenu

type ConditionalMenu struct {
	Button    []*MenuButton  `json:"button"`
	MenuID    int64          `json:"menuid"`
	MatchRule *MenuMatchRule `json:"matchrule"`
}

type DefaultMenu

type DefaultMenu struct {
	Button []*MenuButton `json:"button"`
	MenuID int64         `json:"menuid"`
}

type EventMsg

type EventMsg struct {
	ToUserName   string  `xml:"ToUserName"`
	FromUserName string  `xml:"FromUserName"`
	CreateTime   int64   `xml:"CreateTime"`
	MsgType      string  `xml:"MsgType"`
	MsgID        int64   `xml:"MsgId"`
	Content      string  `xml:"Content"`
	PicURL       string  `xml:"PicUrl"`
	MediaID      string  `xml:"MediaId"`
	Format       string  `xml:"Format"`
	Recognition  string  `xml:"Recognition"`
	ThumbMediaID string  `xml:"ThumbMediaId"`
	LocationX    float64 `xml:"Location_X"`
	LocationY    float64 `xml:"Location_Y"`
	Scale        int     `xml:"Scale"`
	Label        string  `xml:"Label"`
	Title        string  `xml:"Title"`
	Description  string  `xml:"Description"`
	URL          string  `xml:"Url"`
	Event        string  `xml:"Event"`
	EventKey     string  `xml:"EventKey"`
	Ticket       string  `xml:"Ticket"`
	Latitude     float64 `xml:"Latitude"`
	Longitude    float64 `xml:"Longitude"`
	Precision    float64 `xml:"Precision"`
}

EventMsg 微信公众号事件消息

type ImageReply

type ImageReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	Image struct {
		MediaID utils.CDATA `xml:"MediaId"` // 通过素材管理接口上传多媒体文件得到 MediaId
	} `xml:"Image"`
}

ImageReply 公众号图片回复

type JSAPITicket

type JSAPITicket struct {
	Ticket    string `json:"ticket"`
	ExpiresIn int64  `json:"expires_in"`
}

JSAPITicket wxpub js api ticket

type Menu struct {
	// contains filtered or unexported fields
}

Menu 公众号菜单

func (m *Menu) Create(accessToken string, btns ...Button) error

Create 创建自定义菜单

func (m *Menu) CreateConditional(accessToken string, matchRule *MenuMatchRule, btns ...Button) error

CreateConditional 创建个性化菜单

func (m *Menu) Delete(accessToken string) error

Delete 删除自定义菜单

func (m *Menu) DeleteConditional(accessToken, menuID string) error

DeleteConditional 删除个性化菜单

func (m *Menu) GetList(accessToken string) (*MenuList, error)

GetList 查询自定义菜单

type MenuButton struct {
	Type      string        `json:"type"`
	Name      string        `json:"name"`
	Key       string        `json:"key,omitempty"`
	URL       string        `json:"url,omitempty"`
	AppID     string        `json:"appid,omitempty"`
	PagePath  string        `json:"page_path,omitempty"`
	MediaID   string        `json:"media_id,omitempty"`
	SubButton []*MenuButton `json:"sub_button,omitempty"`
}
type MenuList struct {
	DefaultMenu     *DefaultMenu       `json:"menu"`
	ConditionalMenu []*ConditionalMenu `json:"conditionalmenu"`
}
type MenuMatchRule struct {
	TagID              int64  `json:"tag_id"`
	Sex                int    `json:"sex"`
	Country            string `json:"country"`
	Province           string `json:"province"`
	City               string `json:"city"`
	ClientPlatformType int    `json:"client_platform_type"`
}

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message 公众号消息

func (*Message) Template

func (m *Message) Template(data *TplMsg, accessToken string) (int64, error)

Template 发送模板消息

type MsgBody

type MsgBody map[string]map[string]string

MsgBody 消息内容体

type MsgCrypt

type MsgCrypt struct {
	// contains filtered or unexported fields
}

MsgCrypt 公众号消息解析

func (*MsgCrypt) Decrypt

func (m *MsgCrypt) Decrypt() error

Decrypt 消息解密,参考微信[加密解密技术方案](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318482&token=&lang=zh_CN)

func (*MsgCrypt) EventMsg

func (m *MsgCrypt) EventMsg() (*EventMsg, error)

EventMsg 获取事件消息

type MusicReply

type MusicReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	Music struct {
		Title        utils.CDATA `xml:"Title,omitempty"`       // 音乐标题
		Description  utils.CDATA `xml:"Description,omitempty"` // 音乐描述
		MusicURL     utils.CDATA `xml:"MusicUrl,omitempty"`    // 音乐链接
		HQMusicURL   utils.CDATA `xml:"HQMusicUrl,omitempty"`  // 高质量音乐链接, WIFI环境优先使用该链接播放音乐
		ThumbMediaID utils.CDATA `xml:"ThumbMediaId"`          // 通过素材管理接口上传多媒体文件得到 ThumbMediaId
	} `xml:"Music"`
}

Music 公众号音乐回复

type Reply

type Reply struct {
	// contains filtered or unexported fields
}

Reply 公众号回复

func (*Reply) Articles

func (r *Reply) Articles(count int, articles ...*Article) (*ReplyMsg, error)

Articles build wxpub articles reply msg

func (*Reply) Image

func (r *Reply) Image(mediaID string) (*ReplyMsg, error)

Image build wxpub image reply msg

func (*Reply) Music

func (r *Reply) Music(mediaID, title, desc, url, HQUrl string) (*ReplyMsg, error)

Music build wxpub music reply msg

func (*Reply) Text

func (r *Reply) Text(content string) (*ReplyMsg, error)

Text build wxpub text reply msg

func (*Reply) Transfer2KF

func (r *Reply) Transfer2KF(kfAccount ...string) (*ReplyMsg, error)

Transfer2KF transfer msg to wxpub kf

func (*Reply) Video

func (r *Reply) Video(mediaID, title, desc string) (*ReplyMsg, error)

Video build wxpub video reply msg

func (*Reply) Voice

func (r *Reply) Voice(mediaID string) (*ReplyMsg, error)

Voice build wxpub voice reply msg

type ReplyHeader

type ReplyHeader struct {
	ToUserName   utils.CDATA `xml:"ToUserName"`
	FromUserName utils.CDATA `xml:"FromUserName"`
	CreateTime   int64       `xml:"CreateTime"`
	MsgType      utils.CDATA `xml:"MsgType"`
}

ReplyHeader 公众号消息回复公共头

type ReplyMsg

type ReplyMsg struct {
	XMLName      xml.Name    `xml:"xml"`
	Encrypt      utils.CDATA `xml:"Encrypt"`
	MsgSignature utils.CDATA `xml:"MsgSignature"`
	TimeStamp    int64       `xml:"TimeStamp"`
	Nonce        utils.CDATA `xml:"Nonce"`
}

ReplyMsg 公众号回复消息

type Sns

type Sns struct {
	// contains filtered or unexported fields
}

Sns sns

func (*Sns) CheckAccessToken

func (s *Sns) CheckAccessToken(accessToken, openid string) bool

CheckAccessToken 校验授权AccessToken是否有效

func (*Sns) Code2Token

func (s *Sns) Code2Token(code string) (*AuthToken, error)

Code2Token 获取公众号授权AccessToken

func (*Sns) GetUserInfo

func (s *Sns) GetUserInfo(accessToken, openid string) (*User, error)

GetUserInfo 获取微信用户信息

func (*Sns) RefreshAccessToken

func (s *Sns) RefreshAccessToken(refreshToken string) (*AuthToken, error)

RefreshAccessToken 刷新授权AccessToken

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

Subscriber 微信公众号订阅者

func (*Subscriber) BatchGet

func (s *Subscriber) BatchGet(accessToken string, openid ...string) ([]*SubscriberInfo, error)

BatchGet 批量获取微信公众号订阅者信息

func (*Subscriber) Get

func (s *Subscriber) Get(accessToken, openid string) (*SubscriberInfo, error)

GetSubscriberInfo 获取微信公众号订阅者信息

func (*Subscriber) GetList

func (s *Subscriber) GetList(accessToken string, nextOpenID ...string) (*SubscriberList, error)

GetList 获取微信公众号订阅者列表

type SubscriberInfo

type SubscriberInfo struct {
	Subscribe      int     `json:"subscribe"`
	OpenID         string  `json:"openid"`
	NickName       string  `json:"nickName"`
	Sex            int     `json:"sex"`
	Language       string  `json:"language"`
	City           string  `json:"city"`
	Province       string  `json:"province"`
	Country        string  `json:"country"`
	AvatarURL      string  `json:"headimgurl"`
	SubscribeTime  int64   `json:"subscribe_time"`
	UnionID        string  `json:"unionid"`
	Remark         string  `json:"remark"`
	GroupID        int64   `json:"groupid"`
	TagidList      []int64 `json:"tagid_list"`
	SubscribeScene string  `json:"subscribe_scene"`
	QRScene        int64   `json:"qr_scene"`
	QRSceneStr     string  `json:"qr_scene_str"`
}

SubscriberInfo 微信公众号订阅者信息

type SubscriberList

type SubscriberList struct {
	Total      int                 `json:"total"`
	Count      int                 `json:"count"`
	Data       map[string][]string `json:"data"`
	NextOpenID string              `json:"next_openid"`
}

SubscriberList 微信公众号订阅者列表

type TextReply

type TextReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	Content utils.CDATA `xml:"Content"`
}

TextReply 公众号文本回复

type TplMsg

type TplMsg struct {
	OpenID      string  // 接收者(用户)的 openid
	TplID       string  // 模板ID
	RedirectURL string  // 模板跳转链接(海外帐号没有跳转能力)
	MPAppID     string  // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系,暂不支持小游戏)
	MPPagePath  string  // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar),要求该小程序已发布,暂不支持小游戏
	Data        MsgBody // 模板内容,格式形如:{"key1": {"value": any}, "key2": {"value": any}}
	Color       string  // 模板内容字体颜色,不填默认为黑色
}

TplMsg 公众号模板消息

type TransInfo

type TransInfo struct {
	KfAccount utils.CDATA `xml:"KfAccount"`
}

TransInfo 转发客服账号

type Transfer2KF

type Transfer2KF struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	TransInfo *TransInfo `xml:"TransInfo,omitempty"`
}

Transfer2KF 公众号消息转客服

type User

type User struct {
	OpenID    string   `json:"openid"`
	UnionID   string   `json:"unionid"`
	Nickname  string   `json:"nickname"`
	Gender    int      `json:"sex"`
	Province  string   `json:"province"`
	City      string   `json:"city"`
	Country   string   `json:"country"`
	Avatar    string   `json:"headimgurl"`
	Privilege []string `json:"privilege"`
}

User 微信用户信息

type VideoReply

type VideoReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	Video struct {
		MediaID     utils.CDATA `xml:"MediaId"`               // 通过素材管理接口上传多媒体文件得到 MediaId
		Title       utils.CDATA `xml:"Title,omitempty"`       // 视频消息的标题, 可以为空
		Description utils.CDATA `xml:"Description,omitempty"` // 视频消息的描述, 可以为空
	} `xml:"Video" json:"Video"`
}

Video 公众号视频回复

type VoiceReply

type VoiceReply struct {
	XMLName xml.Name `xml:"xml"`
	ReplyHeader
	Voice struct {
		MediaID utils.CDATA `xml:"MediaId"` // 通过素材管理接口上传多媒体文件得到 MediaId
	} `xml:"Voice"`
}

VoiceReply 公众号语音回复

type WXPub

type WXPub struct {
	AccountID      string
	AppID          string
	AppSecret      string
	SignToken      string
	EncodingAESKey string
	Client         *utils.HTTPClient
}

WXPub 微信公众号

func (*WXPub) CgiBin

func (wx *WXPub) CgiBin(options ...utils.HTTPRequestOption) *CgiBin

CgiBin returns new cgi-bin

func (*WXPub) Menu

func (wx *WXPub) Menu(options ...utils.HTTPRequestOption) *Menu

Menu returns new menu

func (*WXPub) Message

func (wx *WXPub) Message(options ...utils.HTTPRequestOption) *Message

Message returns new tpl msg

func (*WXPub) MsgCrypt

func (wx *WXPub) MsgCrypt(cipherMsg string) *MsgCrypt

MsgCrypt returns new msg crypt

func (*WXPub) Reply

func (wx *WXPub) Reply(openid string) *Reply

Reply returns new reply

func (*WXPub) Sns

func (wx *WXPub) Sns(options ...utils.HTTPRequestOption) *Sns

Sns returns new sns

func (*WXPub) Subscriber

func (wx *WXPub) Subscriber(options ...utils.HTTPRequestOption) *Subscriber

Subscriber returns new subscriber

Jump to

Keyboard shortcuts

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