Userposter.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 用户海报
  7. */
  8. class Userposter extends Api
  9. {
  10. // 无需登录的接口,*表示全部
  11. protected $noNeedLogin = [''];
  12. // 无需鉴权的接口,*表示全部
  13. protected $noNeedRight = ['*'];
  14. public function testhaibao(){
  15. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  16. // dump($haibao);
  17. $this->success('success', $haibao);
  18. }
  19. //海报
  20. public function haibao($player_id,$data){
  21. //下载页二维码,没必要保留
  22. $params = [
  23. 'text' => config('img_url').'?code=' . $data['introcode'],
  24. 'size' => 90,
  25. 'logo' => false,
  26. 'label' => false,
  27. 'padding' => 0,
  28. ];
  29. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  30. $qrcode_path = ROOT_PATH . 'public/uploads/hbplayer/'.date('Ymd');
  31. if (!is_dir($qrcode_path)) {
  32. @mkdir($qrcode_path);
  33. }
  34. if (is_really_writable($qrcode_path)) {
  35. $filename = 'download'.$player_id.'.png';
  36. $download_qrcode = $qrcode_path.'/'.$filename;
  37. $qrCode->writeFile($download_qrcode);
  38. }
  39. //海报
  40. $filepath = '/uploads/hbplayer/'.date('Ymd') .'/'. $filename;
  41. $haibao = $this->createhaibao($filepath,$player_id,$data);
  42. return $haibao;
  43. }
  44. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  45. //背景图
  46. $background = $sub_data['background'] ? $sub_data['background'] : config('img_url').'/assets/img/haibao.png';
  47. //海报图片路径
  48. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  49. mk_dir($new_path);
  50. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  51. //二维码
  52. $download_qrcode= config('img_url').'/'.$download_qrcode;
  53. //合成wap图片
  54. $image = new \addons\poster\library\Image2();
  55. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  56. return '/'.$wap_file_name;
  57. }*/
  58. public function createhaibao($download_qrcode,$player_id,$sub_data){
  59. //二维码
  60. $data = [
  61. [
  62. "left" => "15px",
  63. "top" => "296px",
  64. "type" => "img",
  65. "width" => "58px",
  66. "height" => "58px",
  67. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  68. ],
  69. [
  70. "left" => "81px",
  71. "top" => "300px",
  72. "type" => "nickname",
  73. "width" => "80px",
  74. "height" => "24px",
  75. "size" => "12px",
  76. "color" => "#000",
  77. "content" => $this->auth->nickname
  78. ],
  79. [
  80. "left" => "81px",
  81. "top" => "327px",
  82. "type" => "nickname",
  83. "width" => "80px",
  84. "height" => "24px",
  85. "size" => "12px",
  86. "color" => "#000",
  87. "content" => $this->auth->introcode
  88. ],
  89. [
  90. "left" => "227px",
  91. "top" => "283px",
  92. "type" => "img",
  93. "width" => "80px",
  94. "height" => "80px",
  95. "src" => httpurllocal($download_qrcode)
  96. ]
  97. ];
  98. $data = json_encode($data, 320);
  99. $poster = [
  100. 'id' => $this->auth->id,
  101. 'title' => '星链',
  102. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  103. 'bg_image' => $sub_data['background'] ? localpath_to_netpath($sub_data['background']) : '/assets/img/inviteposter.png',
  104. 'data' => $data,
  105. 'status' => 'normal',
  106. 'weigh' => 0,
  107. 'createtime' => 1653993709,
  108. 'updatetime' => 1653994259,
  109. ];
  110. $image = new \addons\poster\library\Image();
  111. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  112. if (!$imgurl) {
  113. $this->error('生成海报出错');
  114. }
  115. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  116. return '/' . $imgurl;
  117. }
  118. //海报背景图
  119. public function posterlist() {
  120. $list = config('site.intro_images');
  121. if (!$list) {
  122. $this->success('success', (object)[]);
  123. }
  124. foreach ($list as &$v) {
  125. $v = config('img_url') . $this->createposter(localpath_to_netpath($v));
  126. }
  127. $this->success('success', $list);
  128. }
  129. //生成海报
  130. public function createposter($image = '') {
  131. // $image = input('image', '', 'trim');
  132. // if (!$image) {
  133. // $this->error('您的网络开小差啦~');
  134. // }
  135. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  136. return $haibao;
  137. // $this->success('success', $haibao);
  138. }
  139. }