公众号第三方平台开发 教程三 微信公众号授权第三方平台

公众号第三方平台开发 教程一 创建公众号第三方平台

公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取

公众号第三方平台开发 教程三 微信公众号授权第三方平台

公众号第三方平台开发 教程四 代公众号发起网页授权说明

公众号第三方平台开发 教程五 代公众号处理消息和事件

公众号第三方平台开发 教程六 代公众号使用JS SDK说明

另,感谢一下这个大虾的博客,这几篇东西都是在他的博文基础上完成的,他的博客里也有一些接口代码可以下载
微信开发系列教程

 

 

这一部分挺简单的,其实就是在页面上放一个链接,引导用户跳转即可

链接的格式如下:

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

这里对参数做一下说明

component_appid即第三方平台的APPID(如下图)

pre_auth_code为预授权码,用获得的第三方平台AccessToken作为参数进行获取,具体看下面的代码

redirect_uri为用户同意授权之后跳转的链接,同时会向该页面发送用户的授权码auth_code,通过这个授权码即可请求到公众号的授权信息

获取预授权码的函数

        /// <summary>
        /// 用于获取预授权码。预授权码用于公众号授权时的第三方平台方安全验证
        /// </summary>
        /// <param name="component_verify_ticket"></param>
        /// <returns></returns>
        public static ResponseCreatePreauthCode Create_preauthcode(string component_access_token)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token={0}";
            object data = null;
            data = new
            {
                component_appid = Config.ServerAppID,
            };
            return CommonJsonSend.Send<ResponseCreatePreauthCode>(component_access_token, urlFormat, data, timeOut: Config.TIME_OUT);
        }

 

 返回结果示例

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

 

获得用户授权码之后,用auth_Code作为参数请求公众号信息。

component_access_token为第三方平台accessToken 

        /// <summary>
        /// 使用授权码换取公众号的授权信息
        /// </summary>
        /// <param name="component_access_token"></param>
        /// <returns></returns>
        public static PublicWechatAuthorizerInfo Query_auth(string component_access_token, string auth_code_value)
        {
            var urlFormat = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token={0}";
            object data = null;
            data = new
            {
                component_appid = Config.ServerAppID,
                authorization_code = auth_code_value
            };
            return CommonJsonSend.Send<PublicWechatAuthorizerInfo>(component_access_token, urlFormat, data, timeOut: Config.TIME_OUT);
        }

 返回结果示例


"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
}
}
]
}

转载于:https://www.cnblogs.com/iCoffee/p/4813830.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值