HttpBaseController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Api;
  3. use Alipay\EasySDK\Kernel\Config;
  4. use App\Services\Login\LoginTokenService;
  5. use App\Services\OrderService\ComboOrderService;
  6. use App\Services\OrderService\GoodsOrderService;
  7. use App\Traits\CommonTrait;
  8. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  9. use Illuminate\Foundation\Bus\DispatchesJobs;
  10. use Illuminate\Foundation\Validation\ValidatesRequests;
  11. use Illuminate\Routing\Controller as BaseController;
  12. class HttpBaseController extends BaseController
  13. {
  14. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  15. use CommonTrait;
  16. /**
  17. * 登录的token名称
  18. *
  19. * @var string
  20. */
  21. public string $sanctumTokenName = 'api';
  22. /**
  23. * @var array
  24. */
  25. public array $seoData = [
  26. 'title' => '',
  27. 'keywords' => '',
  28. 'description' => '【】。',
  29. ];
  30. public function __construct()
  31. {
  32. }
  33. /**
  34. * 判断该用户是否已经登录
  35. */
  36. public function isLoginJson()
  37. {
  38. $loginToken = new LoginTokenService('user_access_token');
  39. $this->tokenInfo = $loginToken->checkLogin();
  40. if (empty($this->tokenInfo)) {
  41. abort(401, '你还没有登录,请登录!');
  42. } else {
  43. $this->userId = $this->tokenInfo->user_id;
  44. }
  45. }
  46. public function getOptions()
  47. {
  48. $configArr = config('alipay');
  49. $options = new Config();
  50. $options->protocol = 'https';
  51. $options->gatewayHost = 'openapi.alipay.com';
  52. $options->signType = 'RSA2';
  53. $options->appId = $configArr['app_id'];
  54. // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
  55. $options->merchantPrivateKey = $configArr['private_key'];
  56. $options->alipayCertPath = $configArr['alipay_cert_public_key_rsa2'];//'<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
  57. $options->alipayRootCertPath = $configArr['alipay_root_cert'];//'<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
  58. $options->merchantCertPath = $configArr['app_cert_public_key'];//'<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';
  59. //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
  60. $options->alipayPublicKey = $configArr['ali_public_key'];
  61. //可设置异步通知接收服务地址(可选)
  62. $options->notifyUrl = $configArr['notify_url'];
  63. //可设置AES密钥,调用AES加解密相关接口时需要(可选)
  64. // $options->encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->";
  65. return $options;
  66. }
  67. /**
  68. * 判断是否是测试环境
  69. *
  70. * @return bool
  71. */
  72. public function isTest()
  73. {
  74. $url = \request()->getHttpHost();
  75. if ($url == 'www.yososoft.me' || $url == 'audio.yososoft.me' || $url == 'audio.zhuyou360.com') {
  76. return $url;
  77. } else {
  78. return false;
  79. }
  80. }
  81. }