offiaccount

package
v1.8.124 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Zlib Imports: 11 Imported by: 0

Documentation

Overview

*

  • 事件数据结构 *
  • 微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次。 *
  • 1 关注/取消关注事件
  • 2 扫描带参数二维码事件
  • 3 上报地理位置事件
  • 4 自定义菜单事件
  • 5 点击菜单拉取消息时的事件推送
  • 6 点击菜单跳转链接时的事件推送

*

第一类 模板消息

  • 1 设置所属行业
  • 2 获取设置的行业信息
  • 3 获得模板ID
  • 4 获取模板列表
  • 5 删除模板
  • 6 发送模板消息

Index

Constants

View Source
const (
	EMSubscribe   = "subscribe"
	EMUnsubscribe = "unsubscribe"
	EMScan        = "SCAN"
	EMLocation    = "LOCATION"
	EMClick       = "CLICK"
	EMView        = "VIEW"
)

Variables

This section is empty.

Functions

func ClearQuota

func ClearQuota(api *token.Api) error

ClearQuota 所有api调用(包括第三方帮其调用)次数进行清零,每月10次 https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN

func DeleteTemplate

func DeleteTemplate(api *token.Api, tmId string) error

DeleteTemplate 删除模板 POST https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN { "template_id" : "Dyvp3-Ff0cnail_CDSzk1fIc6-9lOkxsQE7exTJbwUE" }

func GenerateShortUrl

func GenerateShortUrl(api *token.Api, longUrl string) (string, error)

GenerateShortUrl 长链接转短链接接口 https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN

func GetCallbackIP

func GetCallbackIP(api *token.Api) ([]string, error)

GetCallbackIP 获取微信服务器IP地址 https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN

func GetTemplateId

func GetTemplateId(api *token.Api, tmShortId string) (string, error)

GetTemplateId 获得模板ID POST https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN

func GetTicket

func GetTicket(tk token.Token, d data.D) (*token.Ticket, error)

GetTicket 由于获取api_ticket 的api 调用次数非常有限,频繁刷新api_ticket 会导致api调用受限,影响自身业务,开发者需在自己的服务存储与更新api_ticket

func Oauth2

func Oauth2(tk token.Token, d data.D) (access.Token, error)

Oauth2 官司说明 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842 微信网页通过code 授权access_token, 这个授权只是某一个具体的app,某个具体openid对应的access_token

func QRGetBitmap

func QRGetBitmap(ticket string) ([]byte, error)

QRGetBitmap 获取二维码ticket后,开发者可用ticket换取二维码图片。请注意,本接口无须登录态即可调用。 HTTP GET请求(请使用https协议)https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET 提醒:TICKET记得进行UrlEncode ticket正确情况下,http 返回码是200,是一张图片,可以直接展示或者下载。

HEAD Accept-Ranges:bytes IsCache-control:max-age=604800 Connection:keep-alive Content-Length:28026 Content-Name:image/jpg

func SetIndustry

func SetIndustry(api *token.Api, req *IndustryReq) error

SetIndustry 设置所属行业,每月可修改行业1次 数据示例如下:

{
   "industry_id1":"1",
   "industry_id2":"4"
}

POST https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN

func UserCancelBlack

func UserCancelBlack(api *token.Api, req *BatchReq) error

UserCancelBlack 取消拉黑用户 POST https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=ACCESS_TOKEN

func UserGetUnionId

func UserGetUnionId(api *token.Api, openid string) (string, error)

UserGetUnionId 获取 unionid GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID

func UserSetBlack

func UserSetBlack(api *token.Api, req *BatchReq) error

UserSetBlack 拉黑用户 公众号可通过该接口来拉黑一批用户,黑名单列表由一串 OpenId (加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。 POST https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=ACCESS_TOKEN

Types

type ActionInfo

type ActionInfo struct {
	Scene Scene `json:"scene"`
}

type AllMsg

type AllMsg struct {
	Head
	EvData
	MsgData
}

All pack

func (AllMsg) IsEvent

func (m AllMsg) IsEvent() bool

func (AllMsg) ToEvent

func (m AllMsg) ToEvent() *EventMsg

func (AllMsg) ToNormal

func (m AllMsg) ToNormal() *NormalMsg

type BatchReq

type BatchReq struct {
	OpenIdList []string `json:"begin_openid,omitempty"`
}

type BlackReq

type BlackReq struct {
	OpenId string `json:"begin_openid,omitempty"`
}

type EvData

type EvData struct {
	Event string `xml:"Event,omitempty" json:"Event,omitempty"`

	//for subscribe  unsubscribe, SCAN, LOCATION, CLICK, VIEW
	EventKey string `xml:"EventKey,omitempty"  json:"EventKey,omitempty"`

	//for 扫二维码
	Ticket string `xml:"Ticket,omitempty"  json:"Ticket,omitempty"`

	//上报地理位置事件
	Latitude  float64 `xml:"Latitude" json:"Latitude,omitempty"`   //地理位置纬度
	Longitude float64 `xml:"Longitude" json:"Longitude,omitempty"` //地理位置经度
	Precision float64 `xml:"Precision" json:"Precision,omitempty"` //地理位置精度

	//点击菜单跳转链接时的事件推送 .EventMsg = "VIEW"
	MenuID string `xml:"MenuID" json:"MenuID,omitempty"` //指菜单ID,如果是个性化菜单,则可以通过这个字段,知道是哪个规则的菜单被点击了。

	Status string `xml:"Status" json:"Status,omitempty"`

	//for 客户 user_enter_tempsession
	SessionFrom string `xml:"SessionFrom" json:"SessionFrom,omitempty"`
}

type EventMsg

type EventMsg struct {
	Head
	EvData
}

.MsgType = "event"

type Head struct {
	ToAppId    string
	ToUser     string `xml:"ToUserName" json:"ToUserName"`     //开发者微信号
	FromUser   string `xml:"FromUserName" json:"FromUserName"` //OpenId
	CreateTime int64  `xml:"CreateTime" json:"CreateTime"`
	MsgType    string `xml:"MsgType" json:"MsgType"`
}

type Industry

type Industry struct {
	FirstClass  string `json:"first_class"`
	SecondClass string `json:"second_class"`
}

所属行业

type IndustryReq

type IndustryReq struct {
	Id1 string `json:"industry_id1"`
	Id2 string `json:"industry_id2"`
}

所属行业设置

type IndustryS

type IndustryS struct {
	Primary   Industry `json:"primary_industry"`
	Secondary Industry `json:"secondary_industry"`
}

func GetIndustry

func GetIndustry(api *token.Api) (*IndustryS, error)

GetIndustry 获取设置的行业信息 GET https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=ACCESS_TOKEN ErrorIf { "primary_industry":{"first_class":"运输与仓储","second_class":"快递"}, "secondary_industry":{"first_class":"IT科技","second_class":"互联网|电子商务"} }

type Link struct {
	Title string
	Desc  string
	Url   string
}

type Location

type Location struct {
	LocationX float64 //地理位置纬度
	LocationY float64 //地理位置经度
	Scale     float64 //地理位置精度
	Label     string  //地址
}

type MsgData

type MsgData struct {
	MsgId string `xml:"MsgId,omitempty" json:"MsgId,omitempty"`

	// text
	Content string `xml:"Content,omitempty" json:"Content,omitempty"`

	// media
	MediaId string `xml:"MediaId,omitempty" json:"MediaId,omitempty"`

	// image
	PicUrl string `xml:"PicUrl,omitempty" json:"PicUrl,omitempty"`

	// voice
	Format      string `xml:"Format,omitempty" json:"Format,omitempty"`
	Recognition string `xml:"Recognition,omitempty" json:"Recognition,omitempty"`

	// video
	ThumbMediaId string `xml:"ThumbMediaId,omitempty" json:"ThumbMediaId,omitempty"`

	//地理位置
	LocationX float64 `xml:"Location_X,omitempty" json:"Location_X,omitempty"` //地理位置纬度
	LocationY float64 `xml:"Location_Y,omitempty" json:"Location_Y,omitempty"` //地理位置经度
	Scale     float64 `xml:"Scale,omitempty" json:"Scale,omitempty"`           //地理位置精度
	Label     string  `xml:"Label,omitempty" json:"Label,omitempty"`           //地址

	//link
	Title string `xml:"Title" json:"Title,omitempty"`
	Desc  string `xml:"Description" json:"Description,omitempty"`
	Url   string `xml:"Url,omitempty" json:"Url,omitempty"`

	//小卡片
	AppId    string `xml:"AppId" json:"AppId,omitempty"`
	PagePath string `xml:"PagePath" json:"PagePath,omitempty"`
	ThumbUrl string `xml:"ThumbUrl,omitempty" json:"ThumbUrl,omitempty"`
}

type NormalMsg

type NormalMsg struct {
	Head
	MsgData
}

.MsgType = text .MsgType = image .MsgType = voice .MsgType = location .MsgType = shortvideo

type OpenId

type OpenId struct {
	OpenId []string `json:"openid"`
}

type Phone

type Phone struct {
	User
	//用户绑定的手机号(国外手机号会有区号)
	PhoneNumber string `json:"phoneNumber,omitempty"`

	//没有区号的手机号
	PurePhoneNumber string `json:"purePhoneNumber,omitempty"`

	//区号
	CountryCode string `json:"countryCode,omitempty"`
}

type QRCode

type QRCode struct {
	Ticket string `json:"ticket"`
	Expire int64  `json:"expire_seconds"`
	Url    string `json:"url"`
}

func QRCreate

func QRCreate(api *token.Api, qr *QRCodeReq) (*QRCode, error)

QRCreate 临时二维码请求说明

http请求方式: POST URL: https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN POST数据格式:json POST数据例子:{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}

或者也可以使用以下POST数据创建字符串形式的二维码参数: {"expire_seconds": 604800, "action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}} 2 永久二维码请求说明

http请求方式: POST URL: https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN POST数据格式:json POST数据例子:{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}

或者也可以使用以下POST数据创建字符串形式的二维码参数: {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}} expire_seconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 action_name 二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值 action_info 二维码详细信息 scene_id 场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000) scene_str 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64

返回 {"ticket":"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。 expire_seconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天)。 url 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片

type QRCodeReq

type QRCodeReq struct {
	Expire     int64      `json:"expire_seconds,omitempty"`
	ActionName string     `json:"action_name"`
	ActionInfo ActionInfo `json:"action_info"`
}

二维码

func QRGenerateReq

func QRGenerateReq(expireSeconds int64, actionName, sceneStr string, sceneId int32) QRCodeReq

QRGenerateReq

  • 临时二维码 QRGenerateReq(6000,"QR_SCENE","", 1) OR GenReq(6000,"QR_STR_SCENE","test", 0)

  • 永久二维码 QRGenerateReq(0,"QR_LIMIT_SCENE","", 1) OR GenReq(0,"QR_LIMIT_STR_SCENE","test", 0)

type QrcBuffer

type QrcBuffer struct {
	Type string `json:"contentType"`
	Buff []byte `json:"buffer"`
}

type Scene

type Scene struct {
	SceneId  int32  `json:"scene_id,omitempty"`  //场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)
	SceneStr string `json:"scene_str,omitempty"` //场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
}

type ShortUrlReq

type ShortUrlReq struct {
	Action string `json:"action"` //=long2short
	Url    string `json:"long_url"`
}

长链接转短链接

type TemplateInfo

type TemplateInfo struct {
	Id              string `json:"template_id"`
	Title           string `json:"title"`
	PrimaryIndustry string `json:"primary_industry"`
	DeputyIndustry  string `json:"deputy_industry"`
	Content         string `json:"content"`
	Example         string `json:"example"`
}

TemplateInfo 模板信息

type User

type User struct {
	OpenId    string   `json:"openid"`               //用户的唯一标识
	UnionId   string   `json:"unionid,omitempty"`    //只有在用户将公众号绑定到微信开放平台账号后,才会出现该字段
	Nick      string   `json:"nickname,omitempty"`   //用户昵称
	ImgUrl    string   `json:"headimgurl,omitempty"` //用户头像,最后一个数值代表正方形头像大小
	Province  string   `json:"province,omitempty"`   //省份
	City      string   `json:"city,omitempty"`       //城市
	Country   string   `json:"country,omitempty"`    //国家
	Privilege []string `json:"privilege,omitempty"`  //用户特权信息,json 数组
	Language  string   `json:"language,omitempty"`   // 语言,zh-CN
	AppId     string   `json:"appid"`
	Sex       int      `json:"sex,omitempty"` //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
}

func Oauth2UserGet

func Oauth2UserGet(api *token.Api, openid, lang string) (*User, error)

Oauth2UserGet GET https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s 通过access_token和openid获取用户的基础信息,包括头像、昵称、性别、地区

type UserEx

type UserEx struct {
	User
	Subscribe      int     `json:"subscribe"`                 //用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息
	SubscribeTime  int64   `json:"subscribe_time,omitempty"`  //用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
	Remark         string  `json:"remark,omitempty"`          //公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
	GroupId        int64   `json:"groupid,omitempty"`         //用户所在的分组ID(兼容旧的用户分组接口)
	TagIds         []int64 `json:"tagid_list,omitempty"`      //用户被打上的标签ID列表
	SubscribeScene string  `json:"subscribe_scene,omitempty"` //返回用户关注的渠道来源,ADD_SCENE_SEARCH 公众号搜索,ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 扫描二维码,ADD_SCENE_PROFILE_LINK 图文页内名称点击,ADD_SCENE_PROFILE_ITEM 图文页右上角菜单,ADD_SCENE_PAID 支付后关注,ADD_SCENE_WECHAT_ADVERTISEMENT 微信广告,ADD_SCENE_REPRINT 他人转载,ADD_SCENE_LIVESTREAM 视频号直播,ADD_SCENE_CHANNELS 视频号,ADD_SCENE_W
	QRSceneId      int32   `json:"qr_scene,omitempty"`        //二维码扫码场景
	QRSceneStr     string  `json:"qr_scene_str,omitempty"`    //二维码扫码场景描述
}

func UserBatchGetInfo

func UserBatchGetInfo(api *token.Api, open []UserReq) ([]UserEx, error)

UserBatchGetInfo 批量获取用户基本信息 开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。 http请求方式: POST https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN

func UserGetInfo

func UserGetInfo(api *token.Api, openid, lang string) (*UserEx, error)

UserGetInfo 2021年12月27日之后,不再输出头像、昵称信息。 GET https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN

type UserOpenIdList

type UserOpenIdList struct {
	Total      int32  `json:"total"`
	Count      int32  `json:"count"`
	Data       OpenId `json:"data"`
	NextOpenId string `json:"next_openid"`
}

func UserGetBlack

func UserGetBlack(api *token.Api, nextopenid string) (*UserOpenIdList, error)

UserGetBlack 获取公众号的黑名单列表

公众号可通过该接口来获取帐号的黑名单列表,黑名单列表由一串 OpenId(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。

该接口每次调用最多可拉取 10000 个OpenID,当列表数较多时,可以通过多次拉取的方式来满足需求。 POST https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=ACCESS_TOKEN

func UserGetList

func UserGetList(api *token.Api, nextopenid string) (*UserOpenIdList, error)

UserGetList 获取用户列表 公众号可通过本接口来获取帐号的关注者列表,关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。 GET https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID

type UserReq

type UserReq struct {
	Openid string `json:"openid"`
	Lang   string `json:"lang"`
}

type Video

type Video struct {
	MediaId      string
	ThumbMediaId string
}

type Voice

type Voice struct {
	MediaId string
	Format  string
}

Jump to

Keyboard shortcuts

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