Index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. if ($this->auth->reffer_img) {
  187. $savepath = httpurllocal($this->auth->reffer_img);
  188. $this->success("获取成功!", $savepath);
  189. }
  190. // 获取用户的邀请码
  191. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  192. // $invitecode = 'y0AnrH';
  193. // 文字图片合成
  194. $bigImgPath = httpurllocal('/assets/img/inviteimg.png');
  195. $img = imagecreatefrompng($bigImgPath);
  196. imagesavealpha($img, true);
  197. //字体文件
  198. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  199. //字体颜色(RGB)
  200. $black = imagecolorallocate($img, 217, 76, 41);
  201. //字体大小
  202. $fontSize = 25;
  203. //旋转角度
  204. $circleSize = 0;
  205. //左边距
  206. $left = 192;//383;
  207. //上边距
  208. $top = 1114;//680;
  209. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  210. $filename = date("YmdHis"). $this->auth->id . rand(10000, 99999) . ".jpeg";
  211. $path = "/uploads/qrcode/".$filename;
  212. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  213. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  214. switch ($bgType) {
  215. case 1://gif
  216. header('Content-Type:image/gif');
  217. imagegif($img,$file);
  218. break;
  219. case 2://jpg
  220. header('Content-Type:image/jpg');
  221. imagejpeg($img,$file);
  222. break;
  223. case 3://jpg
  224. header('Content-Type:image/png');
  225. imagepng($img,$file);
  226. break;
  227. default:
  228. break;
  229. }
  230. //销毁照片
  231. imagedestroy($img);
  232. // 图片和二维码合成
  233. // $qrcode = config("site.qrcode");
  234. $params['text'] = 'https://' . $_SERVER['HTTP_HOST'] . '/index/index/invite?code=' . $invitecode;
  235. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  236. $mimetype = 'image/png';
  237. $response = Response::create()->header("Content-Type", $mimetype);
  238. // 直接显示二维码
  239. header('Content-Type: ' . $qrcode_service->getContentType());
  240. $response->content($qrcode_service->writeString());
  241. $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
  242. if (!is_dir($qrcodePath)) {
  243. @mkdir($qrcodePath);
  244. }
  245. if (is_really_writable($qrcodePath)) {
  246. $filePath = $qrcodePath . md5(implode('', $params)) . '.png';
  247. $qrcode_service->writeFile($filePath);
  248. }
  249. $background = $file;
  250. $target = $filePath;//httpurl($qrcode);
  251. // $background_iamge = imagecreatefromstring(file_get_contents($background)); // 无透明度
  252. $background_iamge = imagecreatefrompng($background); // 保留背景的透明度
  253. imagesavealpha($background_iamge, true);
  254. $target_image = imagecreatefromstring(file_get_contents($target));
  255. list($target_width, $target_height, $target_type) = getimagesize($target);
  256. // imagecopy($background_iamge , $target_image , 350, 850, 0, 0, $target_width, $target_height);
  257. imagecopy($background_iamge , $target_image , 468, 1048, 0, 0, $target_width, $target_height);
  258. list($background_width, $background_height, $background_type) = getimagesize($background);
  259. switch ($background_type) {
  260. case 1://gif
  261. header('Content-Type:image/gif');
  262. imagegif($background_iamge,$file);
  263. break;
  264. case 2://jpg
  265. header('Content-Type:image/jpg');
  266. imagejpeg($background_iamge,$file);
  267. break;
  268. case 3://jpg
  269. header('Content-Type:image/png');
  270. imagepng($background_iamge,$file);
  271. break;
  272. default:
  273. break;
  274. }
  275. // header("Content-type: image/png");
  276. // imagepng($background_iamge);exit;
  277. $savepath = httpurllocal($path);
  278. if ($this->auth->id) {
  279. Db::name('user')->where(['id' => $this->auth->id])->setField('reffer_img', $path);
  280. }
  281. $this->success("获取成功!",$savepath);
  282. }
  283. /**
  284. * 获取邀请的用户
  285. */
  286. public function getInviteusers() {
  287. $user_list = \app\common\model\User::field('id,nickname,invite_time')->where(['pre_user_id'=>$this->auth->id])->select();
  288. if($user_list) {
  289. $user_profit_log = Db::name('user_profit_log');
  290. foreach($user_list as $k => &$v) {
  291. $user_list[$k]['invite_time'] = date('Y-m-d H:i:s',$v['invite_time']);
  292. $income = $user_profit_log->where(['user_id' => $v['id']])->order('id', 'desc')->value('after');
  293. $v['total_income'] = $income ? : "0.00";
  294. }
  295. }
  296. $this->success("获取成功!",$user_list);
  297. }
  298. /**
  299. * 获取累计邀请/邀请码等
  300. */
  301. public function getInviteCount() {
  302. $user_count = \app\common\model\User::where(['pre_user_id'=>$this->auth->id])->count("id");
  303. $invite_no = \app\common\model\User::where(['id'=>$this->auth->id])->value('invite_no');
  304. $this->success("获取成功!",['user_count'=>$user_count,'invite_no'=>$invite_no]);
  305. }
  306. //rsa公钥私钥加密测试
  307. public function test() {
  308. $data = '123456';
  309. $private_key = "-----BEGIN RSA PRIVATE KEY-----" .PHP_EOL.
  310. wordwrap(config('private_key'), 64, PHP_EOL, true) .
  311. PHP_EOL."-----END RSA PRIVATE KEY-----";
  312. $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
  313. wordwrap(config('public_key'), 64, PHP_EOL, true) .
  314. PHP_EOL."-----END PUBLIC KEY-----";
  315. $encrypted = $decrypted = "";
  316. openssl_private_encrypt($data, $encrypted, $private_key); // 使用私钥加密数据
  317. echo base64_encode($encrypted);
  318. openssl_public_decrypt($encrypted, $decrypted, $public_key);// 使用公钥进行解密
  319. echo $decrypted;
  320. }
  321. }