Index.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace app\index\controller;
  3. use app\cms\model\Message as ModelMessage;
  4. use app\enterprise\model\{File,Group,User,Message};
  5. use think\facade\View;
  6. use app\manage\model\Config;
  7. use app\Request;
  8. use think\facade\Filesystem;
  9. class Index
  10. {
  11. public function index()
  12. {
  13. if (!file_exists(PACKAGE_PATH . "install.lock")) {
  14. return redirect(url('index/install/index'));
  15. }
  16. $demon=env('app.demon_mode',false);
  17. if(request()->isMobile() && strpos(request()->url(),'index.html')===false && !$demon){
  18. return redirect("/h5");
  19. }
  20. return redirect("/index.html");
  21. }
  22. public function view()
  23. {
  24. $url=request()->param('src');
  25. $suffix=explode('.',$url);
  26. $ext=$suffix[count($suffix)-1];
  27. return View::fetch('',[
  28. 'url' => $url,
  29. 'ext'=>$ext,
  30. 'name'=>lang('file.preview')
  31. ]);
  32. }
  33. // 头像生成
  34. public function avatar()
  35. {
  36. circleAvatar(input('str'), input('s') ?: 80, input('uid'));die;
  37. }
  38. // 文件下载
  39. public function download()
  40. {
  41. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
  42. throw new \think\Exception(lang('file.browserDown'),400);
  43. }
  44. $param = request()->param();
  45. $file_id = $param['file_id'] ?? 0;
  46. if (!$file_id) {
  47. throw new \think\Exception(lang('system.parameterError'), 502);
  48. }
  49. try {
  50. $file_id = decryptIds($file_id);
  51. } catch (\Exception $e) {
  52. throw new \think\Exception($e->getMessage(), 400);
  53. }
  54. $file = File::find($file_id);
  55. if (!$file) {
  56. throw new \think\Exception(lang('file.exist'),404);
  57. }
  58. $file = $file->toArray();
  59. // 兼容本地文件下载
  60. $fileUrl=getDiskUrl();
  61. if($fileUrl==getMainHost()){
  62. $url=rtrim(public_path(),'/').$file['src'];
  63. }else{
  64. $url= getFileUrl($file['src']);
  65. }
  66. return \utils\File::download($url, $file['name'] . '.' . $file['ext'], $file['size'], $file['ext']);
  67. }
  68. // 扫码获取信息
  69. public function scanQr(){
  70. $param=request()->param();
  71. $action=$param['action'] ?? '';
  72. $token=$param['token'] ?? '';
  73. $realToken=$param['realToken'] ?? '';
  74. if(request()->isPost() && $action && $token && $realToken){
  75. $actions=[
  76. 'g'=>'group',
  77. 'u'=>'user',
  78. 'a'=>'qrLogin',
  79. ];
  80. $a=$actions[$action] ?? '';
  81. if(!$a){
  82. return warning(lang('scan.failure'));
  83. }
  84. return $this->$a($param);
  85. }else{
  86. return redirect('/downapp');
  87. }
  88. }
  89. protected function group($param)
  90. {
  91. $token=authcode(urldecode($param['realToken']),"DECODE", 'qr');
  92. if(!$token){
  93. return warning(lang('scan.failure'));
  94. }
  95. $groupInfo=explode('-',$token);
  96. $uid=$groupInfo[0];
  97. $group_id=$groupInfo[1];
  98. $group=Group::find($group_id);
  99. if($group){
  100. $group=$group->toArray();
  101. $group['avatar']=avatarUrl($group['avatar'],$group['name'],$group_id,120,1);
  102. $group['invite_id']=$uid;
  103. $group['id']='group-'.$group_id;
  104. $group['action']='groupInfo';
  105. return success('',$group);
  106. }else{
  107. return warning(lang('scan.failure'));
  108. }
  109. }
  110. protected function user($param)
  111. {
  112. $id=decryptIds($param['token']);
  113. if(!$id){
  114. return warning(lang('scan.failure'));
  115. }
  116. $user=User::where(['user_id'=>$id])->field(User::$defaultField)->find();
  117. if($user){
  118. $user=$user->toArray();
  119. $user['avatar']=avatarUrl($user['avatar'],$user['realname'],$user['user_id'],120);
  120. $user['id']=$user['user_id'];
  121. $user['action']='userInfo';
  122. return success('',$user);
  123. }else{
  124. return warning(lang('scan.failure'));
  125. }
  126. }
  127. // 简易实现二维码扫描登录
  128. protected function qrLogin($param){
  129. $appid=config('app.app_id');
  130. $client_id=authcode(urldecode($param['realToken']),"DECODE",$appid);
  131. if(!$client_id){
  132. return warning(lang('scan.failure'));
  133. }
  134. return success('',[
  135. 'loginToken'=>urlencode(authcode($client_id,'ENCODE',$appid,300)),
  136. 'action'=>'qrLogin'
  137. ]);
  138. }
  139. // app下载页
  140. public function downApp(){
  141. // echo request()->domain(true);
  142. $downAppUrl=env('app.downApp_url','');
  143. if($downAppUrl){
  144. return redirect($downAppUrl);
  145. }
  146. $config=Config::where('field','sysInfo')->value('val');
  147. $android=getAppDowmUrl('android');
  148. $winUrl=getAppDowmUrl('windows');
  149. $macUrl=getAppDowmUrl('mac');
  150. $client=[
  151. 'android_appid'=>env('app.android_appid',''),
  152. 'android_webclip'=>env('app.android_webclip','') ? : $android,
  153. 'ios_appid'=>env('app.ios_appid',''),
  154. 'ios_webclip'=>env('app.ios_webclip',''),
  155. 'win_webclip'=>env('app.win_webclip','') ? : $winUrl,
  156. 'mac_webclip'=>env('app.mac_webclip','') ? : $macUrl
  157. ];
  158. $noUrl=false;
  159. if(!$client['android_appid'] && !$client['android_webclip'] && !$client['ios_appid'] && !$client['ios_webclip']){
  160. $noUrl=true;
  161. }
  162. View::assign('noUrl',$noUrl);
  163. View::assign('client',$client);
  164. View::assign('config',$config);
  165. return View::fetch();
  166. }
  167. // 下载APP
  168. public function downloadApp(){
  169. $platform=request()->param('platform','windows');
  170. $config=config('version.'.$platform);
  171. $name=config('version.app_name');
  172. if($platform=='android'){
  173. $packageName=$name."_Setup_".$config['version'].".apk";
  174. }elseif($platform=='mac'){
  175. $packageName=$name."_Setup_".$config['version'].".dmg";
  176. }else{
  177. $packageName=$name."_Setup_".$config['version'].".exe";
  178. }
  179. $file=PACKAGE_PATH . $packageName;
  180. if(is_file($file)){
  181. return \utils\File::download($file, $packageName);
  182. }else{
  183. return shutdown(lang('file.exist'));
  184. }
  185. }
  186. public function test(){
  187. echo time()-(30*86400);
  188. // $m=new Message();
  189. // $sql="ALTER TABLE `".config('database.connections.mysql.prefix')."message` ENGINE = InnoDB;";
  190. // \think\facade\Db::execute($sql);
  191. // $list=Message::where('create_time','<',time()-(30*86400))->where(['type'=>'image'])->select()->toArray();
  192. // foreach($list as $k=> $v){
  193. // $list[$k]['src']=str_encipher($v['content'],false);
  194. // }
  195. // halt($list);
  196. }
  197. }