Index.php 12 KB

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