HttpBaseController.php 3.2 KB

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