审查视图

application/api/controller/Common.php 21.0 KB
郭盛 authored
1 2 3 4 5 6 7 8 9
<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Area;
use app\common\model\Version;
use fast\Random;
use think\Config;
郭盛 authored
10 11
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
郭盛 authored
12 13 14 15 16 17

/**
 * 公共接口
 */
class Common extends Api
{
郭盛 authored
18
    protected $noNeedLogin = ['init','test_pdf'];
郭盛 authored
19 20
    protected $noNeedRight = '*';
郭盛 authored
21
    public function test_pdf($name='',$use='',$tel='',$number='',$order_num='',$time='',$addressee) {
郭盛 authored
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
// create new PDF document
        $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 002');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// remove default header/footer
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);

// set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

// set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
//        if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
//            require_once(dirname(__FILE__).'/lang/eng.php');
//            $pdf->setLanguageArray($l);
//        }

// ---------------------------------------------------------

// set font
        $pdf->SetFont('msyh', '', 20);

// add a page
        $pdf->AddPage();
        $test_title = '    <div>
            <div
            style="font-size: 28px;color: #333;text-align: center;margin-bottom: 30px"
          >
            素材使用授权书
          </div>
          <div style="font-size: 16px;color: #333;margin-bottom: 20px">
            亲爱的用户,您好
          </div>
郭盛 authored
70
          <div style="font-size: 16px;color: #333">
郭盛 authored
71 72 73
            非常感谢您使用仁甲看见SHOP的相关素材,
            本小程序内销售的素材均为仁甲看见拍摄的正版优质作品,为方便您能正当合法的使用本素材,避免日后因版权纠纷引起的不必要麻烦,请务必填写本授权书;我们会为您自动生成一个pdf文件发送给您;
          </div>
郭盛 authored
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
          <div style="line-height: 0.5">
            <div style="font-size: 18px;color: #333;font-weight:bold">
            使用方<span style="color:orange">【'.$name.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
            使用用途<span style="color:orange">【'.$use.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
            联系方式<span style="color:orange">【'.$tel.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
           素材编号为<span style="color:orange">【'.$number.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
            订单编号为<span style="color:orange">【'.$order_num.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
            素材购买时间为<span style="color:orange">【'.$time.'】</span>
          </div>
          <div style="font-size: 18px;color: #333;font-weight:bold">
             本小程序所有的图片及视频素材拥有者为山东仁甲看见影像服务有限公司
          </div>
郭盛 authored
96
          </div>
郭盛 authored
97
          <div style="">
郭盛 authored
98
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于版权和使用权</div>
郭盛 authored
99
              <div style="font-size: 16px;color: #333;font-weight: bold">&nbsp;&nbsp;&nbsp;&nbsp;<span>您购买的素材</span><span style="color:red">仅限贵单位使用于本协议中的指定用途</span>,仅拥有<span style="color:red">使用权</span>,不包含<span style="color:red">版权</span> <span style="color:red">及著作权等</span>
郭盛 authored
100 101
;如若在其他项目中继续使用,须联系客服更新授权书(无限次免费),以避免日后出现的侵权事件造成的不必要麻烦。
</div>
郭盛 authored
102 103 104
          </div>
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于物权</div>
郭盛 authored
105
              <div style="font-size: 16px;color: #333;">&nbsp;&nbsp;&nbsp;&nbsp;此微信小程序中图片/视频涉及的拍摄目标主要针对城市景观,如果客户在使用过程中出现<span style="color:red">涉及物权纠纷的案例</span>,本公司及小程序概不负责。如果您介意此事,请慎重下单 。</div>
郭盛 authored
106 107 108
          </div>
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于素材质量</div>
郭盛 authored
109 110
              <div style="font-size: 16px;color: #333;font-weight: bold">&nbsp;&nbsp;&nbsp;&nbsp;素材拍摄使用的设备种类很多,本小程序内素材稳定性&nbsp;分辨率&nbsp;调色&nbsp;光比等都会略有差别,建议您在下单购买之前认真查看小样,素材属于虚拟版权物品,<span style="color:red">一经售出概不接</span>
<span style="color:red">受任何理由的退换货</span>。如果您介意此事,请慎重下单</div>
郭盛 authored
111 112 113
          </div>
          <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;视频素材的分辨率在每个素材下方都有详细描述,2K  4K  8K有些部分素材尺寸并 <span style="color:red">非为国际常用标准的尺寸</span> ,比如部分8k素材实际分辨率为6K,建议您在下单购买之前仔细查看照片和视频下方关于分辨率的说明描述,以避免因为分辨率问题带来的困扰和麻烦。</div>
          <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;我们摆上货架的商品都是仁甲看见仔细筛选和挑选的优质素材,部分航拍延时素材可能存在 <span style="color:red">轻微抖动</span> 的问题,建议您在购买之前仔细查看预览视频及水印小样,以避免因为素材抖动问题带来的困扰和麻烦。 <span style="font-weight:bold">如果您介意此事,请慎重下单。</span> </div>
郭盛 authored
114
         <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;如果您在使用素材的过程中遇到<span style="color:red;font-weight:bold">其他问题</span>或是有更好的建议请联系客服,我们会在 第一时间与您沟通确保素材的正常使用</div>
郭盛 authored
115 116 117 118 119 120 121 122
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于义务</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您应当严格遵守用户使用规范的相关规定,不得使用仁甲看见SHOP小程序的所有素材用于违法行为或其它非法目的</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您不得利用此微信小程序素材丑化、诽谤、恶意抹黑山东仁甲看见影像服务有限公司的形象,或用于危害社会,侵蚀道德风尚,宣传不法邪教组织等内容。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;其他干扰仁甲看见SHOP小程序正常运营和侵犯其他用户或第三方合法权益的行为。</div>
          </div>
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于免责</div>
郭盛 authored
123
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您应当理解并同意,仁甲看见SHOP小程序所展示的服务是以现有技术和素材原状提供的,所展示及销售的版权素材皆为最原始状态,由于您对本网站服务未尽了解或理解错误造成的损失不承担法律责任。</div>
郭盛 authored
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您应当理解并同意,如果您无法判断所需内容是否需要额外的第三方授权,您有义务咨询专业人士的法律意见或与本公司相关部门进行确认,因您未尽到上述责任产生的任何第三方主张的索赔、要求或损失,您应当独立承担责任;本公司因此遭受损失的,您应当一并赔偿</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您应当理解并同意,仁甲看见SHOP小程序不担保所提供的服务完全符合您的需要,对于可能遇到的网络信息带来的风险,不对其内容的准确性、真实性、正当性、合法性负责,包括但不限于:</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;1. 使用本服务过程中受到,遭人误导或理解错误导致或可能导致的任何心理、生理上的伤害以及其他经济损失;</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;2. 使用过程中造成的个人隐私泄露或其他信息安全风险;</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;您应当理解并同意,除法律不能豁免的责任外,本网站对您或通过您使用本网站或其内容的第三方,均不承担个人风险行为产生的责任,包括木马病毒、未能传送讯息、数据损坏、传输错误,或因使用互联网服务供应商,或因链接到第三方网站和第三方网站内容,而导致的任何损害,包括但不限于利润的损失、机会的损失或必然的损害赔偿。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 30px">&nbsp;&nbsp;&nbsp;&nbsp;您应当理解并同意,仁甲看见SHOP小程序不能随时预见和防范法律法规、技术以及其他风险,包括但不限于不可抗力、第三方瑕疵、黑客攻击、系统不稳定等可能导致服务中断、数据丢失以及其他的损失与风险。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本公司依据协议约定取得处理违法违规行为的权利,但不构成义务或承诺,有权利但没有义务及时发现违法行为或进行处理。</div>
          </div>
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">关于产权保护</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;仁甲看见SHOP小程序的一切商标权、专利权、图片、视频等知识产权均受中华人民共和国法律法规和相应的国际条约保护,山东仁甲看见影像服务有限公司享有上述知识产权。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;未经山东仁甲看见影像服务有限公司或相关权利人书面同意,您不得为任何商业或非商业目的自行或许可任何第三方实施、利用、转让上述知识产权,也不得以任何形式进行或创造相关衍生作品</div>
          </div>
          <div style="margin-bottom:20px">
              <div style="font-size: 16px;color: gray;margin-bottom: 20px;text-align: center">补充说明</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本协议自发布之日起生效,直至本网站决定终止此协议或协议更新后终止。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本协议签订地为中华人民共和国山东省青岛市李沧区。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本协议的成立、生效、履行、解释及纠纷解决,适用中华人民共和国大陆地区法律(不包括冲突法)。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;若您和本网站发生任何纠纷或争议,首先应友好协商解决;协商不成的,您同意将纠纷或争议提交本协议签订地有管辖权的人民法院管辖</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本协议所有条款的标题仅为阅读方便,本身并无实际涵义,不能作为本协议涵义解释的依据。</div>
              <div style="font-size: 16px;color: #333;margin-bottom: 20px">&nbsp;&nbsp;&nbsp;&nbsp;本协议条款无论因何种原因部分无效或不可执行,其余条款仍有效,对双方具有约束力。</div>
          </div>
          <div style="color:red;font-size:16px;margin-bottom:20px;text-align: center;font-weight: bold">山东仁甲看见影像服务有限公司对于本协议所有条款拥有最终解释权</div>
          <div style="color:red;font-size:16px;margin-bottom:20px;text-align: center;font-weight: bold">祝您使用愉快!!!</div>
    </div>';


// output the HTML content
        $pdf->MultiCell('', '', $test_title, $border=0, $align='J', $fill=0, $ln=1, $x='20', $y='20', $reseth=true, $stretch=0, $ishtml=true, $autopadding=true, $maxh=0);
// ---------------------------------------------------------
// ---------------------------------------------------------

//Close and output PDF document
郭盛 authored
158 159
        ob_clean();
        $pdf->Output(ROOT_PATH.'public'.DS.'pdf'.DS.$order_num.'.pdf', 'F');
郭盛 authored
160
        $url = 'https://areial.w.broing.cn'.'/pdf/'.$order_num.'.pdf';
郭盛 authored
161
        $this->send($addressee,$url);
郭盛 authored
162
        $this->success('success',$url);
郭盛 authored
163 164 165 166
//        var_dump($pdf);exit;
        exit;
    }
郭盛 authored
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
    /**
     * 加载初始化
     *
     * @param string $version 版本号
     * @param string $lng     经度
     * @param string $lat     纬度
     */
    public function init()
    {
        if ($version = $this->request->request('version')) {
            $lng = $this->request->request('lng');
            $lat = $this->request->request('lat');
            $content = [
                'citydata'    => Area::getCityFromLngLat($lng, $lat),
                'versiondata' => Version::check($version),
                'uploaddata'  => Config::get('upload'),
                'coverdata'   => Config::get("cover"),
            ];
            $this->success('', $content);
        } else {
            $this->error(__('Invalid parameters'));
        }
    }

    /**
     * 上传文件
     * @ApiMethod (POST)
     * @param File $file 文件流
     */
    public function upload()
    {
        $file = $this->request->file('file');
        if (empty($file)) {
            $this->error(__('No file upload or server upload limit exceeded'));
        }

        //判断是否已经存在附件
        $sha1 = $file->hash();

        $upload = Config::get('upload');

        preg_match('/(\d+)(\w+)/', $upload['maxsize'], $matches);
        $type = strtolower($matches[2]);
        $typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3];
        $size = (int)$upload['maxsize'] * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0);
        $fileInfo = $file->getInfo();
        $suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
        $suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'file';

        $mimetypeArr = explode(',', strtolower($upload['mimetype']));
        $typeArr = explode('/', $fileInfo['type']);

        //禁止上传PHP和HTML文件
        if (in_array($fileInfo['type'], ['text/x-php', 'text/html']) || in_array($suffix, ['php', 'html', 'htm'])) {
            $this->error(__('Uploaded file format is limited'));
        }
        //验证文件后缀
        if ($upload['mimetype'] !== '*' &&
            (
                !in_array($suffix, $mimetypeArr)
                || (stripos($typeArr[0] . '/', $upload['mimetype']) !== false && (!in_array($fileInfo['type'], $mimetypeArr) && !in_array($typeArr[0] . '/*', $mimetypeArr)))
            )
        ) {
            $this->error(__('Uploaded file format is limited'));
        }
        //验证是否为图片文件
        $imagewidth = $imageheight = 0;
        if (in_array($fileInfo['type'], ['image/gif', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/png', 'image/webp']) || in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp'])) {
            $imgInfo = getimagesize($fileInfo['tmp_name']);
            if (!$imgInfo || !isset($imgInfo[0]) || !isset($imgInfo[1])) {
                $this->error(__('Uploaded file is not a valid image'));
            }
            $imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth;
            $imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight;
        }
        $replaceArr = [
            '{year}'     => date("Y"),
            '{mon}'      => date("m"),
            '{day}'      => date("d"),
            '{hour}'     => date("H"),
            '{min}'      => date("i"),
            '{sec}'      => date("s"),
            '{random}'   => Random::alnum(16),
            '{random32}' => Random::alnum(32),
            '{filename}' => $suffix ? substr($fileInfo['name'], 0, strripos($fileInfo['name'], '.')) : $fileInfo['name'],
            '{suffix}'   => $suffix,
            '{.suffix}'  => $suffix ? '.' . $suffix : '',
            '{filemd5}'  => md5_file($fileInfo['tmp_name']),
        ];
        $savekey = $upload['savekey'];
        $savekey = str_replace(array_keys($replaceArr), array_values($replaceArr), $savekey);

        $uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1);
        $fileName = substr($savekey, strripos($savekey, '/') + 1);
        //
        $splInfo = $file->validate(['size' => $size])->move(ROOT_PATH . '/public' . $uploadDir, $fileName);
        if ($splInfo) {
            $params = array(
                'admin_id'    => 0,
                'user_id'     => (int)$this->auth->id,
                'filesize'    => $fileInfo['size'],
                'imagewidth'  => $imagewidth,
                'imageheight' => $imageheight,
                'imagetype'   => $suffix,
                'imageframes' => 0,
                'mimetype'    => $fileInfo['type'],
                'url'         => $uploadDir . $splInfo->getSaveName(),
                'uploadtime'  => time(),
                'storage'     => 'local',
                'sha1'        => $sha1,
            );
            $attachment = model("attachment");
            $attachment->data(array_filter($params));
            $attachment->save();
            \think\Hook::listen("upload_after", $attachment);
            $this->success(__('Upload successful'), [
                'url' => $uploadDir . $splInfo->getSaveName()
            ]);
        } else {
            // 上传失败获取错误信息
            $this->error($file->getError());
        }
    }
郭盛 authored
290 291 292 293 294 295 296 297 298 299

    public function send($addressee,$url){
        $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
        try {
            //服务器配置
            $mail->CharSet ="UTF-8";                     //设定邮件编码
            $mail->SMTPDebug = 0;                        // 调试模式输出
            $mail->isSMTP();                             // 使用SMTP
            $mail->Host = 'smtp.163.com';                // SMTP服务器
            $mail->SMTPAuth = true;                      // 允许 SMTP 认证
郭盛 authored
300 301
            $mail->Username = 'lh865157660@163.com';                // SMTP 用户名  即邮箱的用户名
            $mail->Password = 'root123456';             // SMTP 密码  部分邮箱是授权码(例如163邮箱)
郭盛 authored
302 303 304
            $mail->SMTPSecure = 'ssl';                    // 允许 TLS 或者ssl协议
            $mail->Port = 465;                            // 服务器端口 25 或者465 具体要看邮箱服务器支持
郭盛 authored
305
            $mail->setFrom('lh865157660@163.com', 'Mailer');  //发件人
郭盛 authored
306 307
            $mail->addAddress($addressee, 'Joe');  // 收件人
            //$mail->addAddress('ellen@example.com');  // 可添加多个收件人
郭盛 authored
308
            $mail->addReplyTo('lh865157660@163.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
郭盛 authored
309 310 311 312 313 314 315 316 317 318
            //$mail->addCC('cc@example.com');                    //抄送
            //$mail->addBCC('bcc@example.com');                    //密送

            //发送附件
            // $mail->addAttachment('../xy.zip');         // 添加附件
            // $mail->addAttachment('../thumb-1.jpg', 'new.jpg');    // 发送附件并且重命名

            //Content
            $mail->isHTML(true);                                  // 是否以HTML文档格式发送  发送后客户端可直接显示对应HTML内容
            $mail->Subject = '授权信息';
郭盛 authored
319
            $mail->Body    = '<a href='.$url.'>'.$url.'</a>';
郭盛 authored
320 321 322 323
            $mail->AltBody = '如果邮件客户端不支持HTML则显示此内容';

            $mail->send();
        }   catch (Exception $e) {
郭盛 authored
324
郭盛 authored
325 326
            }
        }
郭盛 authored
327
}