Check.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 04/05/2017
  6. * Time: 00:32
  7. */
  8. namespace app\common\services;
  9. use app\common\facades\Setting;
  10. use app\common\helpers\Url;
  11. use Illuminate\Support\Facades\Cache;
  12. class Check
  13. {
  14. public static function app()
  15. {
  16. if(app()->environment() !== 'production'){
  17. return true;
  18. }
  19. $key = 'app_auth' . \YunShop::app()->uniacid;
  20. if(Cache::has($key)){
  21. if(Cache::get($key)){
  22. exit(redirect(Url::absoluteWeb('setting.key.index'))->send());
  23. } else{
  24. return true;
  25. }
  26. }
  27. $key = Setting::get('shop.key')['key'];
  28. $secret = Setting::get('shop.key')['secret'];
  29. $update = new AutoUpdate(null, null, 300);
  30. $update->setUpdateFile('check_app.json');
  31. $update->setCurrentVersion(config('version'));
  32. $update->setUpdateUrl(config('auto-update.checkUrl')); //Replace with your server update directory
  33. Setting::get('auth.key');
  34. $update->setBasicAuth($key, $secret);
  35. if ($update->checkUpdate() === false) {
  36. Cache::put($key,false,360);
  37. exit(redirect(Url::absoluteWeb('setting.key.index'))->send());
  38. }
  39. Cache::put($key,true,360);
  40. return true;
  41. }
  42. public static function setKey()
  43. {
  44. if (app()->environment() == 'production' && strpos(request()->get('route'),'setting.key') !== 0) {
  45. $key = Setting::get('shop.key')['key'];
  46. $secret = Setting::get('shop.key')['secret'];
  47. if (!$key || !$secret) {
  48. redirect(Url::absoluteWeb('setting.key.index',['uniacid'=>\YunShop::app()->uniacid]))->send();
  49. }
  50. }
  51. }
  52. }