Index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use fast\Random;
  5. use \think\Log;
  6. use Redis;
  7. use app\common\library\Sms as Smslib;
  8. /**
  9. * 首页接口
  10. */
  11. class Index extends Api
  12. {
  13. protected $noNeedLogin = ['index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList','getPartyHotList','searchUsers','getInviteCode','getEdition','getInviteImg','getWebsiteInfoForMini','getBankList','getSwitch','getBootAnimation'];
  14. protected $noNeedRight = ['*'];
  15. public function index(){
  16. echo 'apisuccess';
  17. exit;
  18. }
  19. /**
  20. * 获取邀请图片
  21. */
  22. public function getInviteImg() {
  23. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  24. if(!in_array($plat,[1,2])) $this->error("参数错误");
  25. // 获取用户的邀请码
  26. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  27. // 文字图片合成
  28. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  29. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  30. //字体文件
  31. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  32. //字体颜色(RGB)
  33. $black = imagecolorallocate($img, 217, 76, 41);
  34. //字体大小
  35. $fontSize = 30;
  36. //旋转角度
  37. $circleSize = 0;
  38. //左边距
  39. $left = 275;
  40. //上边距
  41. $top = 540;
  42. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  43. $filename = date("YmdH").".jpeg";
  44. $path = "/uploads/qrcode/".$filename;
  45. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  46. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  47. switch ($bgType) {
  48. case 1://gif
  49. header('Content-Type:image/gif');
  50. imagegif($img,$file);
  51. break;
  52. case 2://jpg
  53. header('Content-Type:image/jpg');
  54. imagejpeg($img,$file);
  55. break;
  56. case 3://jpg
  57. header('Content-Type:image/png');
  58. imagepng($img,$file);
  59. break;
  60. default:
  61. break;
  62. }
  63. //销毁照片
  64. imagedestroy($img);
  65. // 图片和二维码合成
  66. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  67. $background = $file;
  68. $target = $this->httpurl($qrcode);
  69. $background_iamge = imagecreatefromstring(file_get_contents($background));
  70. $target_image = imagecreatefromstring(file_get_contents($target));
  71. list($target_width, $target_height, $target_type) = getimagesize($target);
  72. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  73. list($background_width, $background_height, $background_type) = getimagesize($background);
  74. switch ($background_type) {
  75. case 1://gif
  76. header('Content-Type:image/gif');
  77. imagegif($background_iamge,$file);
  78. break;
  79. case 2://jpg
  80. header('Content-Type:image/jpg');
  81. imagejpeg($background_iamge,$file);
  82. break;
  83. case 3://jpg
  84. header('Content-Type:image/png');
  85. imagepng($background_iamge,$file);
  86. break;
  87. default:
  88. break;
  89. }
  90. $savepath = $this->httpurlLocal($path);
  91. $this->success("获取成功!",$savepath);
  92. }
  93. /**
  94. * 评论时间转换
  95. * @param null $time
  96. * @return false|string
  97. */
  98. private function get_last_time($time = NULL) {
  99. $text = '';
  100. $time = $time === NULL || $time > time() ? time() : intval($time);
  101. $t = time() - $time; //时间差 (秒)
  102. $y = date('Y', $time)-date('Y', time());//是否跨年
  103. switch($t){
  104. case $t == 0:
  105. $text = '刚刚';
  106. break;
  107. case $t < 60:
  108. $text = $t . '秒前'; // 一分钟内
  109. break;
  110. case $t < 60 * 60:
  111. $text = floor($t / 60) . '分钟前'; //一小时内
  112. break;
  113. case $t < 60 * 60 * 24:
  114. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  115. break;
  116. case $t < 60 * 60 * 24 * 3:
  117. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  118. break;
  119. case $t < 60 * 60 * 24 * 30:
  120. $text = date('m月d日 H:i', $time); //一个月内
  121. break;
  122. case $t < 60 * 60 * 24 * 365&&$y==0:
  123. $text = date('m月d日', $time); //一年内
  124. break;
  125. default:
  126. $text = date('Y年m月d日', $time); //一年以前
  127. break;
  128. }
  129. return $text;
  130. }
  131. }