toutiaoapp.account.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class ToutiaoappAccount extends WeAccount {
  8. protected $tablename = 'account_toutiaoapp';
  9. protected $menuFrame = 'wxapp';
  10. protected $type = ACCOUNT_TYPE_TOUTIAOAPP_NORMAL;
  11. protected $typeName = '抖音小程序';
  12. protected $typeTempalte = '-toutiaoapp';
  13. protected $typeSign = TOUTIAOAPP_TYPE_SIGN;
  14. protected $supportVersion = STATUS_ON;
  15. protected function getAccountInfo($uniacid) {
  16. return table('account_toutiaoapp')->getAccount($uniacid);
  17. }
  18. public function getAccessToken() {
  19. global $_W;
  20. $cachekey = cache_system_key('accesstoken', array('uniacid' => $this->account['uniacid']));
  21. $cache = cache_load($cachekey);
  22. if (!empty($cache) && !empty($cache['token'])) {
  23. $this->account['access_token'] = $cache;
  24. return $cache['token'];
  25. }
  26. if (empty($this->account['link'])) {
  27. return error(-1, '参数错误!');
  28. }
  29. load()->library('sdk-module');
  30. $link_config = iunserializer($this->account['link_config']);
  31. try {
  32. $api = new \W7\Sdk\Module\Api($_W['setting']['site']['key'], $_W['setting']['site']['token'], $link_config['app_id'], 7, CLOUD_V3API_DOMAIN_PRE);
  33. $token = $api->app()->getAccessToken()->toArray();
  34. } catch (Exception $e) {
  35. return error('-1', $e->getMessage());
  36. }
  37. $record = array();
  38. $record['token'] = $token['access_token'];
  39. $record_expire = $token['expires_in'] - 200;
  40. $this->account['access_token'] = $record;
  41. cache_write($cachekey, $record, $record_expire);
  42. return $record['token'];
  43. }
  44. }