HttpBaseController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Http\Home;
  3. use App\Traits\CommonTrait;
  4. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  5. use Illuminate\Foundation\Bus\DispatchesJobs;
  6. use Illuminate\Foundation\Validation\ValidatesRequests;
  7. use Illuminate\Routing\Controller as BaseController;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Request;
  10. use Illuminate\Support\Facades\View;
  11. use Alipay\EasySDK\Kernel\Config;
  12. use Illuminate\Support\Facades\Log;
  13. class HttpBaseController extends BaseController
  14. {
  15. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  16. use CommonTrait;
  17. /**
  18. * @var array|null 已经登录的用户信息
  19. */
  20. public ?array $userInfo;
  21. /**
  22. * @var array
  23. */
  24. public array $seoData = [
  25. 'title' => '星优办公软件',
  26. 'keywords' => '星优办公',
  27. 'description' => '【星优办公软件】提供各种办公工具。',
  28. ];
  29. public function __construct()
  30. {
  31. //
  32. if ($test = $this->isTest()) {
  33. $url = \request()->getScheme() . '://' . $test;
  34. } else {
  35. $url = \request()->getScheme() . '://www.xingyousoft.com';
  36. }
  37. View::share('target', $url);
  38. View::share($this->seoData);
  39. }
  40. /**
  41. * 判断是否是测试环境
  42. *
  43. * @return false|string
  44. */
  45. public function isTest(): bool|string
  46. {
  47. $url = \request()->getHttpHost();
  48. if ($url == 'www.xingyousoft.me' || $url == 'audio.xingyousoft.me' || $url == 'pdf.xingyousoft.me' || $url == 'audio.xingyousoft.com') {
  49. return $url;
  50. } else {
  51. return false;
  52. }
  53. }
  54. /**
  55. * 获取产品信息
  56. *
  57. * @param string $pmid
  58. * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null
  59. */
  60. public function getProductInfo(string $pmid)
  61. {
  62. return DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
  63. }
  64. /**
  65. * 获取版本信息
  66. *
  67. * @param $productId
  68. * @param string $osType
  69. * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null
  70. */
  71. public function getProductVersion($productId, string $osType = 'windows')
  72. {
  73. // 如果有相同的版本,则获取最后一条 orderby
  74. return DB::table('product_version')
  75. ->where('product_id', $productId)
  76. ->where('os_type', $osType)
  77. ->where('is_delete', 0)
  78. ->orderBy("id", "desc")->first();
  79. }
  80. public function getAlipayOptions()
  81. {
  82. $configArr = config('alipay');
  83. $options = new Config();
  84. $options->protocol = 'https';
  85. $options->gatewayHost = 'openapi.alipay.com';
  86. $options->signType = 'RSA2';
  87. $options->appId = $configArr['app_id'];
  88. // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
  89. $options->merchantPrivateKey = file_get_contents($configArr['private_key']);
  90. $options->alipayCertPath = $configArr['alipay_cert_public_key_rsa2'];//'<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
  91. $options->alipayRootCertPath = $configArr['alipay_root_cert'];//'<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
  92. $options->merchantCertPath = $configArr['app_cert_public_key'];//'<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';
  93. //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
  94. //$options->alipayPublicKey = $configArr['ali_public_key'];
  95. //可设置异步通知接收服务地址(可选)
  96. $options->notifyUrl = $configArr['notify_url'];
  97. //可设置AES密钥,调用AES加解密相关接口时需要(可选)
  98. // $options->encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->";
  99. return $options;
  100. }
  101. }