accesstoken.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. error_reporting(0);
  3. define('IN_SYS', true);
  4. define('WECHATS', 1);
  5. define('WXAPP', 4);
  6. function account_tablename($type) {
  7. $account_types = array(
  8. WECHATS => 'account_wechats',
  9. WXAPP => 'account_wxapp',
  10. );
  11. return !empty($account_types[$type]) ? $account_types[$type] : '';
  12. }
  13. require '../framework/bootstrap.inc.php';
  14. parse_str($_SERVER['QUERY_STRING'], $query);
  15. if(is_array($query) && count($query) == 3 && in_array($query['type'], array(WECHATS, WXAPP)) && !empty($query['appid']) && !empty($query['secret'])) {
  16. $table_name = account_tablename($query['type']);
  17. if (empty($table_name)) {
  18. exit('Invalid Type');
  19. }
  20. $account_info = pdo_get($table_name, array('key' => $query['appid']));
  21. if (empty($account_info) || empty($account_info['uniacid'])) {
  22. exit('Appid Not Found');
  23. }
  24. $account_api = WeAccount::createByUniacid($account_info['uniacid']);
  25. $result = array('accesstoken' => $account_api->getAccessToken());
  26. echo json_encode($result);
  27. exit;
  28. }
  29. exit('Invalid Request');