• curl 抓取图片


    /**
         * curl 抓取图片
         * @param $url
         * @return mixed
         */
        public static function downLoadImage($url)
        {
            $header = array('Expect:');
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $img = curl_exec($ch);
            curl_close ($ch);
    
            //$return_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
            return $img;
        }


    foreach ($productData as $val) {
                $serviceParams['model_id'] = $val['id'];
                // 调用逻辑层
                $qrcodeService->getQrcode($serviceParams);
                // 接收逻辑层处理结果
                if (!is_null($qrcodeService->getError())) {
                    return $this->setError($qrcodeService->getError());
                }
                $qrcode = CommonLib::downLoadImage($qrcodeService->_data);
                //重试一次
                if (!$qrcode) {
                    $qrcode = CommonLib::downLoadImage($qrcodeService->_data);
                }
                //重名重写
                if (isset($name[$val['name']])) {
                    $name[$val['name']]++;
                    $val['name'] = $val['name'] . '(' . $name[$val['name']] . ')';
                }
                $name[$val['name']] = 0;
                file_put_contents(iconv('utf-8', 'gbk', $dir . DIRECTORY_SEPARATOR . $val['name'] . '.png'), $qrcode);
            }
    
  • 相关阅读:
    检查型异常(Checked Exception)与非检查型异常(Unchecked Exception)
    maven跳过单元测试-maven.test.skip和skipTests的区别
    java JFR
    Docker常用命令
    关键字group by 、 Having的 用法
    css特效
    sql
    初识Hibernate之理解持久化类
    Hibernate 搭建
    基本 SQL 之增删改查
  • 原文地址:https://www.cnblogs.com/-mrl/p/6857610.html
Copyright © 2020-2023  润新知