资讯专栏INFORMATION COLUMN

微信公众号第三方开发平台(二)

hearaway / 3700人阅读

摘要:微信公众号第三方开发平台一之前的文章是获取调用接口的一些基本参数,继续开发微信开放平台。

微信公众号第三方开发平台(一)

之前的文章是获取调用接口的一些基本参数,继续开发微信开放平台。

一、授权公众号,获取公众号的授权参数
    public function tiaozhuan()
    {
        $info = getData("system_config", array("type" => "pre_auth_code"), array(), 1);    ////获取保存在数据库中的pre_auth_code
        $pre_auth_code = $info["value"];
        $back_url = "http://www.xxxxxx.com/index.php/$APPID$/callback";   //后台设置的回调地址,用户扫完二维码之后会跳转到这个连接    
        $url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=wxcda7bf3c4bf44cdc&pre_auth_code=".$pre_auth_code."&redirect_uri=".$back_url;
        header("Location:".$url);
    }
二、在回调地址中,获取公众号access,并获取公众号的信息
    //保存公众号信息
    private function saveOpenWeixin()
    {
        //获取公众号access
        $info = getData("system_config", array("type" => "component_access_token"), array() , 1); //获取保存在数据库中的component_access_token
        $component_access_token = $info["value"];
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=".$component_access_token;
        $auth_code = $_GET["auth_code"];
        $post = array(
            "component_appid" => $this->appid,    //应用的appid
            "authorization_code"    => $auth_code,
        );
        $ret=send_post($url, $post);
        $author = json_decode($ret, True);
        //获取公众号信息
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=".$component_access_token;
        $authorAppid = $author["authorization_info"]["authorizer_appid"];
        $post = array(
            "component_appid" => $this->appid,
            "authorizer_appid" => $authorAppid,
        );
        $ret = send_post($url, $post);
        $userInfo = json_decode($ret, True);
        
        //公众号信息
        $authorInfo = $author["authorization_info"];

    }
三、使用公众号的基本信息调用接口
//获取授权方的公众号帐号基本信息
    public function demo6()
    {
        $info = getData("system_config", array("type" => "component_access_token"), array(), 1);  //获取保存在数据库中的component_access_token
        $token = $info["value"];
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=".$token;
        $post = array(
            "component_appid" => $this->appid,
            "authorizer_appid" => "xxxxxxxxxx",  //公众号appid
        );
        $ret = send_post($url, $post);
        $res = json_decode($ret, True);
    }
    
    //微信账号网页授权
    public function demo8()
    {
        $appid = "xxxx"; //公众号的appid
        $redirect = site_url("toupiao/".$appid."/callback");
        //$scope = "snsapi_base";
        $scope = "snsapi_userinfo";   //获取方式
        $state = "omllz";
        $component_appid = $this->appid;  //应用的appid
        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect."&response_type=code&scope=".$scope."&state=".$state."&component_appid=".$component_appid."#wechat_redirect";
        header("Location:".$url);
    }

这是我的个人网站今日Tech 喜欢科技新闻的朋友可以收藏下。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/22141.html

相关文章

  • 微信公众支付开发全过程(java版)

    摘要:一微信官方文档微信支付开发流程公众号支付首先我们到微信支付的官方文档的开发步骤部分查看一下需要的设置。配置微信公众账号支付配置支付类所有方法都在这个类里发起支付微信公众账号支付订单异步回调这就是这个所说的行代码解决微信支付。 文章有不当之处,欢迎指正,如果喜欢微信阅读,你也可以关注我的微信公众号:好好学java,获取优质学习资源。 一、微信官方文档微信支付开发流程(公众号支付) 首先我...

    Shimmer 评论0 收藏0
  • 微信公众三方开发平台(一)

    摘要:二接收微信调用任何接口都需要这一步也是折腾我最久的,主要推送过来的信息是加密的我们需要将信息解密,解密出将该保存后面需要用到消息加解密接入指引这个页面上可以下载对应语言解密的我选择的是,貌似有点问题,自己改了下可以用了。 最近在做一个公众号的工具,想使用公众号的权限,第一步就是授权,官方的文档说的不是很清楚,对于一个刚接触的开发者看起来是有点吃力的。 一、创建微信第三方应用 showI...

    why_rookie 评论0 收藏0
  • RageFrame 一个 Yii2 + AdminLET 免费开源多商户通用后台管理系统

    摘要:极致的插件机制,系统内的系统,安装和卸载不会对原来的系统产生影响强大的功能完全满足各阶段的需求,支持用户多端访问后台微信前台等,系统中的系统。多入口模式,多入口分为后台前端,微信,对内接口,对外接口,不同的业务,不同的设备,进入不同的入口。 RageFrame 2.0 为二次开发而生,让开发变得更简单 项目地址:https://github.com/jianyan74/... 前言 这...

    sunny5541 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<