tp

package
v0.0.0-...-3b54ddd Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

tp

Documentation

Overview

获取授权方的帐号基本信息 - 公众号 - 小程序

Index

Constants

View Source
const (
	URLComponentToken = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"
	URLPreAuthCode    = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token="
	// 公众号或小程序的接口调用凭据
	URLOtherAuthToken = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token="
	// 获取(刷新)授权公众号或小程序的接口调用凭据(令牌)
	URLRefreshOtherAuthToken = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token="
)

Variables

View Source
var (
	Token     string
	AesKey    string
	AppId     string
	AppSecret string
)

Functions

func DecodeMessage

func DecodeMessage(msgSignature, timeStamp, nonce string, body []byte) (t wx_open.Message, err error)

解密消息/事件推送

func DecodeMessageByte

func DecodeMessageByte(msgSignature, timeStamp, nonce string, body []byte) (bs []byte, err error)

解密消息/事件推送

func EncodeMessageByte

func EncodeMessageByte(body []byte) (bs []byte, err error)

加密

func FilterReady

func FilterReady(appId string, body []byte) (stop bool, response []byte, err error)

拦截测试消息并相应

func GetComponentAccessToken

func GetComponentAccessToken() (componentAccessToken string, err error)

获取ComponentAccessToken 会检测过期时间自动刷新哟

func GetLastVerifyTicket

func GetLastVerifyTicket() (ticket string, ok bool)

获取上一次的ticket, 存储在文件

func GetPreAuthCode

func GetPreAuthCode() (preAuthCode string, err error)

获取PreAuthCode 会检测过期时间自动刷新哟

func HandleComponentVerifyTicketReq

func HandleComponentVerifyTicketReq(bs []byte) (ticket string, err error)

处理微信VerifyTicket回调 成功后会将ticket保存在本地文件

func HandleEvent

func HandleEvent(bs []byte, handler EventHandler) (rsp []byte, err error)

处理授权事件

func HandleMessage

func HandleMessage(bs []byte, appId string, filterReady bool, handler EventHandler) (rsp []byte, err error)

处理公众号消息 filterReady: 是否处理全网发布的测试消息

func InitThirdParty

func InitThirdParty(token, aeskey, appid, appSecret string)

在调用第三方平台的时候请务必Init

func SaveVerifyTicket

func SaveVerifyTicket(ticket string) (err error)

存储在文件

Types

type AuthMsgCancelAuthReq

type AuthMsgCancelAuthReq struct {
	EventReq
	CreateTime      string `xml:"CreateTime"`
	AuthorizerAppid string `xml:"AuthorizerAppid"`
}

取消授权通知

type AuthMsgComponentVerifyTicketReq

type AuthMsgComponentVerifyTicketReq struct {
	AppId                 string `xml:"AppId"`
	CreateTime            string `xml:"CreateTime"`
	InfoType              string `xml:"InfoType"`
	ComponentVerifyTicket string `xml:"ComponentVerifyTicket"`
	AuthorizationCode     string `xml:"AuthorizationCode"`
}

component_verify_ticket 出于安全考虑,在第三方平台创建审核通过后,微信服务器每隔10分钟会向第三方的消息接收地址推送一次component_verify_ticket,用于获取第三方平台接口调用凭据 接收到后必须直接返回字符串success。

type AuthorizedInfoReq

type AuthorizedInfoReq struct {
	ComponentAppid         string `json:"component_appid"`
	AuthorizerAppid        string `json:"authorizer_appid"`
	AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
}

type AuthorizedInfoRsp

type AuthorizedInfoRsp struct {
	wx_open.WxResponse
	AccessToken  string `json:"authorizer_access_token"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"authorizer_refresh_token"`
}

func RefreshAccessToken

func RefreshAccessToken(authorizerAppid, refreshToken string) (authorizedInfo *AuthorizedInfoRsp, err error)

type AuthorizerInfo

type AuthorizerInfo struct {
	UserName       string `json:"user_name"`      // 小程序的原始ID
	HeadImg        string `json:"head_img"`       // 授权方头像
	NickName       string `json:"nick_name"`      // 授权方昵称
	PrincipalName  string `json:"principal_name"` // 小程序的主体名称
	Signature      string `json:"signature"`      // 帐号介绍
	QrcodeUrl      string `json:"qrcode_url"`     // 二维码图片的URL,开发者最好自行也进行保存
	VerifyTypeInfo struct {
		Id int `json:"id"`
	} `json:"verify_type_info"` // 授权方认证类型,-1代表未认证,0代表微信认证
	MiniProgramInfo struct {
		Network struct {
			RequestDomain   []string `json:"RequestDomain"`
			WsRequestDomain []string `json:"WsRequestDomain"`
			UploadDomain    []string `json:"UploadDomain"`
			DownloadDomain  []string `json:"DownloadDomain"`
		} `json:"network"`
	} `json:"MiniProgramInfo"`
	BusinessInfo struct {
		OpenPay   int `json:"open_pay"`   // 是否开通微信支付功能
		OpenShake int `json:"open_shake"` // 是否开通微信摇一摇功能
		OpenScan  int `json:"open_scan"`  // 是否开通微信扫商品功能
		OpenCard  int `json:"open_card"`  // 是否开通微信卡券功能
		OpenStore int `json:"open_store"` // 是否开通微信门店功能
	} `json:"business_info"`
}

func GetWxAppInfo

func GetWxAppInfo(appId string) (wxappInfo AuthorizerInfo, err error)

获取小程序账号信息

type AuthorizerTokenReq

type AuthorizerTokenReq struct {
	ComponentAppid    string `json:"component_appid"`
	AuthorizationCode string `json:"authorization_code"`
}

type AuthorizerTokenRsp

type AuthorizerTokenRsp struct {
	AuthorizationInfo struct {
		AuthorizerAppid        string `json:"authorizer_appid"`
		AuthorizerAccessToken  string `json:"authorizer_access_token"`
		ExpiresIn              int64  `json:"expires_in"`
		AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
		FuncInfo               []struct {
			FuncscopeCategory struct {
				Id int `json:"id"`
			} `json:"funcscope_category"`
		} `json:"func_info"`
	} `json:"authorization_info"`
}

func GetAuthorizerToken

func GetAuthorizerToken(authorizationCode string) (authorizerTokenRsp *AuthorizerTokenRsp, err error)

type ComponentAccessTokenReq

type ComponentAccessTokenReq struct {
	ComponentAppid        string `json:"component_appid"`
	ComponentAppsecret    string `json:"component_appsecret"`
	ComponentVerifyTicket string `json:"component_verify_ticket"`
}

type ComponentAccessTokenRsp

type ComponentAccessTokenRsp struct {
	ComponentAccessToken string `json:"component_access_token"`
	ExpiresIn            int64  `json:"expires_in"`
}

type EventHandler

type EventHandler func(types string, body []byte) (rsp []byte, err error)

type EventReq

type EventReq struct {
	AppId    string `xml:"AppId"`
	InfoType string `xml:"InfoType"`
}

初步解析body, 得到type

type MessageHandler

type MessageHandler func(msgType string, body []byte) (rsp []byte, err error)

type MessageReq

type MessageReq struct {
	MsgType string `xml:"MsgType"` // 消息类型: event, text ....
}

初步解析body, 得到type

type PreAuthCodeReq

type PreAuthCodeReq struct {
	ComponentAppid string `json:"component_appid"`
}

type PreAuthCodeRsp

type PreAuthCodeRsp struct {
	PreAuthCode string `json:"pre_auth_code"`
	ExpiresIn   int64  `json:"expires_in"`
}

type SavedVerifyTicket

type SavedVerifyTicket struct {
	VerifyTicket string `json:"verify_ticket"`
	SaveAt       string `json:"save_at"`
}

type WxAppInfo

type WxAppInfo struct {
	wx_open.WxResponse
	AuthorizerInfo AuthorizerInfo `json:"authorizer_info"`
}

Jump to

Keyboard shortcuts

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