Client.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * This file is part of the overtrue/wechat.
  9. *
  10. * (c) overtrue <i@overtrue.me>
  11. *
  12. * This source file is subject to the MIT license that is bundled
  13. * with this source code in the file LICENSE.
  14. */
  15. namespace ByteDance\MiniProgram\Auth;
  16. use ByteDance\Kernel\BaseClient;
  17. /**
  18. * Class Auth.
  19. *
  20. * @author mingyoung <mingyoungcheung@gmail.com>
  21. */
  22. class Client extends BaseClient
  23. {
  24. /**
  25. * Get session info by code.
  26. *
  27. * @param string $code
  28. *
  29. * @throws \ByteDance\Kernel\Exceptions\InvalidConfigException
  30. *
  31. * @return \Psr\Http\Message\ResponseInterface|\ByteDance\Kernel\Support\Collection|array|object|string
  32. */
  33. public function session(string $code, bool $anonymous = false)
  34. {
  35. $params = [
  36. 'appid' => $this->app['config']['app_id'],
  37. 'secret' => $this->app['config']['app_secret'],
  38. ];
  39. if ($anonymous) {
  40. $params['anonymous_code'] = $code;
  41. } else {
  42. $params['code'] = $code;
  43. }
  44. return $this->httpGet('api/apps/jscode2session', $params);
  45. }
  46. }