open

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationUrl       = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s"
	TokenUrl               = "/cgi-bin/component/api_component_token"
	CreatePreAuthCodeUrl   = "/cgi-bin/component/api_create_preauthcode?component_access_token="
	QueryAuthUrl           = "/cgi-bin/component/api_query_auth?component_access_token="
	AuthorizerTokenUrl     = "/cgi-bin/component/api_authorizer_token?component_access_token="
	AuthorizerInfoUrl      = "/cgi-bin/component/api_get_authorizer_info?component_access_token="
	AuthorizerOptionUrl    = "/cgi-bin/component/api_get_authorizer_option?component_access_token="
	SetAuthorizerOptionUrl = "/cgi-bin/component/api_set_authorizer_option?component_access_token="
	AuthorizerListUrl      = "/cgi-bin/component/api_get_authorizer_list?component_access_token="
	ClearQuotaUrl          = "/cgi-bin/component/clear_quota?component_access_token="
	OpenCreateUrl          = "/cgi-bin/open/create?access_token="
	OpenBindUrl            = "/cgi-bin/open/bind?access_token="
	OpenUnbindUrl          = "/cgi-bin/open/unbind?access_token="
	OpenGetUrl             = "/cgi-bin/open/get?access_token="
)

此项目所有开发接口文档来源于:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Third_party_platform_appid.html

Variables

This section is empty.

Functions

func AuthorizationMessageAdapter

func AuthorizationMessageAdapter(call func(common.CallbackModel, common.Adapter) string) common.Adapter

func VerifyTicketMessageAdapter

func VerifyTicketMessageAdapter(call func(common.CallbackModel, common.Adapter) string) common.Adapter

VerifyTicketMessageAdapter 验证票据 验证票据(component_verify_ticket),在第三方平台创建审核通过后,微信服务器会向其 ”授权事件接收URL” 每隔 10 分钟以 POST 的方式推送 component_verify_ticket

接收 POST 请求后,只需直接返回字符串 success。

注意:component_verify_ticket 的有效时间为12小时,比 component_access_token 更长,建议保存最近可用的component_verify_ticket, 在 component_access_token 过期之前都可以直接使用该 component_verify_ticket 进行更新,避免出现因为 component_verify_ticket 接收失败而无法更新 component_access_token 的情况。 详见:third.VerifyTicketMessage

Types

type AuthorizationInfoModel

type AuthorizationInfoModel struct {
	common.ErrorModel
	AuthorizationInfo common.AuthorizationInfo `json:"authorization_info"`
}

AuthorizationInfoModel 授权信息结果参数说明 参数 类型 说明 authorization_info Object 授权信息 授权信息说明 参数 类型 说明 authorizer_appid string 授权方 appid authorizer_access_token string 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值) expires_in number authorizer_access_token 的有效期(在授权的公众号/小程序具备API权限时,才有此返回值),单位:秒 authorizer_refresh_token string 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。

一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效

func_info 授权给开发者的权限集列表 返回结果示例:

{
 "authorization_info": {
   "authorizer_appid": "wxf8b4f85f3a794e77",
   "authorizer_access_token": "QXjUqNqfYVH0yBE1iI_7vuN_9gQbpjfK7hYwJ3P7xOa88a89-Aga5x1NMYJyB8G2yKt1KCl0nPC3W9GJzw0Zzq_dBxc8pxIGUNi_bFes0qM",
   "expires_in": 7200,
   "authorizer_refresh_token": "dTo-YCXPL4llX-u1W1pPpnp8Hgm4wpJtlR6iV0doKdY",
   "func_info": [
     {
       "funcscope_category": {
         "id": 1
       }
     },
     {
       "funcscope_category": {
         "id": 2
       }
     },
     {
       "funcscope_category": {
         "id": 3
       }
     }
   ]
 }
}

type AuthorizationMessage

type AuthorizationMessage struct {
	PlatformMessage
	AuthorizerAppid              string `xml:"AuthorizerAppid"`              // 公众号或小程序的 appid
	AuthorizationCode            string `xml:"AuthorizationCode"`            // 授权码,可用于获取授权信息
	AuthorizationCodeExpiredTime int64  `xml:"AuthorizationCodeExpiredTime"` // 授权码过期时间 单位秒
	PreAuthCode                  string `xml:"PreAuthCode"`                  // 授权码过期时间 单位秒
}

AuthorizationMessage 授权变更通知推送 当公众号/小程序对第三方平台进行授权、取消授权、更新授权后,微信服务器会向第三方平台方的授权事件接收 URL(创建时由第三方平台时填写)以 POST 的方式推送相关通知。

接收 POST 请求后,只需直接返回字符串 success。为了加强安全性,postdata 中的 xml 将使用服务申请时的加解密 key 来进行加密,具体请见《加密解密技术方案》, 在收到推送后需进行解密(详细请见《消息加解密接入指引》),

字段说明 参数 类型 字段描述 AppId string 第三方平台 appid CreateTime number 时间戳 InfoType string 通知类型,详见InfoType 说明 AuthorizerAppid string 公众号或小程序的 appid AuthorizationCode string 授权码,可用于获取授权信息 AuthorizationCodeExpiredTime nubmer 授权码过期时间 单位秒 PreAuthCode string 预授权码

InfoType 说明 type 说明 unauthorized 取消授权 updateauthorized 更新授权 authorized 授权成功 推送内容解密后的示例:

授权成功通知 <xml>

<AppId>第三方平台appid</AppId>
<CreateTime>1413192760</CreateTime>
<InfoType>authorized</InfoType>
<AuthorizerAppid>公众号appid</AuthorizerAppid>
<AuthorizationCode>授权码</AuthorizationCode>
<AuthorizationCodeExpiredTime>过期时间</AuthorizationCodeExpiredTime>
<PreAuthCode>预授权码</PreAuthCode>

<xml> 取消授权通知 <xml>

<AppId>第三方平台appid</AppId>
<CreateTime>1413192760</CreateTime>
<InfoType>unauthorized</InfoType>
<AuthorizerAppid>公众号appid</AuthorizerAppid>

</xml> 授权更新通知 <xml>

<AppId>第三方平台appid</AppId>
<CreateTime>1413192760</CreateTime>
<InfoType>updateauthorized</InfoType>
<AuthorizerAppid>公众号appid</AuthorizerAppid>
<AuthorizationCode>授权码</AuthorizationCode>
<AuthorizationCodeExpiredTime>过期时间</AuthorizationCodeExpiredTime>
<PreAuthCode>预授权码</PreAuthCode>

<xml>

type AuthorizerInfo

type AuthorizerInfo struct {
	NickName        string `json:"nick_name"`
	HeadImg         string `json:"head_img"`
	ServiceTypeInfo struct {
		Id int `json:"id"`
	} `json:"service_type_info"`
	VerifyTypeInfo struct {
		Id int `json:"id"`
	} `json:"verify_type_info"`
	UserName      string `json:"user_name"`
	PrincipalName string `json:"principal_name"`
	Alias         string `json:"alias"`
	QrcodeUrl     string `json:"qrcode_url"`
	BusinessInfo  struct {
		OpenStore string `json:"open_store"`
		OpenScan  string `json:"open_scan"`
		OpenPay   string `json:"open_pay"`
		OpenCard  string `json:"open_card"`
		OpenShake string `json:"open_shake"`
	} `json:"business_info"`
	// 以下部分小程序专有
	Signature       string `json:"signature"`
	Idc             int    `json:"idc"`
	MiniProgramInfo struct {
		Network struct {
			RequestDomain   []string `json:"RequestDomain"`
			WsRequestDomain []string `json:"WsRequestDomain"`
			UploadDomain    []string `json:"UploadDomain"`
			DownloadDomain  []string `json:"DownloadDomain"`
			BizDomain       []string `json:"BizDomain"`
			UDPDomain       []string `json:"UDPDomain"`
		} `json:"network"`
		Categories  []map[string]string `json:"categories"`
		VisitStatus int                 `json:"visit_status"`
	} `json:"MiniProgramInfo"`
}

AuthorizerInfo 公众号帐号信息 参数 类型 说明 nick_name string 昵称 head_img string 头像 service_type_info object 公众号类型 verify_type_info object 公众号认证类型 user_name string 原始 ID principal_name string 主体名称 alias string 公众号所设置的微信号,可能为空 business_info object 用以了解功能的开通状况(0代表未开通,1代表已开通),详见business_info 说明 qrcode_url string 二维码图片的 URL,开发者最好自行也进行保存

business_info 说明 功能 说明 open_store 是否开通微信门店功能 open_scan 是否开通微信扫商品功能 open_pay 是否开通微信支付功能 open_card 是否开通微信卡券功能 open_shake 是否开通微信摇一摇功能

type AuthorizerInfoListModel

type AuthorizerInfoListModel struct {
	common.ErrorModel
	TotalCount int64 `json:"total_count"` // 授权的帐号总数
	List       []struct {
		AuthorizerAppid string `json:"authorizer_appid"` // 已授权的公众号或小程序的appid
		RefreshToken    string `json:"refresh_token"`    // 刷新令牌authorizer_access_token
		AuthTime        int64  `json:"auth_time"`        // 授权的时间
	} `json:"list"` // 当前查询的帐号基本信息列表
}

AuthorizerInfoListModel 返回参数说明 参数 类型 说明 total_count number 授权的帐号总数 list object array 当前查询的帐号基本信息列表 帐号基本信息 参数 类型 说明 authorizer_appid string 已授权的 appid refresh_token string 刷新令牌authorizer_access_token auth_time number 授权的时间 返回结果示例:

{
 "total_count": 33,
 "list": [
   {
     "authorizer_appid": "authorizer_appid_1",
     "refresh_token": "refresh_token_1",
     "auth_time": 1558000607
   },
   {
     "authorizer_appid": "authorizer_appid_2",
     "refresh_token": "refresh_token_2",
     "auth_time": 1558000607
   }
 ]
}

type AuthorizerInfoModel

type AuthorizerInfoModel struct {
	common.ErrorModel
	AuthorizationInfo common.AuthorizationInfo `json:"authorization_info"`
	AuthorizerInfo    AuthorizerInfo           `json:"authorizer_info"`
}

AuthorizerInfoModel 返回参数说明(公众号) 参数 类型 说明 authorization_info object 授权信息,详见authorization_info authorizer_info object 详见公众号帐号信息 公众号帐号信息 参数 类型 说明 nick_name string 昵称 head_img string 头像 service_type_info object 公众号类型 verify_type_info object 公众号认证类型 user_name string 原始 ID principal_name string 主体名称 alias string 公众号所设置的微信号,可能为空 business_info object 用以了解功能的开通状况(0代表未开通,1代表已开通),详见business_info 说明 qrcode_url string 二维码图片的 URL,开发者最好自行也进行保存 公众号类型 类型 说明 0 订阅号 1 由历史老帐号升级后的订阅号 2 服务号 公众号认证类型 类型 说明 -1 未认证 0 微信认证 1 新浪微博认证 2 腾讯微博认证 3 已资质认证通过但还未通过名称认证 4 已资质认证通过、还未通过名称认证,但通过了新浪微博认证 5 已资质认证通过、还未通过名称认证,但通过了腾讯微博认证 返回结果示例(公众号):

{
 "authorizer_info": {
   "nick_name": "微信SDK Demo Special",
   "head_img": "http://wx.qlogo.cn/mmopen/GPy",
   "service_type_info": {
     "id": 2
   },
   "verify_type_info": {
     "id": 0
   },
   "user_name": "gh_eb5e3a772040",
   "principal_name": "腾讯计算机系统有限公司",
   "business_info": {
     "open_store": 0,
     "open_scan": 0,
     "open_pay": 0,
     "open_card": 0,
     "open_shake": 0
   },
   "alias": "paytest01",
   "qrcode_url": "URL",
 },
 "authorization_info": {
   "authorizer_appid": "wxf8b4f85f3a794e77",
   "func_info": [
     {
       "funcscope_category": {
         "id": 1
       }
     },
     {
       "funcscope_category": {
         "id": 2
       }
     }
   ]
 }
}

返回参数说明(小程序) 参数 类型 说明 authorizer_info object 详见小程序帐号信息 authorization_info object 授权信息,详见authorization_info 小程序帐号信息 参数 类型 说明 nick_name string 昵称 head_img string 头像 service_type_info object id为0 verify_type_info object 小程序认证类型 user_name string 原始 ID principal_name string 主体名称 signature string 帐号介绍 business_info object 用以了解功能的开通状况(0代表未开通,1代表已开通),详见business_info 说明 qrcode_url string 二维码图片的 URL,开发者最好自行也进行保存 MiniProgramInfo object 小程序配置,根据这个字段判断是否为小程序类型授权 小程序认证类型 类型 说明 -1 未认证 0 微信认证 小程序配置说明 参数 类型 说明 network object 小程序配置的合法域名信息 categories object array 小程序配置的类目信息 返回结果示例(小程序):

{"authorizer_info":

{"nick_name":"找呀找呀找盲盒",
 "head_img":"http:xxx",
 "service_type_info":{"id":0},
 "verify_type_info":{"id":-1},
 "user_name":"gh_3dacad47dc6b",
 "alias":"",
 "qrcode_url":"http:xxx",
 "business_info":{"open_pay":0,"open_shake":0,"open_scan":0,"open_card":0,"open_store":0},
 "idc":1,"principal_name":"个人","signature":"欢迎小伙伴一起参与盲盒游戏,集齐9款鞋卡,可以兑换大奖!",
 "MiniProgramInfo":{"network":{"RequestDomain":["https:xxx","https:xxxx","https:xxx"],"WsRequestDomain":[],"UploadDomain":[],"DownloadDomain":[],"BizDomain":[],"UDPDomain":[]},
                    "categories":[{"first":"工具","second":"效率"}],"visit_status":0}},

"authorization_info":{"authorizer_appid":"wxf24d2dfc1a974128",

                      "authorizer_refresh_token":"xxxxxx",
                      "func_info":[{"funcscope_category":{"id":17}},
                                   {"funcscope_category":{"id":18},
                                    "confirm_info":{"need_confirm":0,"already_confirm":0,"can_confirm":0}},
                                   {"funcscope_category":{"id":19}},{"funcscope_category":{"id":25},"confirm_info":{"need_confirm":0,"already_confirm":0,"can_confirm":0}},
                                   {"funcscope_category":{"id":30},"confirm_info":{"need_confirm":0,"already_confirm":0,"can_confirm":0}},
                                   {"funcscope_category":{"id":31},"confirm_info":{"need_confirm":0,"already_confirm":0,"can_confirm":0}},
                                   {"funcscope_category":{"id":36}},{"funcscope_category":{"id":37}},{"funcscope_category":{"id":40}},
                                   ]}
}

type AuthorizerOption

type AuthorizerOption string
const (
	LocationReport  AuthorizerOption = "location_report"
	VoiceRecognize  AuthorizerOption = "voice_recognize"
	CustomerService AuthorizerOption = "customer_service"
)

type AuthorizerOptionModel

type AuthorizerOptionModel struct {
	common.ErrorModel
	AuthorizerAppid string `json:"authorizer_appid"` // 公众号或小程序的 appid
	OptionName      string `json:"option_name"`      // 消息类型
	OptionValue     string `json:"option_value"`     // 事件类型
}

AuthorizerOptionModel 获取授权方选项信息返回结果示例:

{
 "authorizer_appid": "wx7bc5ba58cabd00f4",
 "option_name": "voice_recognize",
 "option_value": "1"
}

选项名称及可选值说明 option_name 选项名说明 option_value 选项值说明 location_report 地理位置上报选项 0 无上报

1	            进入会话时上报
2	            每 5s 上报

voice_recognize 语音识别开关选项 0 关闭语音识别

1	            开启语音识别

customer_service 多客服开关选项 0 关闭多客服

1	            开启多客服

type AuthorizerTokenModel

type AuthorizerTokenModel struct {
	common.ErrorModel
	AuthorizerAccessToken  string `json:"authorizer_access_token"`  // 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值)
	ExpiresIn              int    `json:"expires_in"`               // 有效期,单位:秒
	AuthorizerRefreshToken string `json:"authorizer_refresh_token"` // 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。
}

AuthorizerTokenModel 获取/刷新接口调用令牌结果参数说明 参数 类型 说明 authorizer_access_token string 授权方令牌 expires_in nubmer 有效期,单位:秒 authorizer_refresh_token string 刷新令牌 返回结果示例:

{
 "authorizer_access_token": "some-access-token",
 "expires_in": 7200,
 "authorizer_refresh_token": "refresh_token_value"
}

type OpenPlatformModel

type OpenPlatformModel struct {
	common.ErrorModel
	OpenAppId string `json:"open_appid"` // 公众号或小程序的 appid
}

OpenPlatformModel 创建开放平台帐号并绑定公众号/小程序返回结果示例

{
 "open_appid": "appid_value",
 "errcode": 0,
 "errmsg": "ok"
}

type PlatformMessage

type PlatformMessage struct {
	AppId      string `xml:"AppId"`      // 第三方平台 appid
	CreateTime int64  `xml:"CreateTime"` // 时间戳,单位:s
	InfoType   string `xml:"InfoType"`   // 消息类型
}

PlatformMessage 第三方平台推送消息

type PreAuthCodeModel

type PreAuthCodeModel struct {
	common.ErrorModel
	PreAuthCode string `json:"pre_auth_code"` // 预授权码
	ExpiresIn   int    `json:"expires_in"`    // 有效期,单位:秒
}

PreAuthCodeModel 预授权码 结果参数说明 参数 类型 说明 pre_auth_code string 预授权码 expires_in number 有效期,单位:秒 返回结果示例:

{
 "pre_auth_code": "Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
 "expires_in": 600
}

type ThirdPlatform

type ThirdPlatform struct {
	*common.Api
	ThirdPlatformConfig
	// contains filtered or unexported fields
}

func NewThirdPlatform

func NewThirdPlatform(cp cache.Provider, log *log.Slf4g, cfg ThirdPlatformConfig) *ThirdPlatform

func (*ThirdPlatform) AuthorizationInfo

func (op *ThirdPlatform) AuthorizationInfo(authCode string) (t bool, aim AuthorizationInfoModel)

AuthorizationInfo 使用授权码获取授权信息 当用户在第三方平台授权页中完成授权流程后,第三方平台开发者可以在回调 URI 中通过 URL 参数获取授权码。使用以下接口可以换取公众号/小程序的授权信息。建议保存授权信息中的刷新令牌(authorizer_refresh_token)。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

注意: 公众号/小程序可以自定义选择部分权限授权给第三方平台,因此第三方平台开发者需要通过该接口来获取公众号/小程序具体授权了哪些权限,而不是简单地认为自己声明的权限就是公众号/小程序授权的权限。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 appid authorization_code string 是 授权码, 会在授权成功时返回给第三方平台,详见第三方平台授权流程说明 POST 数据示例:

{ "component_appid":"appid_value" , "authorization_code": "auth_code_value" } 返回参数详见: AuthorizationInfoModel

func (*ThirdPlatform) AuthorizerInfo

func (op *ThirdPlatform) AuthorizerInfo(authorizerAppId string) (t bool, aim AuthorizerInfoModel)

AuthorizerInfo 获取授权方的帐号基本信息 该 API 用于获取授权方的基本信息,包括头像、昵称、帐号类型、认证类型、微信号、原始ID和二维码图片URL。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

注意: 公众号和小程序的接口返回结果不一样。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 appid authorizer_appid string 是 授权方 appid POST 数据示例:

{
 "component_appid": "appid_value" ,
 "authorizer_appid": "auth_appid_value"
}

返回参数详见: AuthorizerInfoModel

func (*ThirdPlatform) AuthorizerList

func (op *ThirdPlatform) AuthorizerList(offset, count int) (t bool, ail AuthorizerInfoListModel)

AuthorizerList 拉取所有已授权的帐号信息 使用本 API 拉取当前所有已授权的帐号基本信息。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 APPID offset number 是 偏移位置/起始位置 count number 是 拉取数量,最大为 500 POST 数据示例:

{
 "component_appid": "appid_value",
 "offset": 0,
 "count": 100
}

返回参数详见: AuthorizerInfoListModel

func (*ThirdPlatform) AuthorizerOption

func (op *ThirdPlatform) AuthorizerOption(authorizerAppId string, option AuthorizerOption) (t bool, aom AuthorizerOptionModel)

AuthorizerOption 获取授权方选项信息 本 API 用于获取授权方的公众号/小程序的选项设置信息,如:地理位置上报,语音识别开关,多客服开关。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

注意: 获取各项选项设置信息,需要有授权方的授权,详见权限集说明。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 appid authorizer_appid string 是 授权公众号或小程序的 appid option_name string 是 选项名称 POST 数据示例:

{
 "component_appid": "appid_value",
 "authorizer_appid": "auth_appid_value ",
 "option_name": "option_name_value"
}

返回参数详见: AuthorizerOptionModel

func (*ThirdPlatform) AuthorizerToken

func (op *ThirdPlatform) AuthorizerToken(authorizerAppId string) (t bool)

AuthorizerToken 获取/刷新接口调用令牌 在公众号/小程序接口调用令牌(authorizer_access_token)失效时,可以使用刷新令牌(authorizer_refresh_token)获取新的接口调用令牌。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

注意: authorizer_access_token 有效期为 2 小时,开发者需要缓存 authorizer_access_token,避免获取/刷新接口调用令牌的 API 调用触发每日限额。缓存方法可以参考:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token component_appid string 是 第三方平台 appid authorizer_appid string 是 授权方 appid authorizer_refresh_token string 是 刷新令牌,获取授权信息时得到 POST 数据示例:

{
 "component_appid": "appid_value",
 "authorizer_appid": "auth_appid_value",
 "authorizer_refresh_token": "refresh_token_value"
}

返回参数详见: AuthorizerTokenModel

func (*ThirdPlatform) ClearQuota

func (op *ThirdPlatform) ClearQuota(appId string) (t bool, em common.ErrorModel)

ClearQuota 第三方平台对其所有 API 调用次数清零(只与第三方平台相关,与公众号无关,接口如 api_component_token)

POST https://api.weixin.qq.com/cgi-bin/component/clear_quota?component_access_token=COMPONENT_ACCESS_TOKEN 调用示例:

{
 "component_appid": "appid_value"
}

参数说明:

参数 是否必须 说明 component_access_token 是 调用接口凭据 component_appid 是 第三方平台 APPID 返回参数详见: common.ErrorModel

func (*ThirdPlatform) CreatePreAuthCode

func (op *ThirdPlatform) CreatePreAuthCode() (t bool, pac PreAuthCodeModel)

CreatePreAuthCode 预授权码 预授权码(pre_auth_code)是第三方平台方实现授权托管的必备信息,每个预授权码有效期为 10 分钟。需要先获取令牌才能调用。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 appid POST 数据示例:

{
 "component_appid": "appid_value"
}

返回参数详见: PreAuthCodeModel

func (*ThirdPlatform) MaskAuthorizationUrl

func (op *ThirdPlatform) MaskAuthorizationUrl(preAuthCode string) string

MaskAuthorizationUrl 下面对其进行详细介绍:

步骤 1:第三方平台方获取预授权码(pre_auth_code)

详见 步骤 2:引入用户进入授权页

第三方平台型服务商可以在自己的网站中放置“微信公众号授权”或者“小程序授权”的入口,或生成授权链接放置在移动网页中,引导公众号和小程序管理员进入授权页。

方式一:授权注册页面扫码授权

授权页网址为:

https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=xxxx&pre_auth_code=xxxxx&redirect_uri=xxxx&auth_type=xxx

参数 必填 参数说明 component_appid 是 第三方平台方 appid pre_auth_code 是 预授权码 redirect_uri 是 回调 URI auth_type 否 要授权的帐号类型, 1 则商户扫码后,手机端仅展示公众号、2 表示仅展示小程序,3 表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示。第三方平台开发者可以使用本字段来控制授权的帐号类型。 biz_appid 否 指定授权唯一的小程序或公众号

func (*ThirdPlatform) OpenBind

func (op *ThirdPlatform) OpenBind(appId, openAppId string) (bool, common.ErrorModel)

OpenBind 将公众号/小程序绑定到开放平台帐号下 该 API 用于将一个尚未绑定开放平台帐号的公众号或小程序绑定至指定开放平台帐号上。二者须主体相同。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/open/bind?access_token=xxxx 请求参数说明 参数 类型 必填 说明 access_token String 是 第三方平台接口调用令牌authorizer_access_token appid String 是 授权公众号或小程序的 appid open_appid String 是 开放平台帐号 appid,由创建开发平台帐号接口返回 POST 数据示例

{
 "appid": "auth_appid_value",
 "open_appid": "open_appid_value"
}

返回参数详见: common.ErrorModel

func (*ThirdPlatform) OpenCreate

func (op *ThirdPlatform) OpenCreate(appId string) (t bool, ocm OpenPlatformModel)

OpenCreate 创建开放平台帐号并绑定公众号/小程序 该 API 用于创建一个开放平台帐号,并将一个尚未绑定开放平台帐号的公众号/小程序绑定至该开放平台帐号上。新创建的开放平台帐号的主体信息将设置为与之绑定的公众号或小程序的主体。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/open/create?access_token=ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 access_token String 是 第三方平台接口调用令牌authorizer_access_token appid String 是 授权公众号或小程序的 appid POST 数据示例

{
 "appid": "auth_appid_value"
}

返回参数详见: OpenPlatformModel

func (*ThirdPlatform) OpenGet

func (op *ThirdPlatform) OpenGet(appId string) (t bool, ocm OpenPlatformModel)

OpenGet 获取公众号/小程序所绑定的开放平台帐号 该 API 用于获取公众号或小程序所绑定的开放平台帐号。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/open/get?access_token=ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 access_token String 是 第三方平台接口调用令牌authorizer_access_token appid String 是 授权公众号或小程序的 appid POST 数据示例

{
 "appid": "auth_appid_value"
}

返回参数详见: OpenPlatformModel

func (*ThirdPlatform) OpenUnbind

func (op *ThirdPlatform) OpenUnbind(appId, openAppId string) (bool, common.ErrorModel)

OpenUnbind 将公众号/小程序从开放平台帐号下解绑 该 API 用于将一个公众号或小程序与指定开放平台帐号解绑。开发者须确认所指定帐号与当前该公众号或小程序所绑定的开放平台帐号一致。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

请求地址 POST https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 access_token String 是 第三方平台接口调用令牌authorizer_access_token appid String 是 授权公众号或小程序的 appid open_appid String 是 开放平台帐号 appid,由创建开发平台帐号接口返回 POST 数据示例

{
 "appid": "auth_appid_value",
 "open_appid": "open_appid_value"
}

返回参数详见: common.ErrorModel

func (*ThirdPlatform) SetAuthorizerOption

func (op *ThirdPlatform) SetAuthorizerOption(authorizerAppId string, option AuthorizerOption, value string) (t bool, em common.ErrorModel)

SetAuthorizerOption 设置授权方选项信息 本 API 用于设置授权方的公众号/小程序的选项信息,如:地理位置上报,语音识别开关,多客服开关。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

注意: 设置各项选项设置信息,需要有授权方的授权,详见权限集说明。

请求地址 POST https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option?component_access_token=COMPONENT_ACCESS_TOKEN 请求参数说明 参数 类型 必填 说明 component_access_token string 是 第三方平台component_access_token,不是authorizer_access_token component_appid string 是 第三方平台 appid authorizer_appid string 是 授权公众号或小程序的 appid option_name string 是 选项名称 option_value string 是 设置的选项值 POST 数据示例:

{
 "component_appid": "appid_value",
 "authorizer_appid": "auth_appid_value ",
 "option_name": "option_name_value",
 "option_value": "option_value_value"
}

返回参数详见: common.ErrorModel

func (*ThirdPlatform) SyncToken

func (op *ThirdPlatform) SyncToken(ticket string) bool

SyncToken 令牌 令牌(component_access_token)是第三方平台接口的调用凭据。令牌的获取是有限制的,每个令牌的有效期为 2 小时,请自行做好令牌的管理,在令牌快过期时(比如1小时50分),重新调用接口获取。

如未特殊说明,令牌一般作为被调用接口的 GET 参数 component_access_token 的值使用

请求地址(POST)https://api.weixin.qq.com/cgi-bin/component/api_component_token 参数 类型 必填 说明 component_appid string 是 第三方平台 appid component_appsecret string 是 第三方平台 appsecret component_verify_ticket string 是 微信后台推送的 ticket 数据示例:

{
 "component_appid":  "appid_value" ,
 "component_appsecret":  "appsecret_value",
 "component_verify_ticket": "ticket_value"
}

返回详情: TokenModel

type ThirdPlatformAdapter

type ThirdPlatformAdapter interface {
	VerifyTicketMessageAdapter() common.Adapter
	AuthorizationMessageAdapter() common.Adapter
}

ThirdPlatformAdapter 以下为第三方平台(Third)

type ThirdPlatformConfig

type ThirdPlatformConfig struct {
	AppId            string   `json:"appId"`
	Secret           string   `json:"secret"`
	Token            string   `json:"token"`
	AesKey           string   `json:"aesKey"`
	AuthorizationUrl string   `json:"authorizationUrl"`
	Refreshed        []string `json:"refreshed"`
}

type TokenModel

type TokenModel struct {
	common.ErrorModel
	AccessToken string `json:"component_access_token"` // 第三方平台 access_token
	ExpiresIn   int    `json:"expires_in"`             // 有效期,单位:秒
}

TokenModel 令牌结果参数说明 参数 类型 说明 component_access_token string 第三方平台 access_token expires_in number 有效期,单位:秒 结果示例:

{
 "component_access_token": "61W3mEpU66027wgNZ_MhGHNQDHnFATkDa9-2llqrMBjUwxRSNPbVsMmyD-yq8wZETSoE5NQgecigDrSHkPtIYA",
 "expires_in": 7200
}

type VerifyTicketMessage

type VerifyTicketMessage struct {
	PlatformMessage
	ComponentVerifyTicket string `xml:"ComponentVerifyTicket"` // Ticket 内容
}

VerifyTicketMessage 票据示例: <xml> <AppId>some_appid</AppId> <CreateTime>1413192605</CreateTime> <InfoType>component_verify_ticket</InfoType> <ComponentVerifyTicket>some_verify_ticket</ComponentVerifyTicket> </xml> 详情:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/component_verify_ticket.html

Jump to

Keyboard shortcuts

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