Index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Log;
  6. use think\Response;
  7. /**
  8. * 首页接口
  9. */
  10. class Index extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 获取视频第一针
  16. */
  17. public function getVideo() {
  18. $video = $this->request->request('video'); // 视频文件
  19. if(!$video) {
  20. $this->error(__('视频文件缺失!'));
  21. }
  22. $cover = 'uploads/video_cover/'.date('Ymd').date('His').rand(1000,9999).'.png';
  23. getVideoCover($video,0.1,$cover);
  24. $full_cover = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].'/'.$cover;
  25. if($full_cover) {
  26. $this->success("获取成功",$full_cover);
  27. } else {
  28. $this->error("网络错误,请稍后重试");
  29. }
  30. }
  31. /**
  32. * 首页
  33. *
  34. */
  35. public function index()
  36. {
  37. getVideoCover(config('project_path') . '/public/assets/123.mp4',3,'uploads/ffmpeg_test.png');
  38. $this->success('请求成功');
  39. }
  40. /**
  41. * 获取版本更新信息
  42. */
  43. public function getEdition() {
  44. // 获取二维码
  45. $is_force = config("site.is_force");
  46. $apkUrl = config("site.apkUrl");
  47. $apkName = config("site.apkName");
  48. $desc = config("site.desc");
  49. $versionCode = config("site.versionCode");
  50. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  51. }
  52. /**
  53. * 获取网站配置信息
  54. */
  55. public function getWebsiteInfo() {
  56. $params = $this->request->request("params"); //内容
  57. $this->success("获取成功!",config("site.".$params));
  58. }
  59. /**
  60. * 获取省数据
  61. */
  62. public function getProvince() {
  63. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>0])->select();
  64. $this->success('请求成功',$res);
  65. }
  66. /**
  67. * 获取市数据
  68. */
  69. public function getCity() {
  70. $province = $this->request->request('province'); // 省
  71. if (!$province) $this->error('参数缺失!');
  72. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>$province])->select();
  73. $this->success('请求成功',$res);
  74. }
  75. /**
  76. * 获取区数据
  77. */
  78. public function getArea() {
  79. $city = $this->request->request('city'); // 市
  80. if (!$city) $this->error('参数缺失!');
  81. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>$city])->select();
  82. $this->success('请求成功',$res);
  83. }
  84. /**
  85. * 根据生日获取年龄和星座
  86. */
  87. public function getAgeByBirthday() {
  88. $birthday = $this->request->request('birthday'); // 生日 格式:2011-04-31
  89. $signs = array( array('20' => '水瓶座'), array('19' => '双鱼座'), array('21' => '白羊座'), array('20' => '金牛座'), array('21' => '双子座'), array('22' => '巨蟹座'), array('23' => '狮子座'), array('23' => '处女座'), array('23' => '天秤座'), array('24' => '天蝎座'), array('22' => '射手座'), array('22' => '摩羯座'));
  90. if (!empty($birthday)) {
  91. $age = strtotime($birthday);
  92. if ($age === false) {
  93. $this->error("参数缺失!");
  94. }
  95. list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age));
  96. list($y2, $m2, $d2) = explode("-", date("Y-m-d"), time());
  97. $age = $y2 - $y1;
  98. //下面是判断月份大小,如果只是逄年份的可以去掉,如果算上月份的话,比如:2000年4月1日,那算出来是16算,要到了4月,算出来才是17岁
  99. if ((int)($m2 . $d2) < (int)($m1 . $d1)) {
  100. $age -= 1;
  101. }
  102. //星座
  103. $key = (int)$m1 - 1;
  104. $startSign = array_keys($signs[$key]);
  105. $signName = array_values($signs[$key])[0];
  106. if ($d1 < $startSign) {
  107. $key = $m1 - 2 < 0 ? $m1 = 11 : $m1 -= 2;
  108. $startSign = array_keys($signs[$key]);
  109. $signName = array_values($signs[$key])[0];
  110. }
  111. if($age < 0) {
  112. $this->error("出生日期不能大于当前时间!");
  113. }
  114. $data = [];
  115. $data['age'] = $age;
  116. $data['signName'] = $signName;
  117. $this->success("获取成功!",$data);
  118. } else {
  119. $this->error("参数缺失!");
  120. }
  121. }
  122. /**
  123. * 获取期望对象列表
  124. */
  125. public function getExpect() {
  126. $this->success("获取成功!",\app\admin\model\website\Expect::order("weight","desc")->select());
  127. }
  128. /**
  129. * 获取爱好列表
  130. */
  131. public function getHobby() {
  132. $this->success("获取成功!",\app\admin\model\website\Hobby::order("weight","desc")->select());
  133. }
  134. /**
  135. * 获取职业列表
  136. */
  137. public function getProfession() {
  138. $this->success("获取成功!",\app\admin\model\website\Profession::order("weight","desc")->select());
  139. }
  140. /**
  141. * 获取收入列表
  142. */
  143. public function getIncome() {
  144. $this->success("获取成功!",\app\admin\model\website\Income::order("weight","desc")->select());
  145. }
  146. /**
  147. * 获取会员举报类型
  148. */
  149. public function getReportType() {
  150. $this->success("获取成功!",\app\admin\model\website\ReportType::order("weight","desc")->select());
  151. }
  152. /**
  153. * 获取音乐列表信息
  154. */
  155. public function getMusicInfo() {
  156. $this->success("获取成功!",\app\admin\model\website\Music::order("weight","desc")->select());
  157. }
  158. /**
  159. * 获取标签列表信息
  160. */
  161. public function getTagInfo() {
  162. $this->success("获取成功!",\app\admin\model\website\Tag::order("weight","desc")->select());
  163. }
  164. /**
  165. * 获取客服列表
  166. */
  167. public function getCsList() {
  168. $this->success("获取成功!",\app\admin\model\website\Kefu::order("weight","desc")->select());
  169. }
  170. /**
  171. * 获取邀请图片
  172. */
  173. public function getInviteImg() {
  174. // 获取用户的邀请码
  175. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  176. // $invitecode = 'y0AnrH';
  177. // 文字图片合成
  178. $bigImgPath = httpurllocal('/assets/img/inviteimg.png');
  179. $img = imagecreatefrompng($bigImgPath);
  180. imagesavealpha($img, true);
  181. //字体文件
  182. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  183. //字体颜色(RGB)
  184. $black = imagecolorallocate($img, 217, 76, 41);
  185. //字体大小
  186. $fontSize = 25;
  187. //旋转角度
  188. $circleSize = 0;
  189. //左边距
  190. $left = 192;//383;
  191. //上边距
  192. $top = 1114;//680;
  193. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  194. $filename = date("YmdHis"). $this->auth->id . rand(10000, 99999) . ".jpeg";
  195. $path = "/uploads/qrcode/".$filename;
  196. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  197. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  198. switch ($bgType) {
  199. case 1://gif
  200. header('Content-Type:image/gif');
  201. imagegif($img,$file);
  202. break;
  203. case 2://jpg
  204. header('Content-Type:image/jpg');
  205. imagejpeg($img,$file);
  206. break;
  207. case 3://jpg
  208. header('Content-Type:image/png');
  209. imagepng($img,$file);
  210. break;
  211. default:
  212. break;
  213. }
  214. //销毁照片
  215. imagedestroy($img);
  216. // 图片和二维码合成
  217. // $qrcode = config("site.qrcode");
  218. $params['text'] = 'https://' . $_SERVER['HTTP_HOST'] . '/index/index/invite?code=' . $invitecode;
  219. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  220. $mimetype = 'image/png';
  221. $response = Response::create()->header("Content-Type", $mimetype);
  222. // 直接显示二维码
  223. header('Content-Type: ' . $qrcode_service->getContentType());
  224. $response->content($qrcode_service->writeString());
  225. $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
  226. if (!is_dir($qrcodePath)) {
  227. @mkdir($qrcodePath);
  228. }
  229. if (is_really_writable($qrcodePath)) {
  230. $filePath = $qrcodePath . md5(implode('', $params)) . '.png';
  231. $qrcode_service->writeFile($filePath);
  232. }
  233. $background = $file;
  234. $target = $filePath;//httpurl($qrcode);
  235. // $background_iamge = imagecreatefromstring(file_get_contents($background)); // 无透明度
  236. $background_iamge = imagecreatefrompng($background); // 保留背景的透明度
  237. imagesavealpha($background_iamge, true);
  238. $target_image = imagecreatefromstring(file_get_contents($target));
  239. list($target_width, $target_height, $target_type) = getimagesize($target);
  240. // imagecopy($background_iamge , $target_image , 350, 850, 0, 0, $target_width, $target_height);
  241. imagecopy($background_iamge , $target_image , 468, 1028, 0, 0, $target_width, $target_height);
  242. list($background_width, $background_height, $background_type) = getimagesize($background);
  243. switch ($background_type) {
  244. case 1://gif
  245. header('Content-Type:image/gif');
  246. imagegif($background_iamge,$file);
  247. break;
  248. case 2://jpg
  249. header('Content-Type:image/jpg');
  250. imagejpeg($background_iamge,$file);
  251. break;
  252. case 3://jpg
  253. header('Content-Type:image/png');
  254. imagepng($background_iamge,$file);
  255. break;
  256. default:
  257. break;
  258. }
  259. // header("Content-type: image/png");
  260. // imagepng($background_iamge);exit;
  261. $savepath = httpurllocal($path);
  262. $this->success("获取成功!",$savepath);
  263. }
  264. /**
  265. * 获取邀请的用户
  266. */
  267. public function getInviteusers() {
  268. $user_list = \app\common\model\User::field('id,nickname,invite_time')->where(['pre_user_id'=>$this->auth->id])->select();
  269. if($user_list) {
  270. $user_profit_log = Db::name('user_profit_log');
  271. foreach($user_list as $k => &$v) {
  272. $user_list[$k]['invite_time'] = date('Y-m-d H:i:s',$v['invite_time']);
  273. $income = $user_profit_log->where(['user_id' => $v['id']])->order('id', 'desc')->value('after');
  274. $v['total_income'] = $income ? : "0.00";
  275. }
  276. }
  277. $this->success("获取成功!",$user_list);
  278. }
  279. /**
  280. * 获取累计邀请/邀请码等
  281. */
  282. public function getInviteCount() {
  283. $user_count = \app\common\model\User::where(['pre_user_id'=>$this->auth->id])->count("id");
  284. $invite_no = \app\common\model\User::where(['id'=>$this->auth->id])->value('invite_no');
  285. $this->success("获取成功!",['user_count'=>$user_count,'invite_no'=>$invite_no]);
  286. }
  287. //rsa公钥私钥加密测试
  288. public function test() {
  289. $data = '123456';
  290. $private_key = "-----BEGIN RSA PRIVATE KEY-----" .PHP_EOL.
  291. wordwrap(config('private_key'), 64, PHP_EOL, true) .
  292. PHP_EOL."-----END RSA PRIVATE KEY-----";
  293. $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
  294. wordwrap(config('public_key'), 64, PHP_EOL, true) .
  295. PHP_EOL."-----END PUBLIC KEY-----";
  296. $encrypted = $decrypted = "";
  297. openssl_private_encrypt($data, $encrypted, $private_key); // 使用私钥加密数据
  298. echo base64_encode($encrypted);
  299. openssl_public_decrypt($encrypted, $decrypted, $public_key);// 使用公钥进行解密
  300. echo $decrypted;
  301. }
  302. }