• esaywechat 源码分析


    业务需求:公众号授权给第三方平台。

    方案:用esaywechat 快速开发微信开放平台“第三方平台”。

    坑1:查看esaywechat “开放平台”文档,文档很简洁,一些需要的api并没有写到(但是人家肯定已经实现了)

    例:获取授权方令牌authorizer_access_token,文档并没有写,这时需要自己从源码里面找到。

    1. 全局搜索  authorizer_access_token

    class AccessToken: protected $tokenKey = 'authorizer_access_token'; 
    =》
    父类 abstract class AccessToken:protected $tokenKey = 'access_token';
    public function getToken(bool $refresh = false): array
    {
    $cacheKey = $this->getCacheKey();
    $cache = $this->getCache(); //这里是获取缓存,可以看看他怎么实现的

    if (!$refresh && $cache->has($cacheKey)) {
    return $cache->get($cacheKey);
    }

    $token = $this->requestToken($this->getCredentials(), true);

    $this->setToken($token[$this->tokenKey], $token['expires_in'] ?? 7200);

    return $token;
    }

    找到父类里有getToken方法,非常鸡冻试试这个

    于是,new AccessToken(); 但是子类构造器需要传参
    /**
    * AuthorizerAccessToken constructor.
    *
    * @param PimpleContainer $app
    * @param EasyWeChatOpenPlatformApplication $component
    */
    public function __construct(Container $app, Application $component)
    {
    parent::__construct($app);

    $this->component = $component;
    }

    。。这是什么参数。。头大。
    Container $app 是来自第依赖包类
    Application $component 是easywechat 自己的。
    继续向下找,这两个类又需要传各种参数。。不能这么玩,改变思路。

    2. easywechat 对外暴露的只有Factory类,我们参考文档如何获取access_token$openPlatform对象去获取authorizer_access_token

      $openPlatform = Factory::openPlatform($this->config);

    思想:获取access_token和获取authorizer_access_token都是实现同一个接口同一个规范,用的时候可以参考之前写过的文档

     
     
     


  • 相关阅读:
    C#Winform中treeView控件使用总结
    转:vs发布window应用程序时出错:未能签名 ...setup.exe
    C# 常见集合之前的转换
    开发者眼中的Spring与JavaEE
    运行库到底做了什么?
    C++, Java和C#的编译、链接过程解析
    转载一篇将C/C++ 与lua混合使用入门讲的比较好的文章
    路会越走越窄的
    [DBNETLIB][ConnectionOpen(Connect()).]SQL Server 不存在或拒绝访问 数据库错误 解决办法总结
    Linux学习路线指南
  • 原文地址:https://www.cnblogs.com/wangyuyanhello/p/9182168.html
Copyright © 2020-2023  润新知