Base.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 浏览器基类
  7. */
  8. namespace app\common\controller;
  9. use think\Controller;
  10. use app\common\model\SystemWeb;
  11. use app\common\model\SystemMemberMiniapp;
  12. use filter\Filter;
  13. class Base extends Controller{
  14. protected $web; //站点参数
  15. protected $token = 0; //公众号
  16. protected $is_mp = false; //公众号
  17. protected $is_lightapp = false; //应应用
  18. protected $is_minapp = false; //小程序
  19. protected function initialize(){
  20. $this->web = SystemWeb::config(); //当前站点配置
  21. $this->assign(['web'=> $this->web]);
  22. }
  23. /**
  24. * 方法不存在
  25. */
  26. public function _empty(){
  27. return $this->error('访问的页面不存在');
  28. }
  29. /**
  30. * 判断小程序类型
  31. * @param string $miniapp
  32. * mp
  33. * program
  34. * app
  35. * mp_program
  36. * mp_program_app
  37. * @return boolean
  38. */
  39. protected function isAppTyes($apptyes){
  40. switch ($apptyes) {
  41. case 'mp':
  42. $this->is_mp = true;
  43. break;
  44. case 'program':
  45. $this->is_weapp = true;
  46. break;
  47. case 'app':
  48. $this->is_lapp = true;
  49. break;
  50. case 'mp_program':
  51. $this->is_mp = true;
  52. $this->is_weapp = true;
  53. break;
  54. case 'mp_program_app':
  55. $this->is_mp = true;
  56. $this->is_lapp = true;
  57. $this->is_weapp = true;
  58. break;
  59. }
  60. }
  61. /**
  62. * 接口认证
  63. * @return void
  64. */
  65. protected function apiAccess() {
  66. $appid = $this->request->param('app/d',0);
  67. $condition = [];
  68. if(empty($appid)){
  69. $header = $this->request->header();
  70. if(empty($header['request-miniapp']) && empty($header['request-time'])){
  71. return false;
  72. }
  73. $condition['service_id'] = Filter::filter_escape($header['request-miniapp']);
  74. }else{
  75. $condition['id'] = (int)$appid;
  76. }
  77. $condition['is_lock'] = 0;
  78. $this->token = $header['request-token'] ?? 0;
  79. return SystemMemberMiniapp::where($condition)->field('id,member_id,appname,service_id,navbar_color,navbar_style,create_time,update_time,miniapp_appid,miniapp_id,mp_appid,is_psp,sdk_app_id,sdk_url')->find();
  80. }
  81. }