zoukankan      html  css  js  c++  java
  • 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都是实现同一个接口同一个规范,用的时候可以参考之前写过的文档

     
     
     


  • 相关阅读:
    Delphi/XE2 使用TIdHttp控件下载Https协议服务器文件[转]
    [Delphi]实现使用TIdHttp控件向https地址Post请求[转]
    让PowerShell用上Git
    解答WPF中ComboBox SelectedItem Binding不上的Bug
    那么小伙伴么,问题来了,WPF中,控件的Width="*"在后台怎么写?
    WPF Adorner+附加属性 实现控件友好提示
    关于Mvvm的一些深入理解
    第一个WP8程序,照相机
    夜深了,我们为什么加班(转载)
    Linux学习-SRPM 的使用 : rpmbuild (Optional)
  • 原文地址:https://www.cnblogs.com/wangyuyanhello/p/9182168.html
Copyright © 2011-2022 走看看