Index.php 13 KB

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