Userposter.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 用户海报
  7. */
  8. class Demo 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('site.domain_name').'?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 = 'uploads/hbplayer/'.date('Ymd');
  31. mk_dir($qrcode_path);
  32. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  33. $qrCode->writeFile($download_qrcode);
  34. //海报
  35. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  36. return $haibao;
  37. }
  38. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  39. //背景图
  40. $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
  41. //海报图片路径
  42. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  43. mk_dir($new_path);
  44. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  45. //二维码
  46. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  47. //合成wap图片
  48. $image = new \addons\poster\library\Image2();
  49. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  50. return '/'.$wap_file_name;
  51. }*/
  52. public function createhaibao($download_qrcode,$player_id,$sub_data){
  53. //二维码
  54. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  55. $data = [
  56. [
  57. "left" => "15px",
  58. "top" => "296px",
  59. "type" => "img",
  60. "width" => "58px",
  61. "height" => "58px",
  62. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  63. ],
  64. [
  65. "left" => "81px",
  66. "top" => "300px",
  67. "type" => "nickname",
  68. "width" => "80px",
  69. "height" => "24px",
  70. "size" => "12px",
  71. "color" => "#000",
  72. "content" => $this->auth->nickname
  73. ],
  74. [
  75. "left" => "81px",
  76. "top" => "327px",
  77. "type" => "nickname",
  78. "width" => "80px",
  79. "height" => "24px",
  80. "size" => "12px",
  81. "color" => "#000",
  82. "content" => $this->auth->introcode
  83. ],
  84. [
  85. "left" => "227px",
  86. "top" => "283px",
  87. "type" => "img",
  88. "width" => "80px",
  89. "height" => "80px",
  90. // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  91. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  92. ]
  93. ];
  94. $data = json_encode($data, 320);
  95. $poster = [
  96. 'id' => 1,
  97. 'title' => '测试2',
  98. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  99. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  100. 'data' => $data,
  101. 'status' => 'normal',
  102. 'weigh' => 0,
  103. 'createtime' => 1653993709,
  104. 'updatetime' => 1653994259,
  105. ];
  106. $image = new \addons\poster\library\Image();
  107. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  108. if (!$imgurl) {
  109. $this->error('生成海报出错');
  110. }
  111. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  112. return '/' . $imgurl;
  113. }
  114. //海报背景图
  115. public function posterlist() {
  116. $list = config('site.intro_images');
  117. if (!$list) {
  118. $this->success('success', (object)[]);
  119. }
  120. foreach ($list as &$v) {
  121. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  122. }
  123. $this->success('success', $list);
  124. }
  125. //生成海报
  126. public function createposter($image = '') {
  127. // $image = input('image', '', 'trim');
  128. // if (!$image) {
  129. // $this->error('您的网络开小差啦~');
  130. // }
  131. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  132. return $haibao;
  133. // $this->success('success', $haibao);
  134. }
  135. }