123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- class Userposter extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
-
- private function mini_code($scene, $page_url, $introcode)
- {
- $value = config('wxMiniProgram');
- $appid = $value['appid'];
- $secret = $value['secret'];
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
- $res = file_get_contents($url);
- $token = json_decode($res, true)['access_token'];
- $URL = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $token;
- $data = [
- 'scene' => 'introcode='.$introcode,
- 'page' => $page_url,
- 'env_version' => 'release',
- 'width' => 800,
- 'auto_color' => false,
- 'is_hyaline' => false,
- 'check_path' => false,
- ];
- $json = json_encode($data);
-
- $result = curl_post($URL,$json);
- $path = ROOT_PATH . 'public/uploads/minicode';
- $path2 = '/uploads/minicode';
- if (!file_exists($path)) {
- mkdir($path, 0777, true);
- }
- $path = $path . '/' . $scene . '.png';
- $path2 = $path2 . '/' . $scene . '.png';
- file_put_contents($path, $result);
- return $path2;
- }
-
- public function shareposter() {
- $inviteimage = $this->mini_code($this->auth->id,'pages/index/index',$this->auth->introcode);
- $data = [
- [
- "left"=> "100px",
- "top"=> "515px",
- "type"=> "img",
- "width"=> "170px",
- "height"=> "170px",
- "src"=> httpurllocal($inviteimage)
- ],
- [
- "left"=> "158px",
- "top"=> "490px",
- "type"=> "nickname",
- "width"=> "166px",
- "height"=> "38px",
- "size"=> "13px",
- "color"=> "#2cb47d",
- "content" => $this->auth->introcode,
- ],
- ];
- $data = json_encode($data, 320);
- $poster = [
- 'id' => 1,
- 'title' => '测试',
- 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
- 'bg_image' => '/assets/img/posteruserbg.png',
- 'data' => $data,
- 'status' => 'normal',
- 'weigh' => 0,
- 'createtime' => 1653993709,
- 'updatetime' => 1653994259,
- ];
- $image = new \addons\poster\library\Image();
- $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
- if (!$imgurl) {
- $this->error('生成海报出错');
- }
- $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
- $this->success('', $imgurl);
- }
- }
|