国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0KB

  1. <?php
  2. namespace WeChat\Contracts;
  3. if (!defined('DEDEINC')) exit ('dedebiz');
  4. /**
  5. * 企业微信基础类
  6. * Class BasicWeWork
  7. * @package WeChat\Contracts
  8. */
  9. class BasicWeWork extends BasicWeChat
  10. {
  11. /**
  12. * 获取访问 AccessToken
  13. * @return string
  14. * @throws \WeChat\Exceptions\InvalidResponseException
  15. * @throws \WeChat\Exceptions\LocalCacheException
  16. */
  17. public function getAccessToken()
  18. {
  19. if ($this->access_token) return $this->access_token;
  20. $ckey = $this->config->get('appid').'_access_token';
  21. if ($this->access_token = Tools::getCache($ckey)) return $this->access_token;
  22. list($appid, $secret) = [$this->config->get('appid'), $this->config->get('appsecret')];
  23. $result = Tools::json2arr(Tools::get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$appid}&corpsecret={$secret}"));
  24. if (isset($result['access_token']) && $result['access_token']) Tools::setCache($ckey, $result['access_token'], 7000);
  25. return $this->access_token = $result['access_token'];
  26. }
  27. }
  28. ?>