微信第三方平台接口

2019-04-10  本文已影响0人  会飞一下

第三方平台开发流程

image.png

整个流程是第三方平台 提供一个授权的页面供公众号|小程序管理员进行授权, 授权后第三方平台将获得 授权方(公众号|小程序)的以下信息

authorization_info //授权信息
authorizer_appid  //授权方appid
authorizer_access_token   //access_token
expires_in
authorizer_refresh_token
func_info  // 授权的权限列表

然后用获取的 authorizer_appid 及authorizer_access_token 代授权方调用相应的接口

按开放平台的文档上说, 公众号授权第三方平台管理后,微信服务器会将粉丝发给公众号的消息,以及微信服务器发给公众号的事件推送(如自定义菜单点击事件、粉丝取消关注通知等),发给开发者服务器(会发送到公众号消息与事件接收URL,详见申请资料说明页)上 . 也就是说第三方平台会接管消息接口 ,

关键参数

  1. component_verify_ticket
    第三方平台创建审核通过后, 微信服务器每10分钟推送给第三方平台
<xml>
<AppId> </AppId>
<CreateTime>1413192605 </CreateTime>
<InfoType> </InfoType>
<ComponentVerifyTicket> </ComponentVerifyTicket>
</xml>
  1. component_access_token
    第三方平台的所有接口都需要此token调用, 生成方式:
url:https://api.weixin.qq.com/cgi-bin/component/api_component_token
post:
{
    "component_appid": "appid_value",
    "component_appsecret": "appsecret_value",
    "component_verify_ticket": "ticket_value"
}
return:
{
    "component_access_token": "61W3mEpU66027wgNZ_MhGHNQDHnFATkDa9-2llqrMBjUwxRSNPbVsMmyD-yq8wZETSoE5NQgecigDrSHkPtIYA",
    "expires_in": 7200
}
  1. pre_auth_code
    预授权码, 授权时的参数, 生成方式:
url:
https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=xxx
post:
{
    "component_appid": "appid_value"
}

return:
{
    "pre_auth_code": "Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
    "expires_in": 600
}
  1. auth_code
    授权回调参数, 生成方式
url:
 https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&auth_type=3&no_scan=1&component_appid=xxxx&pre_auth_code=xxxxx&redirect_uri=xxxx&auth_type=xxx&biz_appid=xxxx#wechat_redirect

return :
https://redirect_url/?auth_code=xxx&expires_in=600
  1. authorizer_appid , authorizer_access_token..
    用户授权后 通过回调的 auth_code ,expires_in 获取授权方的appid , access_token 用于代授权方公众号|小程序调用接口
url:
https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=xxxx
post:
{
    "component_appid": "appid_value",
    "authorization_code": "auth_code"
}

return :
{
    "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
                }
            }
        ]
    }
}
  1. 刷新 authorizer_access_token
url:
https:// api.weixin.qq.com /cgi-bin/component/api_authorizer_token?component_access_token=xxxxx

post:
{
    "component_appid": "appid_value",
    "authorizer_appid": "auth_appid_value",
    "authorizer_refresh_token": "refresh_token_value"
}
reutrn :
{
    "authorizer_access_token": "aaUl5s6kAByLwgV0BhXNuIFFUqfrR8vTATsoSHukcIGqJgrc4KmMJ-JlKoC_-NKCLBvuU1cWPv4vDcLN8Z0pn5I45mpATruU0b51hzeT1f8",
    "expires_in": 7200,
    "authorizer_refresh_token": "BstnRqgTJBXb9N2aJq6L5hzfJwP406tpfahQeLNxX0w"
}
  1. 获取授权帐号信息
url:
https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=xxxx
post:
{
    "component_appid": "appid_value",
    "authorizer_appid": "auth_appid_value"
}
return:
{
    "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": {
        "authorization_appid": "wxf8b4f85f3a794e77",
        "func_info": [
            {
                "funcscope_category": {
                    "id": 1
                }
            },
            {
                "funcscope_category": {
                    "id": 2
                }
            },
            {
                "funcscope_category": {
                    "id": 3
                }
            }
        ]
    }
}

  1. 获取授权方的选项设置信息
url:
https://api.weixin.qq.com/cgi-bin/component/ api_get_authorizer_option?component_access_token=xxxx
post:
{
    "component_appid": "appid_value",
    "authorizer_appid": " auth_appid_value ",
    "option_name": "option_name_value"
}

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

option 值:

option_name option_value 选项值说明
location_report(地理位置上报选项) 0 无上报
location_report(地理位置上报选项) 1 进入会话时上报
location_report(地理位置上报选项) 2 每5s上报
voice_recognize(语音识别开关选项) 0 关闭语音识别
voice_recognize(语音识别开关选项) 1 开启语音识别
customer_service(多客服开关选项) 0 关闭多客服
customer_service(多客服开关选项) 1 开启多客服
  1. 设置授权方的选项信息
url:
https://api.weixin.qq.com/cgi-bin/component/ api_set_authorizer_option?component_access_token=xxxx
post:
{
"component_appid":"appid_value",
"authorizer_appid": " auth_appid_value ",
"option_name": "option_name_value",
"option_value":"option_value_value"
}
return:
{
"errcode":0,
"errmsg":"ok"
}
  1. 授权通知
    公众号|小程序在授权页进行操作时, 微信服务器将事件推送给第三方平台设定的url
<xml>
<AppId>第三方平台appid</AppId>
<CreateTime>1413192760</CreateTime>
<InfoType>authorized</InfoType>
<AuthorizerAppid>公众号appid</AuthorizerAppid>
<AuthorizationCode>授权码(code)</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>授权码(code)</AuthorizationCode>
<AuthorizationCodeExpiredTime>过期时间</AuthorizationCodeExpiredTime>
<PreAuthCode>预授权码</PreAuthCode>
<xml>
-- --
字段名称 字段描述
AppId 第三方平台appid
CreateTime 时间戳
InfoType unauthorized是取消授权,updateauthorized是更新授权,authorized是授权成功通知
AuthorizerAppid 公众号或小程序
AuthorizationCode 授权码,可用于换取公众号的接口调用凭据,详细见上面的说明
AuthorizationCodeExpiredTime 授权码过期时间
PreAuthCode 预授权码
  1. 拉取当前所有已授权的帐号基本信息
url:
https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token=COMPONENT_ACCESS_TOKEN
post:
{
    "component_appid": "appid_value",
    "offset": 0,
    "count": 100
}

return:
{
    "total_count": 33,
    "list": [
        {
            "authorizer_appid": "authorizer_appid_1",
            "refresh_token": "refresh_token_1",
            "auth_time": "auth_time_1"
        },
        {
            "authorizer_appid": "authorizer_appid_2",
            "refresh_token": "refresh_token_2",
            "auth_time": "auth_time_2"
        }
    ]
}
上一篇 下一篇

猜你喜欢

热点阅读