123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace App\Http\Home;
- use App\Traits\CommonTrait;
- use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
- use Illuminate\Foundation\Bus\DispatchesJobs;
- use Illuminate\Foundation\Validation\ValidatesRequests;
- use Illuminate\Routing\Controller as BaseController;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- use Illuminate\Support\Facades\View;
- use Alipay\EasySDK\Kernel\Config;
- use Illuminate\Support\Facades\Log;
- class HttpBaseController extends BaseController
- {
- use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
- use CommonTrait;
- /**
- * @var array|null 已经登录的用户信息
- */
- public ?array $userInfo;
- /**
- * @var array
- */
- public array $seoData = [
- 'title' => '星优办公软件',
- 'keywords' => '星优办公',
- 'description' => '【星优办公软件】提供各种办公工具。',
- ];
- public function __construct()
- {
- //
- if ($test = $this->isTest()) {
- $url = \request()->getScheme() . '://' . $test;
- } else {
- $url = \request()->getScheme() . '://www.xingyousoft.com';
- }
- View::share('target', $url);
- View::share($this->seoData);
- }
- /**
- * 判断是否是测试环境
- *
- * @return false|string
- */
- public function isTest(): bool|string
- {
- $url = \request()->getHttpHost();
- if ($url == 'www.xingyousoft.me' || $url == 'audio.xingyousoft.me' || $url == 'pdf.xingyousoft.me' || $url == 'audio.xingyousoft.com') {
- return $url;
- } else {
- return false;
- }
- }
- /**
- * 获取产品信息
- *
- * @param string $pmid
- * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null
- */
- public function getProductInfo(string $pmid)
- {
- return DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
- }
- /**
- * 获取版本信息
- *
- * @param $productId
- * @param string $osType
- * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null
- */
- public function getProductVersion($productId, string $osType = 'windows')
- {
- // 如果有相同的版本,则获取最后一条 orderby
- return DB::table('product_version')
- ->where('product_id', $productId)
- ->where('os_type', $osType)
- ->where('is_delete', 0)
- ->orderBy("id", "desc")->first();
- }
- public function getAlipayOptions()
- {
- $configArr = config('alipay');
- $options = new Config();
- $options->protocol = 'https';
- $options->gatewayHost = 'openapi.alipay.com';
- $options->signType = 'RSA2';
- $options->appId = $configArr['app_id'];
- // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
- $options->merchantPrivateKey = file_get_contents($configArr['private_key']);
- $options->alipayCertPath = $configArr['alipay_cert_public_key_rsa2'];//'<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
- $options->alipayRootCertPath = $configArr['alipay_root_cert'];//'<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
- $options->merchantCertPath = $configArr['app_cert_public_key'];//'<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';
- //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
- //$options->alipayPublicKey = $configArr['ali_public_key'];
- //可设置异步通知接收服务地址(可选)
- $options->notifyUrl = $configArr['notify_url'];
- //可设置AES密钥,调用AES加解密相关接口时需要(可选)
- // $options->encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->";
- return $options;
- }
- }
|