<?php
require_once 'lib/pdf2txt/Pdf2Txt.php';
/**
  * @method PDF转txt识别
  * @author soul
  */
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use KubAT\PhpSimple\HtmlDomParser;
use Illuminate\Database\Capsule\Manager as Capsule;
class OthPdfOcr
{
	public $saveConf = null;
	public $debug = false;
	
	/**
	  * @method 将pdf转txt
	  * @param $pdfFile pdf 文件
	  * @param $totype [bool] 默认:一页一张图  onlyLast:只转最后一张  merge:全部合并一张 onlyFirst:只转第一张
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function pdfToJpg($pdfFile, $totype = '', $toJpgFile = '')
	{
		$imgArr = [];
		if(!empty(mvc::$cfg['urls']['pdfToJpg'])){
			$LibHttp = new LibHttp();
			$html = $LibHttp->fetch(mvc::$cfg['urls']['pdfToJpg'], ['file'=>$pdfFile, "totype"=>$totype]);
			$arr = json_decode($html, true);
			if(is_array($arr) && !empty($arr['img'])){
				return LibFc::ReturnData(true, $arr);
			}
		}
		$imgArr = [];
		try {
			$im = new Imagick();
			$im->setCompressionQuality(100);
			$im->setResolution(200, 200);//设置分辨率 值越大分辨率越高
			$im->readImage($pdfFile);
			$imgNum = $im->getNumberImages();
			if($totype == 'merge')
			{
				if(empty($toJpgFile)) 
					$jpgFile = substr($pdfFile, 0, strrpos($pdfFile, '.')).'_0.jpg';
				else
					$jpgFile = $toJpgFile;
				$canvas = new Imagick();
				foreach ($im as $k => $sub)
				{
					$sub->setImageFormat('png');
					$sub->setResolution(200, 200);
					$sub->stripImage();
					$sub->trimImage(0);
					$width  = $sub->getImageWidth() + 10;
					$height = $sub->getImageHeight() + 10;
					if ($k + 1 == $imgNum) {
						$height += 10;
					} //最后添加10的height
					$canvas->newImage($width, $height, new ImagickPixel('white'));
					$canvas->compositeImage($sub, Imagick::COMPOSITE_DEFAULT, 5, 5);
					$canvas->resetIterator();
				}
				$canvas->appendImages(true)->writeImage($jpgFile);
				$imgArr[] = $jpgFile;
			}
			else
			{
				foreach ($im as $k => $sub)
				{
					if($totype == 'onlyLast' && $k + 1 != $imgNum) continue;
					if(empty($toJpgFile)) 
						$jpgFile = substr($pdfFile, 0, strrpos($pdfFile, '.')).'_'.$k.'.jpg';
					else
						$jpgFile = $toJpgFile;

					$canvas = new Imagick();
					$sub->setImageFormat('png');
					$sub->setResolution(200, 200);
					$sub->stripImage();
					$sub->trimImage(0);
					$width  = $sub->getImageWidth() + 10;
					$height = $sub->getImageHeight() + 10;
					if ($k + 1 == $imgNum) {
						$height += 10;
					} //最后添加10的height
					$canvas->newImage($width, $height, new ImagickPixel('white'));
					$canvas->compositeImage($sub, Imagick::COMPOSITE_DEFAULT, 5, 5);
					$canvas->resetIterator();
					$canvas->appendImages(true)->writeImage($jpgFile);
					$imgArr[] = $jpgFile;
					if($totype == 'onlyFirst') break;
				}
			}
		} catch (Exception $e) {
			return LibFc::ReturnData(true, '#error#'.$pdfFile.'转图失败'.$e->getMessage());
		}
		return LibFc::ReturnData(true, ['count'=>$imgNum, 'img'=>$imgArr]);
	}


	public function getScqdByPdfImgOcr($vin, $pdfFile, $reg, $imgCfg)
	{
		//pdf转图片
		if(!is_array($pdfFile))
		{
			$res = $this->pdfToJpg($pdfFile, $imgCfg['totype']);
			$ocrImgArr = $res['data'];
		}
		else
		{
			$ocrImgArr = $pdfFile;
		}
		if(empty($ocrImgArr['img'])) return LibFc::ReturnData(true, ['error'=>'#error#pdf转图失败']);
		//已经定位到具体图片和位置
		$txtArr = [];
		$MainOcr = new MainOcr();
		foreach($ocrImgArr['img'] as $jpgFile)
		{
			$toJpgFile = str_replace('.jpg', '_thumb.jpg', $jpgFile);
			$thumbData = base64_encode(file_get_contents($toJpgFile));
			$ocrRes = $MainOcr->paddleOcr($thumbData);
			$txtArr[] = implode("\n", $ocrRes['data']);
		}
		var_dump($txtArr);
	}

	
	
	/**
	  * @method pdf转图片识别随车清单信息
	  * @param  $vin  17位车架号
	  * @param  $pdfFile  pdf路径
	  * @param  $reg array [必填] stand_scqd_reg的信息 ['reg_code'=>'gac-toyota', 'reg_wmi'=>'LVG', ...]
	  * @param  $imgCfg array [必填] 配置信息 ['cutsize'=>[]....]
	  * @author soul
	  * @copyright 2020/9/7
	  * @return 
	  */
	public function getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg)
	{
		//pdf转图片
		if(!is_array($pdfFile))
		{
			$res = $this->pdfToJpg($pdfFile, $imgCfg['totype']);
			$ocrImgArr = $res['data'];
		}
		else
		{
			$ocrImgArr = $pdfFile;
		}
		if(empty($ocrImgArr['img'])) return LibFc::ReturnData(true, ['error'=>'#error#pdf转图失败']);
		//已经定位到具体图片和位置
		$isOkImg = false;
		$allHtml = '';
		$wmi = substr($vin, 0, 3);
		foreach($ocrImgArr['img'] as $ik=>$jpgFile)
		{
			if($isOkImg) break;
			$toJpgFile = str_replace('.jpg', '_thumb.jpg', $jpgFile);
			$imgCfg['cutsize'][] = ['size'=>'all'];
			foreach($imgCfg['cutsize'] as $sv)
			{
				if($ik == 1 && in_array($wmi, ['LYV','LVY','YV1','YV4']) && $sv['allpage'] == 2) continue;
				if($isOkImg) break;
				//尺寸和总页数相等才裁剪
				if($sv['size'] == 'all'){
					@copy($jpgFile, $toJpgFile);
				}else{
					if($sv['allpage'] != $ocrImgArr['count']) continue;
					$LibImage = new LibImage();
					$LibImage->thumb($jpgFile, $sv['size'], $toJpgFile, 10);
				}
				//$ocrTypeArr = isset($imgCfg['sce_error']) && stripos($imgCfg['sce_error'], '发动机编号')? ['paddle', '2']: ['paddle','1','2'];
				$ocrTypeArr = ['paddle'];
				$thumbData = base64_encode(file_get_contents($toJpgFile));
				//echo $toJpgFile;
				@unlink($toJpgFile);
				$MainOcr = new MainOcr();
				foreach($ocrTypeArr as $ocrType)
				{
					$addArr = [];
					if($ocrType == 'paddle'){
						$ocrRes = $MainOcr->paddleOcr($thumbData);
						$html = implode("\n", $ocrRes['data']);
					}else{
						$ocrkey = $ocrType == 1? 'baidu_general': null;
						$ocrRes = $MainOcr->baiduOcr($thumbData, $ocrType, $ocrkey);
						$html = implode("\n", $ocrRes['data']['words']);
					}
					if(!empty($imgCfg['strtr'])) $html = strtr($html, $imgCfg['strtr']);
					$allHtml .= '=>'.$html;
					//已经提供型号，只是识别其他信息
					if(!empty($imgCfg['sma_gxb_code_show']))
					{
						$html .= "\n车辆型号:".$imgCfg['sma_gxb_code_show']."\n";
					}
					if(!preg_match('/[0-9-a-z-A-Z]{2,}/', $html, $match)) break;
					if(stripos($html, '型号') === false && stripos($html, '发动机') === false) continue;
					
					$isOkImg = true;
					$txtRes = $this->getHbqdData($vin, $html, $reg);
					if(empty($txtRes['data']['sma']['sma_gxb_code_show']) && empty($txtRes['data']['sma']['sma_engine6'])) continue;

					$addArr = $txtRes['data']['sma'];
					$YpwBase = new YpwBase();
					if(!empty($addArr['sma_gxb_code_show'])){
						//图片识别有错误，检查型号是否在总库
						$res = $YpwBase->get('stand_model_any', ['sma_gxb_code'], sprintf(" and sma_gxb_code = '%s'", LibFc::FormatNum($addArr['sma_gxb_code_show'])), true);
						if(empty($res['data']))
						{
							//if($ocrType != 2) continue;
							//新的型号，但是V8+10+11有记录
							$res = $YpwBase->get('stand_model_any', ['sma_id'], sprintf(" and sma_vin1_8 = '%s' and sma_vin10_12 like '%s%%'", substr($vin, 0, 8), substr($vin, 9, 2)), true);
							if(!empty($res['data']) || !empty($addArr['sma_engine6']))
							{
								unset($addArr['sma_gxb_code_show']);
							}
						}
					}
					if(!empty($addArr['sma_gxb_code_show']) || !empty($addArr['sma_engine6']))
					{
						//有发动机编码的再走一次发动机编码识别
						if(!empty($addArr['sma_engine6']) && strlen($addArr['sma_engine6']) > 5)
							$YpwBase->add('stand_catch_list', ['sce_reg_code'=>'engine6', 'sce_vin'=>$vin, 'sce_engine6'=>$addArr['sma_engine6'], 'sce_level'=>6666]);
						return $this->fillGxbInfo($vin, $addArr);
					}
				}
			}
			//echo $jpgFile;
			@unlink($jpgFile);
		}
		if($allHtml == '=>' && $reg['reg_code'] == 'tftm')
			return LibFc::ReturnData(true, ['error'=>'#end#pdf存在但是无内容']);
		return LibFc::ReturnData(true, ['error'=>'#error#OCR图像识别失败'.$allHtml]);
	}


	/**
	  * @method 将pdf转txt
	  * @param $pdfFile pdf 文件
	  * @param $save [bool]  是否存储txt 默认  true
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function getPdfTxt($pdfFile, $save = true)
	{
		$txtFile = substr($pdfFile, 0, strrpos($pdfFile, '.')).'.txt';
		try {
			$Pdf2Txt = new Pdf2Txt($pdfFile);
			$txt = $Pdf2Txt->toTxt();
			if(!$txt) return LibFc::ReturnData(true, '#error#'.$pdfFile.'转换失败'.$Pdf2Txt->error);
			else if($save) file_put_contents($txtFile,$txt);
		} catch (Exception $e) {
			return LibFc::ReturnData(true, '#error#'.$pdfFile.'转换失败'.$e->getMessage());
		}
		return LibFc::ReturnData(true, $txt);
	}


	/**
	  * @method 将pdf转txt
	  * @param $pdfFile pdf 文件
	  * @param $save [bool]  是否存储txt 默认  true
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function getPdfTxtBySmalot($pdfFile, $save = true)
	{
		$txtFile = substr($pdfFile, 0, strrpos($pdfFile, '.')).'.txt';
		$parser = new \Smalot\PdfParser\Parser();
		try {
			$pdf   = $parser->parseFile($pdfFile);
			$txt = $pdf->getText();
			if($save) file_put_contents($txtFile, $txt);
		} catch (Exception $e) {
			return LibFc::ReturnData(true, '#error#'.$pdfFile.'转换失败'.$e->getMessage());
		}
		return LibFc::ReturnData(true, $txt);
	}


	

	/**
	  * @method 批量将某文件夹的pdf转txt
	  * @param $pdfPath pdf 文件夹
	  * @param $save [bool]  是否存储txt 默认  true
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function batchPdfToTxt($pdfPath, $save = true)
	{
		$iterator = new FilesystemIterator($pdfPath);
		$error = '';
		while ($iterator->valid()) 
		{ // 检测迭代器是否到底了
			if($iterator->getExtension() == 'pdf')
			{
				$txtFile = $pdfPath.str_replace('pdf','txt',$iterator->getFilename());
				$Pdf2Txt = new Pdf2Txt($iterator->getPathname());
				$txt = $Pdf2Txt->toTxt();
				if($txt)
				{
					if($save) file_put_contents($txtFile,$txt);
				} 
				else 
				{
					$error .= $iterator->getPathname().'=>'.$pdf->error."\n";
				}
			}
			$iterator->next();
		}
		if($error != '')
		{
			return LibFc::ReturnData(false, $error);
		}
		else
		{
			return LibFc::ReturnData(true);
		}
	}

	/**
	  * @method 从pdf文件中提取随车清单信息
	  * @param  $html 
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function getHbqdDataFromPdf($pdfFile, $vin, $reg = [])
	{
		$res = $this->getPdfTxt($pdfFile);
		return $this->getHbqdData($vin, $res['data'], $reg);
	}



	/**
	  * @method 提取随车清单信息
	  * @param  $html 
	  * @author soul
	  * @copyright 2020/9/5
	  * @return 
	  */
	public function getHbqdData($vin, $html, $reg = [])
	{
		$wmi = substr($vin, 0, 3);

		//广汽三菱 两个车架号 http://192.168.1.116:88/gmmc/LL66HAB0/526/LL66HAB05JB226526.pdf
		if(preg_match_all('/'.$wmi.'[0-9A-Z]{14}\s+/', $html, $match))
		{
			if(count($match[0]) > 1) $html = substr($html, stripos($html, $vin));
		}

		$addArr = [];

		$reArr = ["（"=>'(',"）"=>')',"\r\n"=>"\n", '：'=>':', '阿尔法�罗密欧'=>'阿尔法·罗密欧', '发动机顺序号'=>'发动机编号'];
		$html = strtr($html, $reArr);
		//OCR识别
		$reArr = [
			"车辆型号:\n发动机编号"=>'车辆型号:',
			"编号:\n"=>'编号:',
			"型号:\n"=>'型号:',
			"型号\n"=>'型号:',
			"编号\n"=>'编号:',
			"续航里程\n"=>'续航里程:',
			"档位数\n"=>'档位数:',
			"产厂:\n"=>'产厂:',
			
		];
		$html = strtr($html, $reArr);
	
		//分隔 5G09/长安标致雪铁龙汽车有限公司11  发动机型号/生产厂： 
		$html = preg_replace('/(\n[^\d][^\n]+)(\d{2} {2,}[^\n]+:\n)/i', "$1\n$2", $html);
		$html = preg_replace('/(\n[^\d][^\n]+)(\d {2,}[^\n]+:\n)/i', "$1\n$2", $html);
		$html = preg_replace('/ +(08 +OBD)/i', "\n$1", $html);
		$html = preg_replace('/ +(18 +厂牌)/i', "\n$1", $html);
		if($this->debug) echo $html;
		//检测html是否含有</td>标签
		$isTd = stripos($html, '</td>') !== false? true: false;
		$allTempReg = [
			//LMXA12AG7LZ399816 出现 VIN和型号一行的情况
			'sma_gxb_code_show'=>[
				//沃尔沃LVYPD10A6JP043955
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/\n *(VC[CD]\d[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/ *(VC[CD]\d[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/ *([A-Z]{2,3}\d{2,}[0-9a-zA-Z\-\/]{4,}) *\n/iUs': ''),
				($isTd? '/<td[^>]*>车辆型号[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>车辆型号[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				($isTd? '/车辆型号[^:\n]*:<\/[^>]+>\s*<[^>]+>([^<]+)/': ''),
				'/车辆型号: *([a-zA-Z]{1,2}[^\n]*) +0\d +商 +标/iUs',
				'/车辆型号: *([a-zA-Z]{1,2}[^\n]*)\n/iUs',
				//奇瑞
				(in_array($wmi, ['LJX','LNJ','LNV','LSC','LSJ','LVM','LVT','LVU','LVV'])? '/\n *(SQR\d{3}[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LDC'])? '/\n *(DC\d{3}[0-9a-zA-Z\-\/]{2,}) *\n/iUs': ''),
				(in_array($wmi, ['LMP'])? '/\n *(DNC\d{4}[0-9a-zA-Z\-\/]{2,}) *\n/iUs': ''),
				(in_array($wmi, ['LB1'])? '/型号: *([a-zA-Z]{2}[^\n]*)\n/iUs': ''),
				(in_array($wmi, ['LE4'])? '/(BJ\d{3,}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				(in_array($wmi, ['LPA'])? '/(CAP\d{3,}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				(in_array($wmi, ['LUZ'])? '/(THZ\d{3,}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				(in_array($wmi, ['LL6'])? '/(GMC[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LL6'])? '/(CFA[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LK6','LZW'])? '/\n *(LZW\d{3,}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				(in_array($wmi, ['LJN'])? '/(ZN\d{3}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				(in_array($wmi, ['LJN'])? '/([a-zA-Z\-\/]{2,}\d{3}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				'/车辆型号: *([a-zA-Z]{1,2}[0-9a-zA-Z\-\/ ]+)/i',
				(substr($wmi, 0, 1) != 'L'? '/车辆型号:([^\n]+)\n/iUs': ''),
				(substr($wmi, 0, 1) != 'L'? '/车辆型号:\n([^\n]+)\n/iUs': ''),
				(in_array($wmi, ['LGD'])? '/\n(EQ[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				//LGDCF31G0JA143759
				(in_array($wmi, ['LGD','LGF','LEW','LGH'])? '/\n([a-zA-Z]{2,}\d{3}[0-9a-zA-Z\-\/]+) *\n/iUs': ''),
				//LUXH61406JB009125
				(in_array($wmi, ['LUX'])? '/(DYM[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
				(in_array($wmi, ['LW4'])? '/(LXA[0-9a-zA-Z\-\/]{3,}) *\n/iUs': ''),
			],
			'sma_engine'=>[
				($isTd? '/<td[^>]*>发动机型号[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>发动机型号[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				'/发动机型号[^:\n]*: *([^\n]*)\n/iUs',
				($isTd? '/<td[^>]*>电动机型号[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>电动机型号[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				'/电动机型号[^:\n]*: *([^\n]*)\n/iUs',
				'/\n *([0-9a-zA-Z][^\n]+)\/神龙汽车有限公司 *\n/iUs',
				'/\n *(SQR[0-9a-zA-Z]{3,}[^\/]+)\/奇瑞汽车股份有限公司 *\n/iUs',
				(in_array($wmi, ['LMP'])? '/\n *(TZ[0-9a-zA-Z]{3,}[^\/]+)\/[^\n]+公司 *\n/iUs': ''),
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/\n *(B[0-9a-zA-Z]{3,}[^\/]+)\/张家口沃尔沃汽车发动机制造有限公司 *\n/iUs': ''),
				(in_array($wmi, ['LE4'])? '/\n\d (\d{6})\/\n/iUs': ''),
				(in_array($wmi, ['LUZ'])? '/\n *([0-9a-zA-Z]{3,}[^\/]+)\/上海汽车电驱动有限公司 *\n/iUs': ''),
				(in_array($wmi, ['LL6'])? '/\n *([0-9a-zA-Z]{3,}[^\/]+)\/三菱汽车工业株式会社 *\n/iUs': ''),
				(in_array($wmi, ['LJN'])? '/\n *([a-zA-Z]{2,}[0-9a-zA-Z]{2,}[^\/\n]*)\/[^\n]*汇川[^\n]+公司*\n/iUs': ''),
				(in_array($wmi, ['LJN'])? '/\n *([a-zA-Z]{2,}[0-9a-zA-Z]{2,}[^\/\n]*)\/[^\n]*绵阳新晨[^\n]+公司*\n/iUs': ''),
				(in_array($wmi, ['LJN'])? '/\n *([a-zA-Z]{2,}[0-9a-zA-Z]{2,}[^\/\n]*)\/[^\n]*东风[^\n]+公司*\n/iUs': ''),
				(in_array($wmi, ['LW4'])? '/\n *([a-zA-Z][0-9a-zA-Z]{2,}[^\/\n]*)\/[^\n]*东安[^\n]+公司*\n/iUs': ''),
				//YCY24120-60  Q25-152E60
				(in_array($wmi, ['LGD','LGF','LEW'])? '/\n *([a-zA-Z][0-9a-zA-Z]{2,}\-[0-9a-zA-Z]{2,})\n/iUs': ''),
				(in_array($wmi, ['LGD','LGF','LEW'])? '/\n *([a-zA-Z][0-9]{2,}\-[0-9a-zA-Z]{2,})\n/iUs': ''),
			],
			'sma_engine6'=>[
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/\n *(\d{6,9}) *\n/iUs': ''),
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/\n *([0-9a-zA-Z ]+\d{6,9}) *\n/iUs': ''),
				($isTd? '/<td[^>]*>发动机编号[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>发动机编号[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				($isTd? '/发动机编号[^:\n]*:<\/[^>]+>\s*<[^>]+>([^<]+)/': ''),
				//B4204T233148601
				(in_array($wmi, ['YV1','YV4'])? '/\n *(B\d{2,}[a-zA-Z]+\d{8,}) *\n/iUs': ''),
				'/发动机编号[^:\n]*: *([^\n]*)\n/iUs',
				(substr($wmi, 0, 1) != 'L'? '/发动机编号:\n([^\n]+)\n/iUs': ''),
				(in_array($wmi, ['LB1'])? '/编号[^:\n]*: *([0-9a-zA-Z]*)\n/iUs': ''),
				(in_array($wmi, ['LGD','LGF','LEW'])? '/\n *([a-zA-Z]+[0-9a-zA-Z]+\d{5,}[a-zA-Z]*) *\n/iUs': ''),
				(in_array($wmi, ['LW4'])? '/\n *([0-9a-zA-Z\-]*\d{6,}[0-9a-zA-Z\-]*) *\n/iUs': ''),
			],
			//变速器型式/档位数：无级变速(CVT)/无
			'sma_tran'=>[
				($isTd? '/<td[^>]*>变速器型式[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>变速器型式[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				'/变速器型式[^:\n]*: *([^\n]*)\n/iUs',
				'/\n *([^:\n]*(自动|手自|手动|无极)[^\n]*) *\n/iUs',
				'/\n *([^:\n]*自动[^\n]*) *\n/iUs',
				'/\n *([^:\n]*手自[^\n]*) *\n/iUs',
				'/\n *([^:\n]*手动[^\n]*) *\n/iUs',
				'/\n *([^:\n]*无级[^\n]*) *\n/iUs',
			],
			'sma_xuhang'=>[
				($isTd? '/<td[^>]*>电池容量[^:\n]*:<\/td>\s*<td[^>]*><[a-zA-Z]+[^>]*>([^<]*)<\/[a-zA-Z]+>/': ''),
				($isTd? '/<td[^>]*>电池容量[^:\n]*:<\/td>\s*<td[^>]*>([^<]*)<\/td>/': ''),
				'/电池容量[^:\n]*: *([^\n]+)\n/iUs',
				//99.8千瓦时/385公里
				'/\n *([^:\n]*千瓦时[^\n]*) *\n/iUs',
				'/\n *([^:\n]*\/\d+公里[^\n]*) *\n/iUs',
			]
		];
		$isGuochan = in_array(substr($vin, 0, 1), ['L','H'])? true: false;
		//进口车
		if(!$isGuochan) 
			$allTempReg['sma_brand'] = [
				(in_array($wmi, ['LYV','LVY','YV1','YV4'])? '/\n *(沃尔沃)\(VOLVO\) *\n/iUs': ''),
				'/商 *标 *:\n([^\n]+) +0\d +汽车分类/iUs',
				'/商 *标 *:\s*([^\n]+)\([^\n]*\n/iUs',
				'/商 *标 *:\s*([^\n]+)\n/iUs',
				'/\n([^\n]+)\n商 *标 *:/iUs',
			];
		
		
		foreach($allTempReg as $filed=>$tRegArr)
		{
			if($filed == 'sma_engine' && !empty($addArr['sma_gxb_code_show']))
			{
				$YpwVin = new YpwVin();
				$eres = $YpwVin->getGxbEngs($addArr['sma_gxb_code_show']);
				foreach($eres['data'] as $eng)
				{
					if(strlen($eng) > 2 && stripos($html, $eng) !== false)
					{
						$addArr[$filed] = $eng;
						break;
					}
				}
				if(!empty($addArr[$filed])) continue;
			}

			foreach($tRegArr as $tReg)
			{
				if(empty($tReg)) continue;
				if(!$isTd && stripos($tReg, '<\/td>') !== false) continue;
				if(preg_match($tReg, $html, $match))
				{
					$fval = trim($match[1]);
					
					if($this->debug) echo $filed, '=>', $tReg, '=>', $fval, "\r\n";

					//多个标签同一行
					if(preg_match('/[ ]+\d{1,2}[ ]+[\x{4e00}-\x{9fa5}]+[ ]*\:/u', $fval, $match2)) 
					{
						$fval = trim(substr($fval, 0, stripos($fval, $match2[0])));
					}
					//01 车辆型号： LZ6510MQ16BM   LMXA12AG7LZ399816
					if($filed == 'sma_gxb_code_show' && preg_match('/ {3,}/', $fval, $tm))
					{
						$fval = trim(substr($fval, 0, stripos($fval, $tm[0])));
					}

					//二次校验
					if($filed == 'sma_engine6')
					{
						if(preg_match('/^CN [A-Z]{2,} /', $fval, $tmc))
						{
							$fval = '';
							continue;
						}
						if($wmi == 'LBV' && preg_match('/[a-zA-Z0-9\-]{6,} ([a-zA-Z0-9\-]{6,})/', $fval, $match2))
						{
							$fval = $match2[1];
						}
						if(preg_match('/([a-zA-Z0-9\- ]{6,})/', $fval, $match2)) 
						{
							$fval = $match2[1];
						}
						else
						{
							$fval = '';
						}
						//至少有一位数字
						if(!preg_match('/[0-9]/', $fval, $match3) || preg_match('/\d{3,}kg/i', $fval, $match3))
						{
							$fval = '';
						}
					}
					else if($filed == 'sma_engine')
					{
						if(stripos($fval, '控制器')) $fval = '';
						if(strrpos($fval, '/'))
						{
							$exArr = explode('/', $fval);
							$tevals = [];
							foreach($exArr as $ek=>$ev)
							{
								if($ek > 0)
								{
									if(!preg_match('/[a-zA-Z0-9]{2,}/', $ev, $match)) break;
									if(stripos($ev, 'TOYOTA') !== false) break;
									//最后一个有中文的直接剔除
									if(count($exArr) == ($ek +1) && (
											!$isGuochan || 
											($isGuochan && preg_match('/[\x{4e00}-\x{9fa5}]/ui', $ev, $match))
										)
									) break;
								}
								$tevals[] = $ev;
							}
							$fval = implode('/', $tevals);
						}
						$fval = strtr($fval, ['前:'=>'', '后:'=>'','前'=>'', '后'=>'', ','=>'/', ';'=>'/', '，'=>'/', '；'=>'/']);
						if(!preg_match('/[a-zA-Z0-9]{'.($isGuochan? 2: 1).',}/', $fval, $match)) $fval = '';

						//发动机型号生产厂:K15-10重庆小康动力有限公司
						if(preg_match('/([^\x{4e00}-\x{9fa5}]+)[\x{4e00}-\x{9fa5}]/u', $fval, $match)) $fval = $match[1];
						if(in_array($wmi, ['LGD','LGF','LEW','LGH']) && strlen($fval) < 3) $fval = '';
					}
					else if($filed == 'sma_gxb_code_show')
					{
						//LGDCH91G7LA111794
						if(in_array($wmi, ['LGD','LGF','LEW','LGH']) && stripos($fval, 'GB') === 0) $fval = '';
						$strlen = strlen(LibFc::FormatNum($fval));
						if(
							$strlen < 2 || $strlen > 48 || 
							(in_array(substr($vin, 0, 1), ['L', 'H']) && $strlen < 4)
						)
							$fval = '';
					}

					if(in_array($fval, ['空', '无', '无Ah', '无Ah/无', 'Ah/km'])) $fval = '';

					if($filed == 'sma_xuhang')
					{
						if(stripos($fval, '法人')) $fval = '';
					}

					if($filed == 'sma_brand' && preg_match('/^[0-9]/', $fval, $match)) $fval = '';

					//匹配的内容是车架号的一部分
					if(stripos($vin, $fval) !== false) $fval = '';

					if(!empty($fval))
					{
						$fval = strip_tags($fval);
						$addArr[$filed] = $fval;
						
						if($filed == 'sma_gxb_code_show') $html = str_replace($fval, '', $html);
						//$html = str_ireplace($match[1], '#####', $html);
						break;
					}
				}
			}
			if(empty($addArr[$filed]) && in_array($filed, ['sma_gxb_code_show', 'sma_engine']))
			{
				$res = $this->fotmatHbQdFromHas($vin, $html, $filed);
				if(!empty($res['val'])) $addArr[$filed] = $res['val'];
			}
		}

		
		
		//重新处理发动机  LJNDGV2T7KN000062
		/*if(!empty($addArr['sma_gxb_code_show']))
		{
			foreach(['sma_engine'] as $filed)
			{
				$res = $this->fotmatHbQdFromGxb($vin, $html, $addArr['sma_gxb_code_show'], $filed, $addArr[$filed]);
				if(!empty($res['val'])) $addArr[$filed] = $res['val'];
			}
		}*/

		if(empty($addArr['sma_gxb_code_show']) && empty($addArr['sma_engine6']))
		{
			//沃尔沃特殊处理，只有发动机编码，没有型号 LYVXF15D0LL175557
			if(in_array($wmi, ['LYV','LVY'])){
				if(preg_match('/\n *(\d{7,}) *\n/iUs',$html, $match)){
					$addArr['sma_engine6'] = $match[1];
				}
			}else{
				return LibFc::ReturnData(true, ['error'=>'#error#车辆型号无法匹配']);
			}
		}

		
		if(isset($addArr['sma_tran'])) 
		{
			$renull = ['/--'=>'', 'æå¨/5'=>'', '/不适用'=>'', '/无'=>'', '/0'=>'', '	'=>'', '空'=>''];
			$addArr['sma_tran'] = strtr($addArr['sma_tran'], $renull);
			if($addArr['sma_tran'] == '无')
			{
				unset($addArr['sma_tran']);
			}
			else if(preg_match('/(.*\/\d+) +\d+/', $addArr['sma_tran'], $match))
			{
				//LE44M8HB0LL000183
				$addArr['sma_tran'] = $match[1];
			}
		}
		if(isset($addArr['sma_xuhang']))
		{
			$renull = ['/不适用'=>'', '/无'=>'', '	'=>'', '空'=>''];
			$addArr['sma_xuhang'] = strtr($addArr['sma_xuhang'], $renull);
			if($addArr['sma_xuhang'] == '无') unset($addArr['sma_xuhang']);
		}
		
		//车辆生产日期	 2018	年01月29日
		$html = strip_tags($html);
		if(preg_match('/生产日期:? *(\d{4}) *(?:年|-|\/) *(\d{1,2}) *(?:月|-|\/) *(\d{1,2}) *日?/', $html, $match)){
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}
		else if(preg_match('/生产日期:? *(\d{4}) *:?年 *(\d{1,2}) *月 *(\d{1,2}) *日/', $html, $match)){
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}
		else if(stripos($html, '生产日期') && preg_match('/\n *东风[^\n]+ *\n *(\d{4}) *年 *(\d{1,2}) *月 *(\d{1,2}) *日/iUs', $html, $match)){
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}
		else if(preg_match('/年 *(\d{1,2}) *月 *(\d{1,2}) *日(\d{4}) *生产日期:?/', $html, $match)){
			//LL665BC05HB002082  
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[3].'-'.$match[1].'-'.$match[2]));
		}
		else if($isGuochan && stripos($html, '生产日期') && preg_match('/(\d{4}) *年 *(\d{1,2}) *月 *(\d{1,2}) *日/', $html, $match))
		{//2023年06月07日
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(preg_match('/生产日期:? *日 *(\d{1,2}) *月 *(\d{1,2}) *年 *(\d{4})/', $html, $match)){
			//LL67GAB02LB203439    
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[3].'-'.$match[2].'-'.$match[1]));
		}else if(preg_match('/生产日期:? *(\d{4}) *年 *(\d{1,2})  *(\d{1,2}) *月 *日/', $html, $match)){
			//奔驰 生产日期： 2025 年09 22月 日
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(preg_match('/进口日期:? *(\d{4}) *年 *(\d{1,2}) *月 *(\d{1,2}) *日/', $html, $match)){
			$addArr['sma_jkyear'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(preg_match('/年 *(\d{1,2}) *月 *(\d{1,2}) *日(\d{4}) *\n/', $html, $match)){
			//LL66HCS04HB170617
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[3].'-'.$match[1].'-'.$match[2]));
		}else if(preg_match('/\n *(\d{4}) *年 *(\d{1,2}) *月 *(\d{1,2}) *日 *\n/', $html, $match)){
			//2019年01月12日
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(preg_match('/ +(\d{4}) +[^ ]+ +(\d{2}) +[^ ]+ +(\d{2}) +/', $html, $match)){
			//2018	¤	11	8	28	
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(stripos($html, '日期') === false && preg_match('/(\d{4}) *年 *(\d{1,2}) *月 *(\d{1,2}) *日/', $html, $match)){
			//沃尔沃部分LVYPD10D4KP111097  2019年01月12日
			$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
		}else if(!empty($addArr['sma_engine6']) || in_array($reg['reg_code'], ['sftm', 'tftm', 'benzfj','benzbj', 'hongyan', 'volvocars', 'weichai', 'chenggong', 'zznissan', 'dfl', 'caky', 'changan'])){
			//LVYPD25D3LP177043  LZFH18M19JD020305
			//沃尔沃特殊处理
		}else{
			return LibFc::ReturnData(true, ['error'=>'#error#生产日期无法匹配']);
		}
		if(!empty($addArr['sma_year']) && strlen($addArr['sma_year']) == 10 && strtotime($addArr['sma_year']) > strtotime('+7 day')) unset($addArr['sma_year']);
		if(!empty($addArr['sma_jkyear']) && strlen($addArr['sma_jkyear']) == 10 && strtotime($addArr['sma_jkyear']) > strtotime('+7 day')) unset($addArr['sma_jkyear']);
		$isJinkou = !in_array(substr($vin, 0, 1), ['L', 'H'])? true: false;
		if($isJinkou && !empty($addArr['sma_year']) && strlen($addArr['sma_year']) == 10 && stripos($html, '生产日期') === false) unset($addArr['sma_year']);
		if($isJinkou && strlen($addArr['sma_year']) == 10 && substr($addArr['sma_year'], -2) == '01')
			$addArr['sma_year'] = date('Y-m', strtotime($addArr['sma_year']));
		return $this->fillGxbInfo($vin, $addArr);
	}

	
	//无法匹配到数据时直接从已有的数据中匹配
	private function fotmatHbQdFromHas($vin, $html, $filed)
	{
		$vin8 = substr($vin, 0, 8);
		$arr = ['val'=>''];
		$cacheFile = mvc::$cfg['AUTOLOAD']['Oth']['path'].'cache/vinReg.php';
		$cacheArr = [];
		if(file_exists($cacheFile)) $cacheArr = include($cacheFile);
		if(!is_array($cacheArr)) $cacheArr = [];
		//缓存不存在，或者已经到期，重新获取
		if(empty($cacheArr[$vin8][$filed]) || $cacheArr[$vin8][$filed]['etime'] < time())
		{
			$YpwBase = new YpwBase();
			$res = $YpwBase->get('stand_model_any', ['distinct '.$filed.' as vals'], sprintf(" and sma_vin1_8 = '%s' and (sma_from != 'catch' OR (sma_from = 'catch' AND LENGTH(sma_engine6) > 5)) and %s != '' order by length(%s) desc ", $vin8, $filed, $filed));
			$cacheArr[$vin8][$filed]['vals'] = array_column($res['data'], 'vals');
			$cacheArr[$vin8][$filed]['etime'] = time()+600;
			LibFc::ArraySave($cacheArr, $cacheFile);
		}
		$vals = $cacheArr[$vin8][$filed]['vals'];
		foreach($vals as $val)
		{
			$val = strtr($val, ['/'=>'\/']);
			if(preg_match('/('.$val.'[^\n]*)\n/iUs', $html, $match))
			{
				//$fval = trim($match[1]);
				$fval = $val;
				//多个标签同一行
				if(preg_match('/[ ]+\d{1,2}[ ]+[\x{4e00}-\x{9fa5}]+[ ]*\:/u', $fval, $match2)) 
				{
					$fval = trim(substr($fval, 0, stripos($fval, $match2[0])));
				}
				if($filed == 'sma_engine')
				{
					if(stripos($fval, '/')) $fval = substr($fval, 0, stripos($fval, '/'));
					if(!preg_match('/[a-zA-Z][a-zA-Z0-9]/', $fval, $match)) $fval = '';
				}

				if(!empty($fval))
				{
					$arr['val'] = $fval;
					break;
				}
			}
		}
		return $arr;
	}
	

	//从型号中匹配匹配其他信息
	private function fotmatHbQdFromGxb($vin, $html, $gxb, $filed, $oldval = '')
	{
		$gxb = LibFc::FormatNum($gxb);
		$arr = ['val'=>''];
		$cacheFile = mvc::$cfg['AUTOLOAD']['Oth']['path'].'cache/gxbReg.php';
		$cacheArr = [];
		if(file_exists($cacheFile)) $cacheArr = include($cacheFile);
		if(!is_array($cacheArr)) $cacheArr = [];
		//缓存不存在，或者已经到期，重新获取
		if(empty($cacheArr[$gxb][$filed]) || $cacheArr[$gxb][$filed]['etime'] < time())
		{
			$YpwBase = new YpwBase();
			$res = $YpwBase->get('stand_model_any', ['distinct '.$filed.' as vals'], sprintf(" and sma_gxb_code = '%s' and (sma_from != 'catch' OR (sma_from = 'catch' AND LENGTH(sma_engine6) > 5)) and %s != '' ORDER BY length(%s) desc", $gxb, $filed, $filed));
			$cacheArr[$gxb][$filed]['vals'] = array_column($res['data'], 'vals');
			$cacheArr[$gxb][$filed]['etime'] = time()+600;
			LibFc::ArraySave($cacheArr, $cacheFile);
		}
		$vals = $cacheArr[$gxb][$filed]['vals'];
		//原值已经在里面，不再匹配
		if(!empty($oldval) && in_array($oldval, $vals))
		{

		}
		else
		{
			foreach($vals as $val)
			{
				$val = strtr($val, ['/'=>'\/']);
				if(preg_match('/('.$val.'[^\n]*)\n/iUs', $html, $match))
				{
					//$fval = trim($match[1]);
					$fval = $val;
					//多个标签同一行
					if(preg_match('/[ ]+\d{1,2}[ ]+[\x{4e00}-\x{9fa5}]+[ ]*\:/u', $fval, $match2)) 
					{
						$fval = trim(substr($fval, 0, stripos($fval, $match2[0])));
					}
					if($filed == 'sma_engine')
					{
						if(stripos($fval, '/')) $fval = substr($fval, 0, stripos($fval, '/'));
						if(!preg_match('/[a-zA-Z][a-zA-Z0-9]/', $fval, $match)) $fval = '';
					}

					if(!empty($fval))
					{
						$arr['val'] = $fval;
						break;
					}
				}
			}
		}
		return $arr;
	
	}


	/**
	  * @method 根据工信部型号填充信息
	  * @param  $addArr array ['sma_gxb_code_show'=>'必填', 'sma_vin'=>'必填'...]
	  * @author soul
	  * @copyright 2020/10/6
	  * @return 
	  */
	public function fillGxbInfo($vin, $addArr)
	{
		if(isset($addArr['sma_tran'])) 
		{
			$renull = ['/--'=>'', 'æå¨/5'=>'', '/不适用'=>'', '/无'=>'', '/0'=>'', '	'=>''];
			$addArr['sma_tran'] = strtr($addArr['sma_tran'], $renull);
			if($addArr['sma_tran'] == '无')
			{
				unset($addArr['sma_tran']);
			}
			else if(preg_match('/(.*\/\d+) +\d+/', $addArr['sma_tran'], $match))
			{
				//LE44M8HB0LL000183
				$addArr['sma_tran'] = $match[1];
			}
		}
		if(isset($addArr['sma_xuhang']))
		{
			$renull = ['/不适用'=>'', '/无'=>'', '	'=>''];
			$addArr['sma_xuhang'] = strtr($addArr['sma_xuhang'], $renull);
			if($addArr['sma_xuhang'] == '无') unset($addArr['sma_xuhang']);
		}

		if(!empty($addArr['sma_gxb_code_show']) && !empty($vin))
		{
			$LibYpApi = new LibYpApi();
			$res = $LibYpApi->Get('vin/catchGxbcodeInfo', [], ['gxbNum'=>$addArr['sma_gxb_code_show'], 'gxbAllMatch'=>1, 'vin'=>$vin]);
			$arr = $res['data'];
			if(!empty($arr['merge']['sma_brand']))
			{
				return $this->fillVinByGxbMerger($vin, $addArr, $arr['merge']);
			}
		}
		return LibFc::ReturnData(true,  ['sma'=>$addArr]);
	}

	
	
	public function fillVinByGxbMerger($vin, $addArr, $mergeArr, $ocrtxt = '')
	{
		//进口从sma获取数据，数据不合并
		if(!empty($mergeArr['sma_brand']) && (empty($mergeArr['from']) ||$mergeArr['from'] != 'sma'))
		{
			if($addArr['sma_gxb_code_show'] != $mergeArr['sma_gxb_code_show'] && LibFc::FormatNum($addArr['sma_gxb_code_show']) == LibFc::FormatNum($mergeArr['sma_gxb_code_show']))
			{
				$addArr['sma_gxb_code_show'] = $mergeArr['sma_gxb_code_show'];
			}
			$filedArr = ["sma_brand", "sma_engine", "sma_cc", "sma_kw", "sma_length", "sma_width","sma_height", "sma_wheel", "sma_axle","sma_weight","sma_passenger","sma_vtype"];
			if(!empty($mergeArr['sma_vin_full']))
			{
				//判断前8是否正确
				$vin1_8 = substr($vin, 0, 8);
				$match = false;
				foreach(explode(',', $mergeArr['sma_vin_full']) as $t8)
				{
					if($t8 == $vin1_8)
					{
						$match = true;
						break;
					}
				}
				if(!$match) return LibFc::ReturnData(true, ['error'=>'#error#车架号前8与工信部型号不匹配']);
			}

			foreach($filedArr as $filed)
			{
				if(empty($mergeArr[$filed])) continue;
				$temp = explode(',', $mergeArr[$filed]);
				if(count($temp) == 1 && !empty($temp[0]))
				{
					$temp[0] = $filed == 'sma_engine' && stripos($temp[0], '#') ? substr($temp[0], 0, stripos($temp[0], '#')): $temp[0];
					$addArr[$filed] = $temp[0];
				}
				else if(count($temp) > 1 && $filed == 'sma_engine' && !empty($addArr['sma_engine']))
				{//发动机已经确认，填充功率排量
					$matchengs = [];
					$reArr = [' '=>'', '-'=>''];
					foreach($temp as $tempv)
					{
						$t = explode('#', $tempv);
						$ismatch = false;
						if(strtr($t[0], $reArr) == strtr($addArr['sma_engine'], $reArr))
						{
							$ismatch = true;
						}
						else
						{//LA91D61D3H1HZG018 通过发动机号码查询只有一个电机 JAS70-D1-R/JAS70-D1-R    多个电机 IM171601/IM171301
							if(strlen($addArr['sma_engine']) >= 12 && stripos($addArr['sma_engine'], '/'))
							{
								$tengs = explode('/', $addArr['sma_engine']);
								//前3是否一样
								if(substr($tengs[0], 0, 3) == substr($tengs[1], 0, 3) && strtr($t[0], $reArr) == strtr($tengs[0], $reArr))
								{
									$ismatch = true;
								}
							}
						}
						if($ismatch) $matchengs[$tempv] = $t;
					}

					if(empty($matchengs))
					{
						if(empty($addArr['sma_engine6']))
							unset($addArr['sma_engine']);
					}
					else if(count($matchengs) == 1 || (count($matchengs) == 2 && !empty($matchengs[$addArr['sma_engine']])))
					{//只有一个匹配的 || 有两个但是其中一个没有功率排量
						unset($matchengs[$addArr['sma_engine']]);
						foreach($matchengs as $t)
						{
							if(!empty($t[1])) $addArr['sma_kw'] = $t[1];
							if(!empty($t[2])) $addArr['sma_cc'] = $t[2];
							break;
						}
					}
					else
					{
						//LFCDKE5P0J1009101 多个功率的不填充
					}
				}
			}
		}
		
		if(!empty($ocrtxt))
		{
			//通过文本匹配相应项
			$OthVinImg = new OthVinImg();
			$imgType = $OthVinImg->getImgType($ocrtxt, $vin);
		
			if($imgType == 2)
			{
				$replace = ["（"=>'(',"）"=>')',"\r\n"=>"\n", '：'=>':'];
				$ocrtxt = strtr($ocrtxt, $replace);
				//2011011101515838
				$ocrtxt = preg_replace('/\d{12,}/', "", $ocrtxt);
				
				$ocrFileds = ["sma_passenger", 'sma_engine', 'sma_weight', 'sma_kw'];
				foreach($ocrFileds as $filed){
					if(!empty($addArr[$filed])) continue;

					switch($filed)
					{
						case 'sma_passenger': 
							$temp = explode(',', $mergeArr[$filed]);
							foreach($temp as $tempv)
							{
								if(!empty($tempv) && (
									preg_match('/人数:? *'.$tempv.'/i', $ocrtxt, $tmatch) || 
									preg_match('/位数:? *'.$tempv.'/i', $ocrtxt, $tmatch) || 
									preg_match('/:? *'.$tempv.' *人/i', $ocrtxt, $tmatch)
								))
								{
									$addArr[$filed] = $tempv;
									break;
								}
							}
						break;
						case 'sma_weight': 
							$temp = explode(',', $mergeArr[$filed]);
							foreach($temp as $tempv)
							{
								if(!empty($tempv) && (
									preg_match('/质量:? *'.$tempv.'/i', $ocrtxt, $tmatch) || 
									preg_match('/\n *'.$tempv.' *(k|[a-z]?g|\n)/i', $ocrtxt, $tmatch)
								))
								{
									$addArr[$filed] = $tempv;
									break;
								}
							}
						break;
						case 'sma_engine':
							$temp = explode(',', $mergeArr[$filed]);
							$kwArr = [];
							$engsArr = [];
							foreach($temp as $tempv)
							{
								$t = explode('#', $tempv);
								$engname = $t[0];
								if(empty($engname)) continue;

								if(!empty($engname) && (
									preg_match('/号:? *'.$engname.'[^a-zA-Z0-9]/i', $ocrtxt, $tmatch) ||
									preg_match('/\n *'.$engname.'[^a-zA-Z0-9]/i', $ocrtxt, $tmatch)
								))
								{
									$addArr['sma_engine'] = $engname;
									if(!empty($t[1])) $addArr['sma_kw'] = $t[1];
									if(!empty($t[2])) $addArr['sma_cc'] = $t[2];
									break;
								}
								$kwArr[$t[1]][] = $tempv;
								$engsArr[$tempv] = $t;
							}

							
							//取4位  //至少两位数字
							if(empty($addArr['sma_engine']))
							{
								$matchByArr = [];
								foreach($engsArr as $ek=>$ev)
								{
									$eng = $ev[0];
									$englen = strlen($eng);
									if($englen < 4) continue;
									$matchlen = 4;
									for($i = 0; $i <= $englen - $matchlen; $i++)
									{
										$tm = substr($eng, $i, $matchlen);
										//至少1位数字
										if(strlen($tm) < $matchlen || !preg_match('/[0-9]/', $tm, $match) || stripos($vin, $tm) !== false) continue;
										if(preg_match('/'.$tm.'/i', $ocrtxt, $tmatch))
										{
											$matchByArr[$tm][$ek] = $ev;
										}
									}
								}

								foreach($matchByArr as $tm=>$evs)
								{
									if(count($evs) == 1)
									{
										$t = array_shift($evs);
										$addArr['sma_engine'] = $t[0];
										if(!empty($t[1])) $addArr['sma_kw'] = $t[1];
										if(!empty($t[2])) $addArr['sma_cc'] = $t[2];
										break;
									}
								}
							}
							
							//功率反确认发动机 LEFAFCG24DHN94905
							if(empty($addArr['sma_engine']))
							{
								foreach($kwArr as $tkw=>$tempv)
								{
									$tempv = array_unique($tempv);
									if(count($tempv) == 1 && (
										preg_match('/功率:?[\n ]*'.$tkw.'/i', $ocrtxt, $tmatch) || 
										preg_match('/\n *'.$tkw.'[\n ]*kw/i', $ocrtxt, $tmatch) ||
										preg_match('/功[\x{4e00}-\x{9fa5}]:?[\n ]*'.$tkw.'[\n ]*kw/iu', $ocrtxt, $tmatch)
									))
									{
										$t = explode('#', $tempv[0]);
										$addArr['sma_engine'] = $t[0];
										if(!empty($t[1])) $addArr['sma_kw'] = $t[1];
										if(!empty($t[2])) $addArr['sma_cc'] = $t[2];
										break;
									}
								}
							}
							
						break;
						case 'sma_kw':
							$temp = explode(',', $mergeArr[$filed]);
							foreach($temp as $tempv){
								if(!empty($tempv) && (
									preg_match('/功率:?[\n ]*'.$tempv.'/iu', $ocrtxt, $tmatch) || 
									preg_match('/'.$tempv.'[\n ]*kw/i', $ocrtxt, $tmatch) || 
									preg_match('/功[\x{4e00}-\x{9fa5}]:?[\n ]*'.$tempv.'[\n ]*kw/iu', $ocrtxt, $tmatch)
								)){
									$addArr[$filed] = $tempv;
									break;
								}
							}
						break;
					}
				
				}
			}
		}
		
		return LibFc::ReturnData(true,  ['sma'=>$addArr]);
	}


	/**
	  * @method 采集车架号信息
	  * @param  $vin  17位车架号
	  * @param  $reg string [必填] stand_scqd_reg的信息 ['reg_code'=>'gac-toyota', 'reg_wmi'=>'LVG', ...]
	  * @param  $cache bool [必填] 默认true  如果有缓存是否使用缓存，检测生命线时用否   
	  * @author soul
	  * @copyright 2020/9/7
	  * @return 
	  */
	public function onlyCatchVin($vin, $reg, $cache = true, $othArr = [])
	{
		//车架号不存在的返回结果
		$nullRes = ['error'=>'', 'sma'=>[]];

		//确定存储路径
		$tk = !empty(mvc::$cfg['SCQD']['code'][$reg['reg_code']]) ?  mvc::$cfg['SCQD']['code'][$reg['reg_code']]: mvc::$cfg['SCQD']['index'];
		$SCQDArr =  mvc::$cfg['SCQD'][$tk];
		$mainPdfRoot = $SCQDArr['save'];
		$midPath = $reg['reg_code'].'/'.substr($vin, 0, 8).'/'.substr($vin, -3).'/';
		$pdfDir = $mainPdfRoot.$midPath;
		$this->saveConf = $SCQDArr;
		$this->saveConf['minpath'] = $midPath;
		$pdfFile = $pdfDir.$vin.'.pdf';
		$txtPdf = $pdfDir.$vin.'.txt';
		$htmlPdf = $pdfDir.$vin.'.html';
		$imgFile = $pdfDir.$vin.'.jpg';
		
		//旧路径转新
		$oldDir = $mainPdfRoot.$reg['reg_code'].'/'.substr($vin, 0, 8).'/';
		if(file_exists($oldDir.$vin.'.pdf')) rename($oldDir.$vin.'.pdf', $pdfFile);
		if(file_exists($oldDir.$vin.'.txt')) rename($oldDir.$vin.'.txt', $pdfFile);
		
		$LibHttp = new LibHttp();
		$LibHttp->timeout = 30;
		switch($reg['reg_code'])
		{
			case 'engine6':
				if(empty($othArr['vin'])) $othArr['vin'] = $vin;
				
				$LibYpApi = new LibYpApi(mvc::$cfg['YPAPILOC']);
				$txtRes = $LibYpApi->Get('vin/catchVinQingdan', $othArr, [], true);
				if($txtRes['status'] && is_array($txtRes['data'])){
					$addArr = [];
					foreach($txtRes['data'] as $tk=>$tv){
						if(stripos($tk, 'sma_') === 0)
							$addArr[$tk] = $tv;
					}
					if(empty($addArr['sma_engine6'])) $addArr['sma_engine6'] = $othArr['engine6'];
					return $this->fillGxbInfo($vin, $addArr);
				}
				else if(stripos($txtRes['data'], '未公开') !== false){
					return LibFc::ReturnData(true, ['error'=>'#end#未公开']);
				}else if(stripos($txtRes['data'], '尚未上传') !== false){
					return LibFc::ReturnData(true, ['error'=>'#end#尚未上传']);
				}else if(stripos($txtRes['data'], '不符') !== false){
					return LibFc::ReturnData(true, ['error'=>'#end#不符']);
				}else if(
					stripos($txtRes['data'], '请重试') !== false || 
					stripos($txtRes['data'], '清单获取失败') !== false || 
					stripos($txtRes['data'], '验证码') !== false || 
					stripos($txtRes['data'], 'Bad Gateway') !== false ||
					stripos($txtRes['data'], '查询时间') !== false
				){
					return LibFc::ReturnData(true, ['error'=>'#again#'.$txtRes['data']]);
				}
				else if(!empty($txtRes['data'])){
					return LibFc::ReturnData(true, ['error'=>'#error#'.$txtRes['data']]);
				}else{
					return LibFc::ReturnData(true, ['error'=>'#again#'.$txtRes['data']]);
				}
			break;
			//广汽丰田
			case 'gac-toyota':
				$exists = $cache && file_exists($txtPdf);
				if(!$exists)
				{
					$html = $LibHttp->fetch('http://about.gac-toyota.com.cn/gw/index.php/campaign/ep/query', ['vin'=>$vin]);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#html获取失败'.$html]);
					if(!empty($htmlArr['data']['url']))
					{
						$html = $LibHttp->fetch($htmlArr['data']['url']);
						$html = strip_tags($html);
						if(stripos($html, $vin) !== false)
						{
							LibDir::CreateDir($pdfDir);
							file_put_contents($txtPdf, $html);
							$exists = true;
						}
						else if(stripos($html, '未找到该VIN码') !== false)
						{
							return LibFc::ReturnData(true, ['error'=>'#end#未找到该VIN码']);
						}
						else
						{
							return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						}
					}
					else if(stripos($htmlArr['msg'], '不存在') !== false)
					{
						return LibFc::ReturnData(true, ['error'=>'#end#不存在']);
					}
				}
				else
				{
					$html = file_get_contents($txtPdf);
				}
				
				if($exists && $html) return $this->getHbqdData($vin, $html, $reg);
			break;
			case 'toyota':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists){
					$url = 'https://www.orangebj.com/environmental-information/check.php';
					$html = $LibHttp->fetch($url, ['vin1'=>$vin]);
					if(stripos($html, '未查询到数据')) return LibFc::ReturnData(true, ['error'=>'#end#未查询到数据']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			//东南
			case 'soueast':
				$exists = $cache && file_exists($txtPdf);
				if(!$exists)
				{
					$url = 'https://ephone.soueast-motor.com/report?callback=callback&action=custom&vin='.$vin.'&_='.sprintf('%d', microtime(true)*1000);
					$html = $LibHttp->fetch($url);
					LibDir::CreateDir($pdfDir);
					file_put_contents($txtPdf, $html);
					$exists = true;
				}
				else
				{
					$html = file_get_contents($txtPdf);
				}
				if($exists && $html)
				{
					$html = substr($html, 9, -1);
					$htmlArr = json_decode($html, true);
					if(is_array($htmlArr) && !empty($htmlArr['info']['vin']))
					{
						if($htmlArr['info']['vin'] == $vin && !empty($htmlArr['info']['unit_name']) && !empty($htmlArr['info']['downlineDate']))
						{
							$addArr = [
								'sma_gxb_code_show'=>$htmlArr['info']['unit_name'],
								'sma_year'=>$htmlArr['info']['downlineDate']
							];
							if(!empty($htmlArr['info']['engine_model']))
								$addArr['sma_engine'] = substr($htmlArr['info']['engine_model'], 0, stripos($htmlArr['info']['engine_model'], '/'));
							if(!empty($htmlArr['info']['bsqxs']))
								$addArr['sma_tran'] = $htmlArr['info']['bsqxs'];
							return $this->fillGxbInfo($vin, $addArr);
						}
						else
						{
							return LibFc::ReturnData(true, ['error'=>'#error#车架号不符'.$html]);
						}
					}
					else if(is_array($htmlArr))
					{
						return LibFc::ReturnData(true, ['error'=>'#end#'.$html]);
					}
					else
					{
						return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					}
				}
			break;
			case 'cheryjaguarlandrover':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists){
					$url = 'https://cdn.cheryjaguarlandrover.com/upload/pdf/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'Access Denied')) return LibFc::ReturnData(true, ['error'=>'#end#Access Denied']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'changan-mazda':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://www.changan-mazda.com.cn/pdf/index.php/pdf/find?&vin='.$vin.'&v='.sprintf('%d', microtime(true)*1000);
					$html = $LibHttp->fetch($url);
					if($html == '')  return LibFc::ReturnData(true, ['error'=>'#end#空']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'changan':
				$minsize = 1024*100;
				$exists = $cache && file_exists($imgFile) && filesize($imgFile) > $minsize;
				$LibHttp->timeout = 60;
				$imgdata = '';
				if(!$exists){
					$YpwBase = new YpwBase();
					$res = $YpwBase->get('stand_vin_file', ['vf_url'], sprintf(" and vf_vin='%s' and vf_url like '%%%s%%' limit 1", $vin, $reg['reg_code']), true);
					if($res['data']){
						$imghtml = $LibHttp->fetch($res['data']['vf_url']);
						if(strlen($imghtml) > $minsize){
							$exists = true;
							$imgdata = base64_encode($imghtml);
						}
					}
					if(!$exists){
						$imgUrl = 'http://192.168.1.177/changan/'.substr($vin, -3).'/'.$vin.'.jpg';
						$imghtml = $LibHttp->fetch($imgUrl);
						if(strlen($imghtml) > $minsize){
							$exists = true;
							LibDir::CreateDir($pdfDir);
							file_put_contents($imgFile, $imghtml);
							$imgdata = base64_encode($imghtml);
						}
					}
				}else{
					$imgdata = base64_encode(file_get_contents($imgFile));
				}

				$LibHttp->timeout = 60;
				$url = 'http://ats.changan.com.cn/guanwang/list_carInformationPublic.shtml?pageNo=1&vin_code='.$vin.'&code=&pageSizes=20';
				$html = $LibHttp->fetch($url);
				$html = preg_replace('/<!--.*?-->/s', '', $html);
				$tres = [];
				if(preg_match('/<td\s*>(CN[^<]+)<\/td>\s*<td\s*>(S[^<]+)<\/td>\s*<td\s*>('.$vin.')<\/td>\s*<td\s*>(.*)<\/td>\s*<td\s*>(.*)<\/td>\s*<td\s*><input\s+type="text"\s+value="([^"]*)"/iUs', $html, $match)){
					$addArr = ['sma_gxb_code_show'=>$match[2]];
					//EPC编码 {"信息公开编号":"CN QQ G6 Z2 0216000556 000001","车型":"SC7151AAB6","VIN号":"LS5A3DKE7LA700184","定编":"5012","选装":"CNH3102","imgid":"64f9aa8b-c0ab-4f48-986b-43c293320f71","详情":"64f9aa8b-c0ab-4f48-986b-43c293320f71"}
					$tArr = [
						'cha_code'=>$match[1],	
						'cha_model'=>$match[2],	
						'cha_vin'=>$vin,
						'cha_delimit'=>$match[4],
						'cha_optional'=>$match[5],
						'cha_info'=>$match[6],
						'lnk_extend_code'=>$match[2].'.'.$match[5],
						'vin1_8'=>substr($vin, 0, 8),
						'vin10_11'=>substr($vin, 9, 2),
						'vin_12_17'=>substr($vin, 11, 6)
					];
					$tArr['cha_gxb_code'] = LibFc::FormatNum($tArr['cha_model']);
					$tArr['lnk_extend_code'] = $tArr['cha_model'].'.'.$tArr['cha_optional'];
					if(!$exists){
						$imgUrl = 'http://ats.changan.com.cn/guanwang/getPhoto_Blob.shtml?keyName=v_id&keyVal='.$match[6];
						$imghtml = $LibHttp->fetch($imgUrl);
						if(strlen($imghtml) > $minsize){
							$exists = true;
							LibDir::CreateDir($pdfDir);
							file_put_contents($imgFile, $imghtml);
							$imgdata = base64_encode($imghtml);
						}
					}
				}else if(stripos($html, '没找到符合')){
					$tres = ['error'=>'#end#无'];
				}else{
					$tres = ['error'=>$vin.'#error#'.$html];
				}
				if($exists){
					$MainOcr = new MainOcr();
					$res = $MainOcr->paddleOcr($imgdata);
					$txt = implode("\r\n", $res['data']);
					$smares = $this->getHbqdData($vin, $txt, $reg);
					if(LibFc::FormatNum($smares['data']['sma']['sma_gxb_code_show']) == LibFc::FormatNum($addArr['sma_gxb_code_show'])){
						//不要日期
						unset($smares['data']['sma']['sma_year']);
					}else{
						$smares = $this->fillGxbInfo($vin, $addArr);
					}
					if($tArr['cha_code']){
						$YPCAR67Db = new BaseDb(mvc::$cfg['DB']['YPCAR67']);
						$res = $YPCAR67Db->get('temp_changan', ['cha_id'], sprintf(" and cha_vin = '%s'", $vin), true);
						if(empty($res['data'])){
							if($smares['data']['sma']['sma_engine']) $tArr['vin_engine'] = $smares['data']['sma']['sma_engine'];
							$YPCAR67Db->add('temp_changan', $tArr);
						}
					}
					return $smares;
				}
				return LibFc::ReturnData(true, $tres);
			break;
			case 'csvw':
				$exists = $cache && file_exists($txtPdf);
				if(!$exists){
					$YpwBase = new YpwBase();
					$res = $YpwBase->get('stand_vin_file', ['vf_url'], sprintf(" and vf_vin='%s' and vf_url like '%%%s%%' limit 1", $vin, $reg['reg_code']), true);
					if($res['data']){
						$html = $LibHttp->fetch($res['data']['vf_url']);
						if(stripos($html, 'carType') !== false){
							$exists = true;
						}else{
							$html = '';
						}
					}
				}
				if(!$exists){
					$url = 'https://www.csvw.com/les-central/external/eow/ep-vehicle/'.$vin;
					$dtime = date('YmdHis'); $rand1 = rand(10000, 99999);
					$LibHttp->httpheader = ['x-app-id: 4v77NaW7Psb8iu56fv6Y', 'x-requested-with:XMLHttpRequest','x-sequence-no:'.$dtime.$rand1.rand(10000, 99999),'x-timestamp:'.$dtime.$rand1];
					$html = $LibHttp->fetch($url);
					$htmlArr = json_decode($html, true);
					if(is_array($htmlArr) && !empty($htmlArr['data']['vin']) && $htmlArr['data']['vin'] == $vin){
					}else if(is_array($htmlArr) && $htmlArr['code'] == '200'){
						return LibFc::ReturnData(true, ['error'=>'#end#空']);
					}else{
						return LibFc::ReturnData(true, ['error'=>'#again#采集失败！'.$html]);
					}
					LibDir::CreateDir($pdfDir);
					file_put_contents($txtPdf, $html);
					$exists = true;
				}else{
					$html = file_get_contents($txtPdf);
				}
				
				if($exists && $html){
					$htmlArr = json_decode($html, true);
					if(is_array($htmlArr) && !empty($htmlArr['data']['vin']) && $htmlArr['data']['vin'] == $vin)
					{
						$htmlArr = $htmlArr['data'];
						if(!empty($htmlArr['carType']) && !empty($htmlArr['clscrq']))
						{
							$addArr = [
								'sma_gxb_code_show'=>$htmlArr['carType'],
								'sma_year'=>$htmlArr['clscrq']
							];

							if(preg_match('/(\d{4})\s*年\s*(\d{1,2})\s*月\s*(\d{1,2})\s*日/', $addArr['sma_year'], $match))
								$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));

							if(!empty($htmlArr['fdj0']))
								$addArr['sma_engine'] = substr($htmlArr['fdj0'], 0, stripos($htmlArr['fdj0'], '/'));
							else if(!empty($htmlArr['ddj0']))
								$addArr['sma_engine'] = substr($htmlArr['ddj0'], 0, stripos($htmlArr['ddj0'], '/'));

							if(!empty($htmlArr['bsq0'])) $addArr['sma_tran'] = $htmlArr['bsq0'];
							if(!empty($htmlArr['dcrl'])){
								$addArr['sma_xuhang'] = $htmlArr['dcrl'];
							}else if(!empty($htmlArr['zcdl']) ||!empty($htmlArr['xslcgk'])){
								 $addArr['sma_xuhang'] = trim($htmlArr['zcdl'].'/'.$htmlArr['xslcgk'], '/');
							}
							if(!empty($htmlArr['fdjh'])){
								if(stripos($htmlArr['fdjh'], ',')){
									$t = explode(',', $htmlArr['fdjh']);
									$addArr['sma_engine6'] = $t[count($t)-1];
								}else{
									$addArr['sma_engine6'] = $htmlArr['fdjh'];
								}
							}
							return $this->fillGxbInfo($vin, $addArr);
						}
						else
						{
							@unlink($txtPdf);
							return LibFc::ReturnData(true, ['error'=>$vin.'#error#车架号匹配失败！'.$html]);
						}
					}else if(is_array($htmlArr) && $htmlArr['code'] == '200'){
						@unlink($txtPdf);
						return LibFc::ReturnData(true, ['error'=>'#end#空']);
					}else if($html != '' && !is_array($htmlArr)){
						@unlink($txtPdf);
						return LibFc::ReturnData(true, ['error'=>'#again#采集失败！'.$html]);
					}
				}
			break;
			case 'sgmw':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024;
				if(!$exists)
				{
					//文本接口
					$existsTxt = $cache && file_exists($txtPdf);
					if(!$existsTxt)
					{
						$url = 'https://environmental.autobaojun.cn/ashx/environment.ashx?vin='.$vin.'&v='.microtime(true).'&_='.sprintf('%d', microtime(true)*1000);
						$html = $LibHttp->fetch($url);
						LibDir::CreateDir($pdfDir);
						file_put_contents($txtPdf, $html);
						$existsTxt = true;
					}
					else
					{
						$html = file_get_contents($txtPdf);
					}
					if($existsTxt && $html)
					{
						$htmlArr = json_decode($html, true);
						if(!empty($htmlArr['info']['VIN']) && $htmlArr['info']['VIN'] == $vin && !empty($htmlArr['info']['CarType']) && !empty($htmlArr['info']['MakerDate']))
						{
							$addArr = [
								'sma_gxb_code_show'=>$htmlArr['info']['CarType'],
								'sma_year'=>date('Y-m-d', strtotime($htmlArr['info']['MakerDate']))
							];
							if(!empty($htmlArr['info']['EngineBarcode']))
								$addArr['sma_engine'] = substr($htmlArr['info']['EngineBarcode'], 0, stripos($htmlArr['info']['EngineBarcode'], '/'));
							if(!empty($htmlArr['info']['EngineCode']) && strlen($htmlArr['info']['EngineCode']) > 5)
								$addArr['sma_engine6'] = $htmlArr['info']['EngineCode'];
							else if(!empty($htmlArr['info']['EngineNumber']) && strlen($htmlArr['info']['EngineNumber']) > 5)
								$addArr['sma_engine6'] = $htmlArr['info']['EngineNumber'];

							if(!empty($htmlArr['info']['TransmissionForm']))
								$addArr['sma_tran'] = $htmlArr['info']['TransmissionForm'];
							if(!empty($htmlArr['info']['MMufflerBarcode']))
								$addArr['sma_xuhang'] = $htmlArr['info']['MMufflerBarcode'];

							return $this->fillGxbInfo($vin, $addArr);
						}
					}
					@unlink($txtPdf);

					//pdf 接口
					$url = 'https://foo.baojunev.com/oldsgmwca/';
					$LibHttp->httpheader = ['Content-Type: application/json'];
					$html = $LibHttp->fetch($url, '{"GetPDFByVIN":{"vin":"'.$vin.'"}}');
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
					if(empty($htmlArr['GetPDFByVINResponse']['GetPDFByVINResult'])) return LibFc::ReturnData(true, ['error'=>'#end#'.$html]);
					$html = $htmlArr['GetPDFByVINResponse']['GetPDFByVINResult'];
					$html = base64_decode($html);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#base64']);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);

				
			break;
			case 'bmw-brilliance':
			case 'bmw-jinkou':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024;
				if(!$exists)
				{
					$res = $this->getBmwVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'java.net.Unknown') !== false) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					if(stripos($html, 'showError') !== false) return LibFc::ReturnData(true, ['error'=>'#end#showError']);
					else if(stripos($html, 'pdf') === false || strlen($html) < 1024) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'ampmake':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://p.ampmake.com/cv/envCert/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'NoSuchKey') !== false) return LibFc::ReturnData(true, ['error'=>'#end#NoSuchKey']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'faw-vw':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				//文件存在进行第一次匹配
				if($exists)
				{
					$res = $this->getPdfTxt($pdfFile);
					if(stripos($res['data'], '型号') !== false) return $this->getHbqdData($vin, $res['data'], $reg);
				}

				for($run = 1; $run <= 5; $run++){
					$LibHttp = new LibHttp(false, false);
					$LibHttp->timeout = 5;
					$url = 'https://www.faw-vw.com/api/v0.1/service/fawcore/vehicle/getVehicleFileList?keyword='.$vin;
					$html = $LibHttp->fetch($url, ['t'=>1]);
					if(stripos($html, 'timed out') !== false){
						sleep(1);
					}else{
						break;
					}
				}
				if(stripos($html, 'Blocked')) return LibFc::ReturnData(true, ['error'=>'#stop#被限制'.$html]);
				$htmlArr = json_decode($html, true);
				if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
				//不再取文件，拖死对方服务器
				if(isset($htmlArr['data']) && empty($htmlArr['data'][0])){
					return LibFc::ReturnData(true, ['error'=>'#end#']);
				}else if(!empty($htmlArr['data'][0]) && $htmlArr['data'][0]['fileName'] == $vin){
					$tempArr = $htmlArr['data'][0];
					//官网漏数据但是有发动机号码
					$jsonAddArr = [];
					if(!empty($tempArr['engineNumber']))
					{
						//LFV3B28R3J3350902
						if(preg_match('/^\d{3}[a-zA-Z]{2}[a-zA-Z0-9]{7,}/', $tempArr['engineNumber'], $match)){
							$jsonAddArr = ['sma_engine6'=>substr($tempArr['engineNumber'], 3, 9)];
						}else{
							$jsonAddArr = ['sma_engine6'=>$tempArr['engineNumber']];
						}
					}
					$url = $tempArr['directory'];
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'pdf') === false || (stripos($html, 'pdf') !== false && strlen($html) < 1024*3))
					{}
					else
					{
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
						$res = $this->getPdfTxt($pdfFile);
						if(stripos($res['data'], '型号') !== false) return $this->getHbqdData($vin, $res['data'], $reg);
					}
					return $this->fillGxbInfo($vin, $jsonAddArr);
				}else{
					return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
				}
			break;
			case 'volvocars':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getVolvocarsVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3 || stripos($html, 'not exist') !== false) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists)
				{
					$imgCfg = $othArr;
					if(substr($vin, 0, 1) == 'L')
					{
						//只转最后一张
						$imgCfg['totype'] = 'onlyLast';
						$imgCfg['cutsize'] = [
							[
								'allpage'=>1,
								'size'=>[
									'gxb'=>[0.05,0.6,0.168,0.20]
								]
							],
							[
								'allpage'=>2,
								'size'=>[
									'gxb'=>[0.05,0.6,0.155,0.22],
									'engine6'=>[0.05,0.6,0.24,0.32],
									'year'=>[0.60, 0.96,0.92, 0.95]
								]
							]
						];
					}
					else
					{
						$imgCfg['totype'] = '';
						$imgCfg['cutsize'] = [
							[
								'allpage'=>1,
								'size'=>[
									'gxb'=>[0.05,0.6,0.22,0.28]
								]
							],
							[
								'allpage'=>2,
								'size'=>[
									'gxb'=>[0.05,0.6,0.23,0.275],
									'engine6'=>[0.05,0.6,0.34,0.39],
									'year'=>[0.60, 0.96,0.92, 0.95]
								]
							],
							[
								'allpage'=>2,
								'size'=>[
									'gxb'=>[0.05,0.6,0.17,0.23],
									'engine6'=>[0.05,0.6,0.28,0.34],
									'year'=>[0.70, 0.96,0.75, 0.85]
								]
							],
							[
								'allpage'=>2,
								'size'=>[
									'gxb'=>[0.05,0.9,0.15,0.23],
									'engine6'=>[0.05,0.6,0.28,0.34],
									'year'=>[0.70, 0.96,0.70, 0.85]
								]
							]
						];
					}
					$ocrTxtRes = $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
					if(!empty($ocrTxtRes['data']['sma']))
						return $ocrTxtRes;

					//YV1PZ10G6L1107490
					$pdfTxtRes = $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
					//LVYPD25D9LP179198 型号不一致
					if(stripos($pdfTxtRes['data']['error'], '前8与') === false && !empty($pdfTxtRes['data']['sma'])) return $pdfTxtRes;
				}
			break;
			case 'saic-gm':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$LibHttp->timeout = 120;
					$url = 'https://admin.sgmlink.com:8087/basePath/SGMCOM/sgm_veh_vecc_pdf/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'not exist')) return LibFc::ReturnData(true, ['error'=>'#end#not exist']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'saicmaxus':
			case 'regetsaicmaxus':
				$existsPdf = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				$existsHtml = $cache && file_exists($htmlPdf);
				if(!$existsHtml && !$existsPdf)
				{
					//html形式 LSH14C3C7LA095557  
					$url = 'https://www.saicmaxus.com/inc/ep.php?vin='.$vin;
					$html = $LibHttp->fetch($url);
					//<a href="/vin/LSKG4AC19LA084969.pdf" download="轻型汽油车环保信息随车清单20210113.pdf">点击下载 &gt;</a>
					if(preg_match('/href="([^"]+'.$vin.'\.pdf)"/iUs', $html, $match))
					{
						//pdf形式 LSH14C3C7LA095557
						$url = 'https://www.saicmaxus.com/'.$match[1];
						$html = $LibHttp->fetch($url);
						if(stripos($html, 'Not Found')) return LibFc::ReturnData(true, ['error'=>'#end#Not Found']);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$existsPdf = true;
					}
					else if(stripos($html, '车辆生产日期') !== false && preg_match('/class="ep_cont main[^>]*>([\s\S]+)<\/div>\s*<div class="footer/', $html, $match))
					{
						$html = $match[1];
						LibDir::CreateDir($pdfDir);
						file_put_contents($htmlPdf, $html);
						$existsHtml = true;
					}
					else if(stripos($html, '点击下载') === false)
					{
						return LibFc::ReturnData(true, ['error'=>'#end#']);
					}
				}
				else if($existsHtml)
				{
					$html = file_get_contents($htmlPdf);
				}
				if($existsPdf)
				{
					return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
				}
				else if($existsHtml && stripos($html, '车辆生产日期') !== false)
				{
					return $this->getHbqdData($vin, $html, $reg);
				}
				else
				{
					@unlink($htmlPdf);
				}
			break;
			case 'dflzm':
				$vin3 = substr($vin, 0, 3);
				$vin11 = substr($vin, 10, 1);
				$fiterArr = [
					'LGG'=>['Z', 'L'],
					'LGJ'=>['T'],
					'LMX'=>['Z'],
				];
				if(empty($fiterArr[$vin3]) || !in_array($vin11, $fiterArr[$vin3])) return LibFc::ReturnData(true, ['error'=>'#end#不在采集规则']);
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getDflzmVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3 || stripos($html, 'not exist') !== false) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'newlongma':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.newlongma.com/Upload/%E7%8E%AF%E4%BF%9D%E4%BF%A1%E6%81%AF%E5%85%AC%E5%BC%80%E9%9A%8F%E8%BD%A6%E6%B8%85%E5%8D%95/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, '找不到') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#找不到']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'dpca':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getDpcaVin($vin);
					if(!empty($res['error']))  return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'not exist') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#not exist']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'dfl':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getDflVin($vin);
					if(!empty($res['error']))  return LibFc::ReturnData(true, $res);
					if(!empty($res['sma']['sma_gxb_code_show']))
					{
						return $this->fillGxbInfo($vin, $res['sma']);
					}
					$html = $res['html'];
					if(stripos($html, '页面不存在') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#页面不存在']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'jmcgl':
				if(substr($vin, 10, 1) != 0) return LibFc::ReturnData(true, ['error'=>'#error#非任务规则的VIN']);
				$res = $this->getJmcglVin($vin);
				if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
				if(!empty($res['data']['sma_gxb_code_show']))
				{
					$addArr = $res['data'];
					return LibFc::ReturnData(true, ['sma'=>$addArr]);
				}
			break;
			case 'tftm':
				if(substr($vin, 10, 1) != 0) return LibFc::ReturnData(true, ['error'=>'#error#非任务规则的VIN']);
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.tftm.com.cn/api/preview/ftmc/download/'.$vin;
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'VIN码不存在') !== false) return LibFc::ReturnData(true, ['error'=>'#end#VIN码不存在']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists)
				{
					$imgCfg = $othArr;
					//只转最后一张
					$imgCfg['totype'] = 'onlyLast';
					$imgCfg['cutsize'] = [
						[
							//LFMAY86C4K0712069需要放大区域否则TV7120GL-i 会变成 TV7120GL 
							'allpage'=>1,
							'size'=>[
								'gxb'=>[0.05,0.6,0.115,0.228]
							]
						],
						[
							//LFMAY86C1K0400078
							'allpage'=>2,
							'size'=>[
								'gxb'=>[0.05,0.6,0.129,0.199],	
								'engine6'=>[0.05,0.6,0.25,0.30]
							]
						]
					];
					$imgCfg['strtr'] = [
						'TV7I'=>'TV71',
						'2IN6'=>'21N6',
						'2lE6'=>'21E6',
						'TV712OGLM'=>'TV7120GLM',
						'TV712IG6'=>'TV7121G6',
						"\nⅣV71"=>"\nTV71",
						"\nⅣ71"=>"\nTV71",
						"\nT71"=>"\nTV71",
						"\nV71"=>"\nTV71",
						'-lHEV'=>'-iHEV',
						' RoyalsIn'=>'Royalsln',
						'-i HEV'=>'-iHEV',
						'GLX-1'=>'GLX-i',
						'GL-1'=>'GL-i',
					];
					return $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
				}
			break;

			case 'liebao':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.leopaard.com/query?m=consultation&c=ajax&a=envAjax';
					$LibHttp = new LibHttp();
					$LibHttp->timeout = 30;
					$LibHttp->httpheader[] = 'x-requested-with: XMLHttpRequest';
					$html = $LibHttp->fetch($url, ['vin'=>$vin]);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
					if(!empty($htmlArr['data']['url']))
					{
						$url = str_replace('http://', 'https://', $htmlArr['data']['url']);
						$html = $LibHttp->fetch($url);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
					else if(stripos($htmlArr['msg'], '不存在') !== false)
					{
						//{"ret":-1,"msg":"此VIN码对应的环保信息不存在!"}
						return LibFc::ReturnData(true, ['error'=>'#end#不存在']);
					}
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'benzfj':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.fujianbenz.com/sites/Environmental/_layouts/15/FBACEIP/Api/EnvironmentalApi.aspx';
					$LibHttp = new LibHttp();
					$LibHttp->timeout = 30;
					$html = $LibHttp->fetch($url, ['WebRequest'=>'{"Type":"GetInfo","StartYear":2018,"Code":"'.$vin.'"}']);
					$htmlArr = json_decode($html, true);
					if(is_array($htmlArr) && isset($htmlArr['Url']))
					{
						if(empty($htmlArr['Data'])) return LibFc::ReturnData(true, ['error'=>'#end#'.$html]);
						$url = 'https://www.fujianbenz.com/sites/Environmental/_layouts/15/FBACEIP/Web/Admin/GetFile.aspx?Type=GetFile&FileUrl='.urlencode($htmlArr['Data'][0]['DocUrl']);
						$html = $LibHttp->fetch($url);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
					else
					{
						return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					}
				}
				if($exists)
				{
					$imgCfg = $othArr;
					$imgCfg['cutsize'] = [
						[
							'allpage'=>1,
							'size'=>[
								'gxb'=>[0.08,0.6,0.207,0.252]
							]
						],
						[
							//LB1WG2E10K8067171
							'allpage'=>2,
							'size'=>[
								'gxb'=>[0.1,0.6,0.169,0.198],	
								'engine6'=>[0.1,0.6,0.295,0.33]
							]
						],
						[
							//LB1WG2E10J8042222
							'allpage'=>2,
							'size'=>[
								'gxb'=>[0.08,0.6,0.207,0.252]
							]
						]
					];
					return $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
				}
			break;
			case 'hongyan':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getHongyanVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'not exist') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#not exist']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'benzbj':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					if($othArr['sce_url']){
						$html = $LibHttp->fetch($othArr['sce_url']);
					}else{
						//$res = $this->getBenzbjVin($vin);
						return LibFc::ReturnData(true, ['error'=>$othArr['sce_error']]);
					}
					if(stripos($html, 'not exist') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#not exist']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists)
				{
					$txtres =  $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
					if(!empty($txtres['data']['sma'])) return $txtres;

					$res = $this->getPdfTxtBySmalot($pdfFile);
					$html  = $res['data'];
					if(stripos($html, '车辆型号') || stripos($html, 'Benz'))
					{
						if(stripos($res['data'], '档位数:') === false)  $res['data'] = str_replace('档位数', '档位数:', $res['data']);
						return $this->getHbqdData($vin, $res['data'], $reg);
					}
					else
					{
						//图片识别
						$imgCfg = $othArr;
						$imgCfg['cutsize'] = [
							[
								//LFMAY86C0H0558078
								'allpage'=>2,
								'size'=>[
									'gxb'=>[0.0,0.6,0.20,0.255]
								]
							]
						];
						return $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
					}
				}
			break;
			case 'fdqc':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getFdqcVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, 'not exist') !== false || stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#not exist']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'weichai':
				$res = $this->getWeichaiVin($vin);
				if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
				$html = $res['html'];
				if(stripos($html, '车辆型号')){
					$html = strip_tags($html);
					return $this->getHbqdData($vin, $html, $reg);
				}else if(preg_match('/<img src="data:image\/png;base64,([^"]+)"/i', $html, $match)){
					$imgFile = str_replace('.txt', '.jpg', $txtPdf);
					LibDir::CreateDir($pdfDir);
					file_put_contents($imgFile, base64_decode($match[1]));
					$imgCfg = $othArr;
					//只转最后一张
					$imgCfg['totype'] = 'onlyLast';
					$imgCfg['cutsize'] = [
						[
							'allpage'=>1,
							'size'=>[
								'gxb'=>[0.08,0.6,0.213,0.242]
							]
						],
						[
							'allpage'=>1,
							'size'=>[
								'gxb'=>[0.53,0.75,0.138,0.18],
								'engine6'=>[0.53,0.75,0.235,0.275],
							]
						]
					];
					$imgCfg['strtr'] = [
						'1Z64'=>'YZ64'
					];
					return $this->getScqdByImgOcr($vin, ['count'=>1, 'img'=>[$imgFile]], $reg, $imgCfg);
				}
			break;
			case 'ds':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.ds.com.cn/web/pdf/'.$vin.'.pdf?t'.time();
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3){
						if(stripos($html, '破解中') !== false) return LibFc::ReturnData(true, ['error'=>'#end#破解中']);
						return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					}
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'nanjunauto':
				$url = 'http://www.nanjunauto.com/Protection.aspx?keyword='.$vin;
				$html = $LibHttp->fetch($url);
				if(preg_match('/href="(protection_template.aspx\?ID\=[^"]+)"/i', $html, $match))
				{
					$url = 'http://www.nanjunauto.com/'.$match[1];
					$html = $LibHttp->fetch($url);
					$html = strip_tags($html);
					$html = preg_replace('/：\r?\n {2,}/i', ':', $html);
					if(stripos($html, $vin) !== false)
					{
						LibDir::CreateDir($pdfDir);
						file_put_contents($txtPdf, strip_tags($html));
						return $this->getHbqdData($vin, $html, $reg);
					}
				}
			break;
			case 'sxqc':
				$url = 'http://www.sxqc.com:8889/sqgk/search/';
				$html = $LibHttp->fetch($url, ['vin'=>$vin, 'fdjh'=>'']);
				if(preg_match('/<td>([^<]*)<\/td>\s*<td>([^<]*)<\/td>\s*<td>([^<]*)<\/td>\s*<td>'.$vin.'<\/td>/iUs', $html, $match))
				{
					$addArr = [
						'sma_gxb_code_show'=>$match[1],
						'sma_engine'=>$match[2],
						'sma_engine6'=>$match[3],
					];
					return $this->fillGxbInfo($vin, $addArr);
				}
				else if(stripos($html, '无查询信息'))
				{
					return LibFc::ReturnData(true, ['error'=>'#end#无查询信息']);
				}
			break;
			case 'dama':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://58.220.233.94:8081/vehicle/vinServlet.php?t=huanbao';
					$html = $LibHttp->fetch($url, ['vin'=>$vin]);
					if(preg_match('/\/vehicle\/download.php\?filename\=[^\']+'.$vin.'\.pdf/iUs', $html, $match))
					{
						$oClient = new Client([
							'debug' => false,
							'timeout' => 10,
							'cookies' => true,
							'base_uri' => 'http://58.220.233.94:8081'
						]);
						$oCookie = new CookieJar();
						try {
							$oGuzzle = $oClient->get($match[0], [
								'cookies' => $oCookie,
							]);
							if (200 == $oGuzzle->getStatusCode())
							{
								$html = $oGuzzle->getBody()->getContents();
								if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
								LibDir::CreateDir($pdfDir);
								file_put_contents($pdfFile, $html);
								@unlink($txtPdf);
								$exists = true;
							}
						} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
							return ['error'=>'#again#pdf失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'hozonauto':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.hozonauto.com/cms/environmental/listNew';
					$LibHttp = new LibHttp();
					$LibHttp->timeout = 30;
					$LibHttp->httpheader = [
						'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
					];
					$html = $LibHttp->fetch($url, ['pageNum'=>1,'model'=>$vin, 'plan'=>'环保随车清单查询']);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
					if(!empty($htmlArr['rows'][0]['file']))
					{
						$url = $htmlArr['rows'][0]['file'];
						$html = $LibHttp->fetch($url);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
					else if(isset($htmlArr['total']) &&  $htmlArr['total'] == 0)
					{
						return LibFc::ReturnData(true, ['error'=>'#end#']);
					}
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'xiaopeng':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://qms.xiaopeng.com:9966/amb/common/download-pdf.htm?fileName='.$vin;
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'gmmc':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$res = $this->getGmmcVin($vin);
					if(!empty($res['error'])) return LibFc::ReturnData(true, $res);
					$html = $res['html'];
					if(stripos($html, '<title>404 -') !== false) return LibFc::ReturnData(true, ['error'=>'#end#404']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'luxgen':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://www.dfyl-luxgen.com/Index/api/searchVin';
					$html = $LibHttp->fetch($url, ['vin'=>$vin]);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
					if(!empty($htmlArr['data']['pdf']))
					{
						$url = 'http://www.dfyl-luxgen.com/download.php?files='.$htmlArr['data']['pdf'];
						$html = $LibHttp->fetch($url);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
					else if(stripos($htmlArr['msg'], '未查询到信息') !== false)
					{
						return LibFc::ReturnData(true, ['error'=>'#end#未查询到信息']);
					}
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'chenggong':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://chenggongauto.com/api/getPdfByVin.php';
					$html = $LibHttp->fetch($url, ['title'=>$vin]);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#pdf获取失败'.$html]);
					if(stripos($html, '未匹配') || stripos($html, '404 Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#未匹配 Not Found']);
					if(!empty($htmlArr['data']['list'][0]['pdfurl']))
					{
						$html = $LibHttp->fetch('https://chenggongauto.com'.$htmlArr['data']['list'][0]['pdfurl']);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
					else if(isset($htmlArr['total']) && $htmlArr['total'] == 0)
					{
						return LibFc::ReturnData(true, ['error'=>'#end#']);
					}
				}
				if($exists) 
				{
					//L3HEDABB6KA000857
					$txtres =  $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
					if(!empty($txtres['data']['sma'])) return $txtres;
					
					//pdf里是图片  L3HFDABBXHA001278
					$imgCfg = $othArr;
					//只转最后一张
					$imgCfg['totype'] = 'onlyLast';
					$imgCfg['cutsize'] = [
						[
							'allpage'=>1,
							'size'=>[
								'gxb'=>[0.05,0.6,0.205,0.286]
							]
						]
					];
					return $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
				}
			break;
			case 'wdsp':
				$LibYpApi = new LibYpApi();
				$txtRes = $LibYpApi->Get('vin/catchAnyVinfromWdspApi', [], ['vins'=>$vin, 'addToSma'=>1], true);
				if($txtRes['status'] && is_array($txtRes['data']))
				{
					$resData = $txtRes['data'][$vin];
					if(!empty($resData['sma_id']))
					{
						return LibFc::ReturnData(true, ['error'=>'', 'sma'=>$resData]);
					}
					else
					{
						return LibFc::ReturnData(true, ['error'=>'#end#']);
					}
				}
				else
				{
					return LibFc::ReturnData(true, ['error'=>'#error#'.json_encode($txtRes, JSON_UNESCAPED_UNICODE)]);
				}
			break;
			case 'wey':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://www.e-gwm.cn:4420/pdf/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, 'Status 404')) return LibFc::ReturnData(true, ['error'=>'#end#nopdf']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'caky':
				$YpwBase = new YpwBase();
				$vinYear = LibFc::VinYear(substr($vin, 9, 1));
				$gwhereArr = [
					sprintf(" and sma_vin1_8='%s' and sma_vin10_12='%s' group by sma_gxb_code", substr($vin, 0, 8), substr($vin, 9, 3)),
					'vinbm'
				];
				$hasChkArr = [];
				foreach($gwhereArr as $tw)
				{
					if($tw == 'vinbm'){
						$res = $YpwBase->get('yp_vin_year', ["concat(vin_10, '".substr($vin, 10, 2)."') as vin_1012"], sprintf(" and vin_year >= 2017 and vin_year in (%d, %d, %d)", $vinYear-1, $vinYear, $vinYear+1));
						if(count($res['data']) < 2) continue;
						$tw = sprintf(" and sma_vin1_8='%s' and sma_vin10_12 in ('%s') group by sma_gxb_code", substr($vin, 0, 8), implode("','", array_column($res['data'], 'vin_1012')));
					}

					$res = $YpwBase->get('stand_model_any', ['sma_gxb_code_show'], $tw);
					$knGxbArr = array_column($res['data'], 'sma_gxb_code_show');
					foreach($knGxbArr as $gxbnum)
					{
						if(in_array($gxbnum, $hasChkArr)) continue;
						$hasChkArr[] = $gxbnum;
						$url = 'http://hbxx.caky.com.cn:15821/Public/carList/lookInfo.jsp?r=0.'.time().'&vin='.$vin.'&car_type='.$gxbnum;
						$html = $LibHttp->fetch($url);
						if(stripos($html, '未上传')) return LibFc::ReturnData(true, ['error'=>'#end#未上传']);
						//EIPrint/CreatePdf/NORMAL/2019_10_11/LSCAB32R2KE714056.pdf
						if(preg_match('/[a-zA-Z0-9].*\.pdf/i', $html, $match))
						{
							$pdfUrl = 'http://hbxx.caky.com.cn:15821/'.$match[0];
							$html = $LibHttp->fetch($pdfUrl);
							if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
							LibDir::CreateDir($pdfDir);
							file_put_contents($pdfFile, $html);
							@unlink($txtPdf);
							$res = $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
							if(!empty($res['data']['sma']['sma_gxb_code_show']) && !empty($res['data']['sma']['sma_gxb_code_show']))
							{
								return $res;
							}
							else
							{
								//pdf是图片 尝试获取发动机编码
								$imgCfg = $othArr;
								$imgCfg['cutsize'] = [
									[
										'allpage'=>1,
										'size'=>[
											'engine6'=>[0.05,0.9,0.185,0.21],
											'engine'=>[0.05,0.8,0.45,0.502],
											//LSCAB52C0JE299132
											'engine2'=>[0.05,0.8,0.36,0.422]
										]
									]
								];
								$imgCfg['strtr'] = [
									'发力机'=>'发动机',
									'发云力机'=>'发动机',
									'扁号'=>'编号',
									'Tz1531J017'=>'TZ185XSDJ017',
									'Tz2303200'=>'TZ230XS200',
									'Tz27o31J010'=>'TZ270XSDJ010',
									'Tz2703D010'=>'TZ270XSDJ010',
									'Tz230X3200'=>'TZ230XS200',
									'Tz153D017'=>'TZ185XSDJ017',
									'C工E'=>'CIE',
								];
								$imgCfg['sma_gxb_code_show'] = $gxbnum;
								$res = $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
								if(!empty($res['data']['sma']['sma_gxb_code_show']))
								{
									$addArr = $res['data']['sma'];
								}
								else
								{
									$addArr = ['sma_gxb_code_show'=>$gxbnum];
								}

								if(preg_match('/\/(\d{4})[_\/-](\d{1,2})[_\/-](\d{1,2})\//', $pdfUrl, $match))
								{
									$addArr['sma_year'] = date('Y-m-d', strtotime($match[1].'-'.$match[2].'-'.$match[3]));
								}
								return LibFc::ReturnData(true, ['error'=>'', 'sma'=>$addArr]);
							}
							break;
						}
					}
				}
			break;
			//四川丰田
			case 'sftm':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.sftm.com.cn/PageHandler/Handler1.ashx?Command=SearchFile&FileInfoNum='.$vin.'&page=1&rows=20';
					$LibHttp->timeout = 60;
					$html = $LibHttp->fetch($url);
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return LibFc::ReturnData(true, ['error'=>'#again#html获取失败'.$html]);
					if(!empty($htmlArr[0]['FileDir']))
					{
						$htmlArr[0]['FileDir'] = str_replace('\\', '/', $htmlArr[0]['FileDir']);
						$html = $LibHttp->fetch('https://www.sftm.com.cn/pdf_viewer/web/'.urlencode($htmlArr[0]['FileDir']));
						if(stripos($html, 'Not Found') !== false) return LibFc::ReturnData(true, ['error'=>'#end#Not Found']);
						if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
						LibDir::CreateDir($pdfDir);
						file_put_contents($pdfFile, $html);
						@unlink($txtPdf);
						$exists = true;
					}
				}
				if($exists)
				{
					$imgCfg = $othArr;
					$imgCfg['totype'] = 'merge';
					$imgCfg['cutsize'] = [
						[
							//LFMAY86C1K0400078
							'allpage'=>2,
							'size'=>[
								'gxb'=>[0.00,0.6,0.095,0.145],	
								'year'=>[0.55,0.9,0.96,0.999],
							]
						],
						[
							//LFMH5581XHS001815
							'allpage'=>2,
							'size'=>[
								'gxb'=>[0.00,0.6,0.125,0.165],
								'engine6'=>[0.05,0.9,0.205,0.235],
								'year'=>[0.55,0.9,0.93,0.99],
							]
						]
					];
					$imgCfg['strtr'] = [];
					return $this->getScqdByImgOcr($vin, $pdfFile, $reg, $imgCfg);
				}
			break;
			case 'dfac':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
				$url = 'https://www.dfac.com/ajax/list_page?siteId=1&columnId=32&subId=0&pageNumber=0&pageSize=100000';
				$LibHttp->httpheader = ['Content-Type: application/json'];
				$html = $LibHttp->fetch($url, '{"LIKE_VIN":"'.$vin.'"}');
				$htmlArr = json_decode($html, true);
				if(isset($htmlArr['info']['totalCount'])){
					if(!empty($htmlArr['info']['totalCount'])){
						$info = $htmlArr['info']['list'][0];
						$addArr = [
							'sma_gxb_code_show'=>$info['VEHICLE'],
							'sma_year'=>date('Y-m-d', strtotime($info['CREATEDATE']))
						];
						if($info['TEXT1'] && $info['TEXT1'] != '无'){
							$addArr['sma_engine'] = $info['TEXT1'];
						}
						if($info['TEXT2'] && $info['TEXT2'] != '无'){
							$addArr['sma_engine6'] = $info['TEXT2'];
						}
						LibDir::CreateDir($pdfDir);
						file_put_contents($txtPdf, $html);
						/*if($info['finfo']['FILE']){
							$url = 'https://www.dfac.com'.$info['finfo']['FILE'];
							$pdfhtml = $LibHttp->fetch($url);
							if(stripos($pdfhtml, 'pdf') !== false && strlen($pdfhtml) > 1024*3)
							{
								LibDir::CreateDir($pdfDir);
								file_put_contents($pdfFile, $pdfhtml);
								@unlink($txtPdf);
								return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
							}
						}*/
						return $this->fillGxbInfo($vin, $addArr);
					}else{
						return LibFc::ReturnData(true, ['error'=>'#end#0']);
					}
				}else{
					return LibFc::ReturnData(true, ['error'=>'#again#html获取失败'.$html]);
				}
			break;
			case 'jinkou':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$wmi = substr($vin, 0, 3);
					$siteKeyArr = [
						//雷克萨斯 丰田
						'CvAhTNdvkKX6ggry'=>['JTJ','JTH','JTE','JTF', 'JT2','JTD'],
					];
					$token = '';
					foreach($siteKeyArr as $sk=>$sv)
					{
						if(in_array($wmi, $sv)){
							$token = $sk;
							break;
						}
					}
					if(empty($token)) return LibFc::ReturnData(true, ['error'=>'#end#token尚未配置']);
					$url = 'https://mv.cqccms.com.cn/coc/servlet/hbDownloadServlet?key='.$token.'&vinCode='.$vin;
					$html = $LibHttp->fetch($url);
					if(stripos($html, '未查询到数据') !== false) return LibFc::ReturnData(true, ['error'=>'#end#未查询到数据']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'zxauto':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://www.zxauto.tv/PDF/file/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, '<title>404')) return LibFc::ReturnData(true, ['error'=>'#end#404']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'zznissan':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$LibHttp->httpheader = [
						'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
						'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
					];
					$url = 'https://www.zznissan.com.cn/uploads/environment_pdf_file/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, '安全警告')) return LibFc::ReturnData(true, ['error'=>'#again#安全警告']);
					if(stripos($html, '不存在')) return LibFc::ReturnData(true, ['error'=>'#end#不存在']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'dfmm': 
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'http://101.37.119.76:18899/dpcvs4.0/rest/dfmmepService/tsmepinfo?vin='.$vin;
					$html = $LibHttp->fetch($url);
					$htmlArr = json_decode($html, true);
					//{"code":"0","data":{"link":"http://101.37.119.76:18899/meppdf/1111111/LGHGLJUM8K6108860.pdf","vin":"LGHGLJUM8K6108860"},"msg":"成功"}
					//{"code":"101","data":null,"msg":"无效的VIN"}
					if(is_array($htmlArr) && isset($htmlArr['code']))
					{
						if(!empty($htmlArr['data']['link']))
						{
							$url = $htmlArr['data']['link'];
							$html = $LibHttp->fetch($url);
							if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
							LibDir::CreateDir($pdfDir);
							file_put_contents($pdfFile, $html);
							@unlink($txtPdf);
							$exists = true;
						}
						else if(stripos($htmlArr['msg'], '无效') !== false)
						{
							return LibFc::ReturnData(true, ['error'=>'#end#无效']);
						}
					}
					else
					{
						return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					}
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);	
			break;
			case 'porsche':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://www.porsche.cn/partial/emissiondata';
					$html = $LibHttp->fetch($url, ['vin-search-input'=>$vin, 'vincode'=>$vin]);
					if(stripos($html, 'showMessage(1)')) return LibFc::ReturnData(true, ['error'=>'#end#不存在']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
			case 'spotlight':
				$exists = $cache && file_exists($pdfFile) && filesize($pdfFile) > 1024*3;
				if(!$exists)
				{
					$url = 'https://emissions.spotlight.cn/uploads/vinpdf/'.$vin.'.pdf';
					$html = $LibHttp->fetch($url);
					if(stripos($html, '<title>404')) return LibFc::ReturnData(true, ['error'=>'#end#404']);
					if(stripos($html, 'pdf') === false || strlen($html) < 1024*3) return LibFc::ReturnData(true, ['error'=>'#error#'.$html]);
					LibDir::CreateDir($pdfDir);
					file_put_contents($pdfFile, $html);
					@unlink($txtPdf);
					$exists = true;
				}
				if($exists) return $this->getHbqdDataFromPdf($pdfFile, $vin, $reg);
			break;
		}
		return LibFc::ReturnData(true, ['error'=>'', 'sma'=>[]]);
	}


	//采集东风的pdf
	public function getDflzmVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
            'base_uri' => 'https://www.dflzm.com.cn'
        ]);

        $sCache = '';
        $sToKen = '';
        $oCookie = new CookieJar();

        try {
            $oGuzzle = $oClient->get('/index.php/greenBill', [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
                $oCache = HtmlDomParser::str_get_html($sCache);
                $sToKen = $oCache->find('#token', 0)->getAttribute('value');
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#页面token获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}

        try {
            $oGuzzle = $oClient->get(sprintf('/index.php/greenBill/codeImage?%d', time()), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}
		$imgcodedata = base64_encode($sCache);
		$OthCodeOcr = new OthCodeOcr();
		$imgres = $OthCodeOcr->getCodeOcr($imgcodedata, 'dflzm', 'self');
		$imgres = $imgres['data'];
        // 第三步请求信息
        if (isset($imgres['imgcode']) && $sToKen)
        {
			$vin3 = substr($vin, 0, 3);
			$vin11 = substr($vin, 10, 1);
			$carType = $vin3 =='LGG' && $vin11 == 'L'? 'cv': 'pv';

            $aParam = [
                'vcode' => $imgres['imgcode'],
                't' => $carType,
                'code' => $vin,
                'csrf_token' => $sToKen
            ];
            try
            {
                $oGuzzle = $oClient->post('/index.php/greenBill/getBill', [
                    'cookies' => $oCookie,
                    'form_params' => $aParam,
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
                    $html = $oGuzzle->getBody()->getContents();
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
					if(stripos($htmlArr['msg'], '验证码') !== false){
						if($run < 5)
							return $this->getDflzmVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					if($htmlArr['code'] == 'ok' && !empty($htmlArr['content'])){
						return ['error'=>'', 'html'=>base64_decode($htmlArr['content'])];
					}else if(stripos($htmlArr['msg'], '该编号无查询结果') !== false){
						return ['error'=>'#end#该编号无查询结果', 'html'=>''];
					}else if($htmlArr['code'] == 'ok' && empty($htmlArr['content'])){
						return ['error'=>'#end#'.$html, 'html'=>''];
					}
					return ['error'=>'#error#'.$html, 'html'=>''];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
            }
        }
		else
		{
			 if($run < 5) return $this->getDflzmVin($vin, $run);
		}
	}


	//采集标致雪铁龙 神龙汽车的pdf
	public function getDpcaVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
            'base_uri' => 'http://www.dpca.com.cn'
        ]);

        $sCache = '';
        $sToKen = '';
        $oCookie = new CookieJar();

        try {
            $oGuzzle = $oClient->get(sprintf('/tools/verify_code.ashx?time=%s', microtime(true)), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}

		$imgcodedata = base64_encode($sCache);
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'dacp',
			'site'=>'self'
		];

		if(strlen($post['imgdata']) < 100)
		{
			if($run < 5) return $this->getDpcaVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];
        // 第三步请求信息
        if (isset($imgres['imgcode']))
        {
			$vin3 = substr($vin, 0, 3);
			$vin11 = substr($vin, 10, 1);
			$carType = $vin3 =='LGG' && $vin11 == 'L'? 'cv': 'pv';

            $aParam = [
                'vcode' => $imgres['imgcode'],
                'vin' => $vin
            ];
            try
            {
                $oGuzzle = $oClient->post('/tools/submit_ajax.ashx?action=GetPDFData', [
                    'cookies' => $oCookie,
                    'form_params' => $aParam,
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
                    $html = $oGuzzle->getBody()->getContents();
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
					if($htmlArr['status'] && !empty($htmlArr['msg']))
					{
						 try {
							$oGuzzle = $oClient->get($htmlArr['msg'], [
								'cookies' => $oCookie,
							]);
							if (200 == $oGuzzle->getStatusCode())
							{
								$sCache = $oGuzzle->getBody()->getContents();
								return ['error'=>'', 'html'=>$sCache];
							}
						} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
							return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}
					else if(stripos($htmlArr['msg'], '验证码') !== false)
					{
						//$LibYpApi->Get('ocr/logCodeOcrError', [], ['imgdata'=>$imgcodedata, 'result'=>json_encode($imgres)]);
						if($run < 5)
							return $this->getDpcaVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					else if(stripos($htmlArr['msg'], '不存在') !== false)
					{
						return ['error'=>'#end#不存在', 'html'=>''];
					}
					return ['error'=>'', 'html'=>''];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
            }
        }
		else
		{
			if($run < 5) return $this->getDpcaVin($vin, $run);
		}
	}

	//采集江铃的jpg
	public function getJmcglVin($vin, $run = 0, $catchImg = false)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'https://dms.jmcgl.com.cn:7070';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
			'verify'=>false,
            'base_uri' => $baseUrl
        ]);

        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
            $oGuzzle = $oClient->get('/opencps/(S(tvbjxz3bnusjc4cij0pzxntd))/OpenCertificateView.aspx', ['cookies' => $oCookie]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $html = $oGuzzle->getBody()->getContents();
				if(preg_match_all('/type="hidden"[^>]+name="([^"]+)"[^>]+value="([^"]*)"/iUs',$html, $match))
				{
					foreach($match[1] as $mk=>$mv)
					{
						$filedArr[$mv] = $match[2][$mk];
					}
				}
				if(preg_match('/opencps\/(\(S\([^\/]+)\//iUs', $html, $match)) $urlKey = $match[1];
				if(preg_match('/Telerik\.Web\.UI\.WebResource\.axd[^"]+;guid=([^"]+)"/iUs',$html, $match)) $codeimgGuid = $match[1];
				
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
		}

		if(empty($urlKey) || empty($codeimgGuid) || empty($filedArr)) return ['error'=>'#again#验证码、或者链接key链接获取失败'];
        try {
            $oGuzzle = $oClient->get('/opencps/'.$urlKey.'/Telerik.Web.UI.WebResource.axd?type=rca&isc=true&guid='.$codeimgGuid, [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage()];
		}
		
		$imgcodedata = base64_encode($sCache);
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'jmcgl',
			'site'=>'self'
		];

		if(strlen($post['imgdata']) < 500)
		{
			if($run < 5) return $this->getJmcglVin($vin, $run, $catchImg);
			else return ['error'=>'#again#验证码图片获取失败'];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];
        // 第三步请求信息
        if (isset($imgres['imgcode']) && !empty($filedArr))
        {
            $aParam = [
				'RadScriptManager1_TSM'=>';;System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35:zh-CN:1dfc24a8-f1c6-47eb-a669-f28ac03160f2:ea597d4b:b25378d2;Telerik.Web.UI, Version=2018.1.117.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4:zh-CN:3346c3e6-3c4c-4be3-94e3-1928d6a828a1:16e4e7cd:11e117d7',
				'__EVENTTARGET'=>'',
				'__EVENTARGUMENT'=>'',
				'__VIEWSTATEENCRYPTED'=>'',
                'txtValidCode' => $imgres['imgcode'],
                'txtVIN_CODE' => $vin,
                'txtMAIN_CAR_CATALOG_CODE' => '',
                'rdCaptcha_ClientState' => '',
                'btnSearch' => '查 询',
            ];
            try
            {
                $oGuzzle = $oClient->post('/opencps/'.$urlKey.'/OpenCertificateView.aspx', [
                    'cookies' => $oCookie,
                    'form_params' => array_merge($filedArr, $aParam)
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
					$reurl = ['../'=>$baseUrl.'/opencps/'.$urlKey.'/','&amp;'=>'&'];
                    $html = $oGuzzle->getBody()->getContents();
					if(stripos($html, '验证码有误') !== false)
					{
						//$LibYpApi->Get('ocr/logCodeOcrError', [], ['imgdata'=>$imgcodedata, 'result'=>json_encode($imgres)]);
						if($run < 5) 
							return $this->getJmcglVin($vin, $run, $catchImg);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}

					if(stripos($html, 'gridView_MAIN_CAR_CATALOG_CODE_ReadTextBox_0') === false) return ['error'=>'', 'data'=>[]];

					$oCache = HtmlDomParser::str_get_html($html);
					$arr = [
						'sma_gxb_code_show'=> $oCache->find('#gridView_MAIN_CAR_CATALOG_CODE_ReadTextBox_0', 0)->getAttribute('value'),
						'sma_year'=> $oCache->find('#gridView_PRODUCT_DATE_ReadTextBox_0', 0)->getAttribute('value')
					];

					if($catchImg)
					{
						try {
							$oGuzzle = $oClient->get('/opencps/'.$urlKey.'/'.strtr($oCache->find('#gridView_btnHBZ_Print_0', 0)->getAttribute('href'), $reurl), [
								'cookies' => $oCookie,
							]);
							if (200 == $oGuzzle->getStatusCode())
							{
								$html = $oGuzzle->getBody()->getContents();
								if(preg_match_all('/<img src="(..\/DownLoad\/[^"]+)" alt="环保证/iUs', $html, $match))
								{
									foreach($match[1] as $tm)
									{
										$arr['imgurl'][] = strtr($tm, $reurl);
									}
								}
								else
								{
									return ['error'=>'#again#清单图片获取失败'];
								}
							}
						} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
							return ['error'=>'#again#清单图片获取失败'.$oTransfer->getMessage()];
						}
					}
					return ['error'=>'', 'data'=>$arr];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
            }
        }
		else
		{
			 if($run < 5) return $this->getJmcglVin($vin, $run, $catchImg);
			  return ['error'=>'#again#验证码图片获取失败'];
		}
	}

	//采集红岩牌
	public function getHongyanVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'http://www.sih.cq.cn';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
            'base_uri' => $baseUrl
        ]);
		$header = ['User-Agent'=>'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'];
        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
            $oGuzzle = $oClient->get('/portal/ei/ei_pdf_query.aspx', ['cookies' => $oCookie,'headers'=>$header]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $html = $oGuzzle->getBody()->getContents();
				if(preg_match_all('/type="hidden"[^>]+name="([^"]+)"[^>]+value="([^"]*)"/iUs',$html, $match))
				{
					foreach($match[1] as $mk=>$mv)
					{
						$filedArr[$mv] = $match[2][$mk];
					}
				}
				if(preg_match('/Telerik\.Web\.UI\.WebResource\.axd[^"]+;guid=([^"]+)"/iUs',$html, $match)) $codeimgGuid = $match[1];
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
		}
	
		if(empty($codeimgGuid) || empty($filedArr)) return ['error'=>'#again#验证码、或者链接key链接获取失败'];
        try {
            $oGuzzle = $oClient->get('/portal/Telerik.Web.UI.WebResource.axd?type=rca&isc=true&guid='.$codeimgGuid, [
                'cookies' => $oCookie,'headers'=>$header
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage()];
		}

		$imgcodedata = base64_encode($sCache);
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'hongyan',
			'site'=>'self'
		];

		if(strlen($post['imgdata']) < 100)
		{
			if($run < 5) return $this->getHongyanVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败'];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];

        // 第三步请求信息
        if (isset($imgres['imgcode']) && !empty($filedArr))
        {
            $aParam = [
				'RadScriptManager1_TSM'=>';;System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35:zh-CN:9ead301a-2c07-4fc5-be19-f8423a34e117:ea597d4b:b25378d2;Telerik.Web.UI, Version=2014.1.225.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4:zh-CN:fe3df733-ee56-4563-8789-bc399360084a:16e4e7cd:f7645509:24ee1bba:92fe8ea0:fa31b949:19620875:874f8ea2:f46195d3:490a9d4e:bd8f85e4:b7778d6c:11e117d7:7165f74',
				'__EVENTTARGET'=>'',
				'__EVENTARGUMENT'=>'',
				'RadWindowManager1_ClientState'=>'',
				'RadTextBox1'=>$vin,
				'RadTextBox1_ClientState'=> '{"enabled":true,"emptyMessage":"","validationText":"'.$vin.'","valueAsString":"'.$vin.'","lastSetTextBoxValue":"'.$vin.'"}',
				'RadCaptcha1$CaptchaTextBox'=>$imgres['imgcode'],
				'RadCaptcha1_ClientState'=>'', 
				'btnVerify'=>'查询',
				'btnVerify_ClientState'=>'',
            ];
            try
            {
                $oGuzzle = $oClient->post('/portal/ei/ei_pdf_query.aspx', [
                    'cookies' => $oCookie,
                    'form_params' => array_merge($filedArr, $aParam),
					'headers'=>$header
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
					$html = $oGuzzle->getBody()->getContents();
					if(stripos($html, '验证码有误') !== false)
					{
						//$LibYpApi->Get('ocr/refundCodeOcr', $imgres);
						if($run < 5)
							return $this->getHongyanVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					if(preg_match('/(GetFile\.aspx\?ch\=[^&]+&id=\d+)/i', $html, $match)){
						try {
							$oGuzzle = $oClient->get('/portal/ei/'.$match[1], [
								'cookies' => $oCookie,
								'headers'=>$header
							]);
							if (200 == $oGuzzle->getStatusCode())
							{
								$sCache = $oGuzzle->getBody()->getContents();
								return ['error'=>'', 'html'=>$sCache];
							}
						} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
							return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}else if(stripos($html, '没有满足条件的数据') !== false){
						return ['error'=>'#end#没有满足条件的数据', 'html'=>''];
					}
					return ['error'=>''];
				
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
            }
        }
		else
		{
			 if($run < 5) return $this->getHongyanVin($vin, $run);
			  return ['error'=>'#again#验证码图片获取失败'];
		}
	}


	//采集北京奔驰
	public function getBenzbjVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'https://estore.mercedes-benz.com.cn';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
			'verify'=>false,
            'base_uri' => $baseUrl
        ]);
        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
            $oGuzzle = $oClient->get('/api/ecommerce/customers/captcha-pic?'.time(), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
				$captchaKey = $oGuzzle->getHeaders()['Captcha-Key'][0];
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage()];
		}

		$imgcodedata = str_replace('data:image/png;base64,', '', $sCache);
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'benzbj',
			'site'=>'self'
		];

		if(strlen($post['imgdata']) < 500)
		{
			if($run < 5) return $this->getBenzbjVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败'];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];

        // 第三步请求信息
        if (isset($imgres['imgcode']) && !empty($captchaKey))
        {
            try
            {
                $oGuzzle = $oClient->post('/environmental-service/environment/v1/search', [
                    'cookies' => $oCookie,
                    'form_params' => [
						'vinVal'=>$vin,
						'captchaCode'=>$imgres['imgcode'],
						'captchaKey'=>$captchaKey, 
					],
					'headers'=>['x-api-key'=>'fVClb96iFHNgZKAeNVEYqBOiGIMwgCP2m']
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
					$html = $oGuzzle->getBody()->getContents();
					
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr) || !isset($htmlArr['validCaptcha'])) return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
					if($htmlArr['validCaptcha'] && !empty($htmlArr['fileUrl']))
					{
						try {
							$oGuzzle = $oClient->get($htmlArr['fileUrl'], [
								'cookies' => $oCookie,
							]);
							if (200 == $oGuzzle->getStatusCode())
							{
								$sCache = $oGuzzle->getBody()->getContents();
								return ['error'=>'', 'html'=>$sCache];
							}
						} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
							return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}
					else if(!$htmlArr['validCaptcha'])
					{
						//$LibYpApi->Get('ocr/logCodeOcrError', [], ['imgdata'=>$imgcodedata, 'result'=>json_encode($imgres)]);
						if($run < 5) 
							return $this->getBenzbjVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					else if($htmlArr['validCaptcha'] && empty($htmlArr['fileUrl']))
					{
						//{"validCaptcha":true,"fileUrl":null}
						return ['error'=>'#end#'.$html, 'html'=>''];
					}
					return ['error'=>'', 'html'=>''];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
            }
        }
		else
		{
			 if($run < 5) return $this->getBenzbjVin($vin, $run);
			  return ['error'=>'#again#验证码图片获取失败'];
		}
	}

	//采集福迪牌
	public function getFdqcVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'http://www.fdqc.com';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 30,
            'cookies' => true,
            'base_uri' => $baseUrl
        ]);
        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
            $oGuzzle = $oClient->get('/stms/user/file_download_hbxx_vin.aspx', ['cookies' => $oCookie]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $html = $oGuzzle->getBody()->getContents();
				if(preg_match_all('/type="hidden"[^>]+name="([^"]+)"[^>]+value="([^"]*)"/iUs',$html, $match))
				{
					foreach($match[1] as $mk=>$mv)
					{
						$filedArr[$mv] = $match[2][$mk];
					}
				}
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
		}
	
		if(empty($filedArr)) return ['error'=>'#again#input获取失败'];

		$aParam = [
			'__EVENTTARGET'=>'',
			'__EVENTARGUMENT'=>'',
			'__VIEWSTATE'=>'',
			'__VIEWSTATEGENERATOR'=>'',
			'__VIEWSTATEENCRYPTED'=>'',
			'__EVENTVALIDATION'=>'',
			'Keywords'=>$vin,
			'Button1'=> '搜 索 '
		];
		try
		{
			$oGuzzle = $oClient->post('/stms/user/file_download_hbxx_vin.aspx', [
				'cookies' => $oCookie,
				'form_params' => array_merge($aParam, $filedArr)
			]);
			if (200 == $oGuzzle->getStatusCode())
			{
				$html = $oGuzzle->getBody()->getContents();
				if(stripos($html, "共有<b><font color='red'>0</font></b>") !== false) return ['error'=>'#end#共有0条', 'html'=>''];

				//file_download_prs_hbxx.aspx?FilePath=../upfile/affix/636290802847212500.pdf&FileListID=4096
				if(preg_match('/(file_download_prs_hbxx\.aspx\?FilePath\=[^\']+)/i', $html, $match))
				{
					try {
						$oGuzzle = $oClient->get('/stms/user/'.$match[1], [
							'cookies' => $oCookie,
						]);
						if (200 == $oGuzzle->getStatusCode())
						{
							$sCache = $oGuzzle->getBody()->getContents();
							return ['error'=>'', 'html'=>$sCache];
						}
					} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
						return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
					}
				}
				return ['error'=>''];
			}
		} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
		   return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
		}
  
	}


	//采集潍柴
	public function getWeichaiVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'http://www.vgvmotor.com';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 80,
            'cookies' => true,
            'base_uri' => $baseUrl
        ]);

        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
            $oGuzzle = $oClient->get('/api.php?m=Checkcode&code_len=4&font_size=14&width=88&height=37&font_color=&background=&time=0.'.rand(10,99).'464241104497'.rand(10,99), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage()];
		}
		$imgcode = $this->jsYzmByBaidu(base64_encode($sCache));
        // 第三步请求信息
        if ($imgcode != '')
        {
            try
            {
                $oGuzzle = $oClient->post('/index.php?a=hb_submit', [
                    'cookies' => $oCookie,
                    'form_params' => [
						'valArgs'=>$this->encodeWeichaiStr($vin.','.$imgcode),
						'attrArgs'=>$this->encodeWeichaiStr('VIN,code'),
					],
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
					$html = $oGuzzle->getBody()->getContents();
					$htmlArr = json_decode($html, true);
					if(!empty($htmlArr['ListHtml']))
					{
						if(stripos($htmlArr['ListHtml'], '没有找到相关信息') !== false)
						{
							return ['error'=>'#end#没有找到相关信息', 'html'=>''];
						}
						else
						{
							return ['error'=>'', 'html'=>$htmlArr['ListHtml']];
						}
					}
					else if(is_array($htmlArr))
					{
						return ['error'=>'', 'html'=>''];
					}
                }
				return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
            }
        }
		else
		{
			if($run < 5) return $this->getWeichaiVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败'];
		}
	}


	//采集BMW
	public function getBmwVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$baseUrl = 'http://www.bmw-brilliance.cn';
		$oClient = new Client([
            'debug' => false,
            'timeout' => 60,
            'cookies' => true,
            'base_uri' => $baseUrl
        ]);

        
        $filedArr = [];
        $oCookie = new CookieJar();
		$urlKey = '';
		$codeimgGuid = '';
        try {
			$oGuzzle = $oClient->get('/cms/cn/zh/emission/jsp/captcha_emission-inquiry.jsp?r=0.'.time(), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $html = $oGuzzle->getBody()->getContents();
				$htmlArr = json_decode($html, true);
				if(empty($htmlArr['data']['captcha'])) return ['error'=>'#again#验证码图片获取失败'];
				$imgcodedata = substr(strstr($htmlArr['data']['captcha'], ','), 1);
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage()];
		}
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'bmw',
			'site'=>'self'
		];
		
		if(strlen($post['imgdata']) < 100)
		{
			if($run < 5) return $this->getBmwVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败', 'html'=>''];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];
        if (isset($imgres['imgcode']) && $imgres['imgcode'] != '')
        {
            try
            {
				if(substr($vin, 0, 1) == 'L')
				{
					 $oGuzzle = $oClient->post('/cms/cn/zh/emission/jsp/action-bba.jsp', [
						'cookies' => $oCookie,
						'form_params' => [
							'captcha'=>$imgres['jscode'],
							'input-temp'=>$vin,
							'vin-model'=>$vin,
							'brand'=>'bba',
						],
					]);
				}
				else
				{
					 $oGuzzle = $oClient->post('/cms/cn/zh/emission/jsp/action.jsp', [
						'cookies' => $oCookie,
						'form_params' => [
							'captcha'=>$imgres['jscode'],
							'input-temp'=>$vin,
							'vin-model'=>$vin,
							'brand'=>'bmw',
						]
					]);
				}
                if (200 == $oGuzzle->getStatusCode())
                {
					$html = $oGuzzle->getBody()->getContents();
					if(stripos($html, 'pdf') === false || strlen($html) < 1024)
					{
						if(stripos($html,'showError(4)'))
						{
							return ['error'=>'#end#4'];
						}
						else if(stripos($html,'showError(-1)'))
						{
							$imgres['imgcode'] .= '='.$imgres['jscode'];
							//$LibYpApi->Get('ocr/logCodeOcrError', [], ['imgdata'=>$imgcodedata, 'result'=>json_encode($imgres)]);
							if($run < 5)
								return $this->getBmwVin($vin, $run);
							else
								return ['error'=>'#again#验证码错误'.$html];
						}
						return ['error'=>'#again#'.$html];
					}
					else
					{
						return ['error'=>'', 'html'=>$html];
					}
                }
				return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
				return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
            }
        }
		else
		{
			if($run < 5) return $this->getBmwVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败'];
		}
	}


	
	//采集东风的pdf
	public function getDflVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
            'base_uri' => 'http://environmental.dfl.com.cn'
        ]);

        $sCache = '';
        $sToKen = '';
        $oCookie = new CookieJar();
        try {
            $oGuzzle = $oClient->get(sprintf('/validateCode?time=%d', time()), [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			if($run < 5) return $this->getDflVin($vin, $run);
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}
		$imgcodedata = base64_encode($sCache);
		$post = [
			'imgdata'=>$imgcodedata,
			'type'=>'dfl',
			'site'=>'self'
		];
		/*$post = [
			'imgdata'=>$imgcodedata,
			'type'=>1,
			'site'=>'ttshitu'
		];*/

		if(strlen($post['imgdata']) < 50)
		{
			if($run < 5) return $this->getDflVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败', 'html'=>''];
		}

		$LibYpApi = new LibYpApi();
		$imgres = $LibYpApi->Get('ocr/getCodeOcr', [], $post);
		$imgres = $imgres['data'];
        if (isset($imgres['imgcode']))
        {
            try
            {
                $oGuzzle = $oClient->post('/api/envi/car/find/vin', [
                    'cookies' => $oCookie,
                    'form_params' =>[
						'vin'=>$vin,
						'validateCode'=>$imgres['imgcode']
					],
                ]);
                if (200 == $oGuzzle->getStatusCode())
                {
                    $html = $oGuzzle->getBody()->getContents();
					if(empty($html)) return ['error'=>'#end#数据没找到', 'html'=>$html];
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
					if(!empty($htmlArr['validateSecret']))
					{
						try
						{
							$oGuzzle = $oClient->get('/api/envifilemanager/fileview?id='.$htmlArr['validateSecret'].'&keynum='.$htmlArr['engineNo'], ['cookies' => $oCookie]);
							$html = $oGuzzle->getBody()->getContents();
							if(preg_match('/\/upload\/envi\/\"\+\"([^"]+[0-9a-zA-Z]{17,}\.pdf)/i', $html, $match))
							{
								///upload/envi/"+"HD2/DFL7162VANH6/202201/126fd38706844aceb09d61fcae4a956c.pdf
								//upload/envi/HD2/DFL7162VANH6/202103/LGBH92E04MY649913.PDF  /upload/envi/ZM/LGBY2ZAA1NM012854.pdf
								$pdfurl = '/upload/envi/'.$match[1];
								try
								{
									$oGuzzle = $oClient->get($pdfurl, ['cookies' => $oCookie]);
									$html = $oGuzzle->getBody()->getContents();
									return ['error'=>'', 'html'=>$html];
								}catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
									if(stripos($oTransfer->getMessage(), '404 Not Found') === false)
									{
										if($run < 5) return $this->getDflVin($vin, $run);
									}
									if(preg_match('/\/(DFL[a-zA-Z0-9]{2,})\/(2\d{5})\/'.$vin.'/', $pdfurl, $pmatch))
									{
										$addArr = [
											'sma_gxb_code_show'=>$pmatch[1],
											'sma_year'=>date('Y-m', strtotime($pmatch[2].'01'))
										];
										return ['error'=>'', 'html'=>'', 'sma'=>$addArr, 'pdf'=>$pdfurl];
									}
									return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
								}
							}
							if($run < 5) return $this->getDflVin($vin, $run);
							return ['error'=>'#again#pdf获取失败'.$html];
						}catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
						   return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}
					else if(empty($htmlArr['validateKey']))
					{
						//$LibYpApi->Get('ocr/logCodeOcrError', [], ['imgdata'=>$imgcodedata, 'result'=>json_encode($imgres)]);
						//$LibYpApi->Get('ocr/refundCodeOcr', $imgres);
						if($run < 5)
							return $this->getDflVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					return ['error'=>'', 'html'=>$html];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
				if($run < 5) return $this->getDflVin($vin, $run);
               return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
            }
        }
		if($run < 5) return $this->getDflVin($vin, $run);
		return ['error'=>'#again#验证码识别失败'];
	}

	private function encodeWeichaiStr($encrystr)
	{
		$v8 = new V8Js();
		$jscode = file_get_contents(mvc::$cfg['AUTOLOAD']['Oth']['path'].'lib/encryptWeichai.js');
		$jscode = str_replace('encrystr', $encrystr, $jscode);
		ob_start();
		$v8->executeString($jscode);
		ob_end_flush();
		return urldecode(ob_get_contents());
	}

	//简单的计算验证码百度 $imgdata = base64_encode(file_get_contents($toJpgFile)) http://www.weichaimotor.com/api.php?m=Checkcode&code_len=4&font_size=14&width=88&height=37&font_color=&background=&time=0.8602996234233118
	private function jsYzmByBaidu($imgdata)
	{
		$code = '';
		$oTransfer = null;
		if(strlen($imgdata) > 100)
		{
			$MainOcr = new MainOcr();
			$res = $MainOcr->general($imgdata);
			$str = str_replace(' ', '', implode(' ', $res['data']));
			if(preg_match('/(\d+)([\-\+\/\*])(\d+)\=/', $str, $match))
			{
				switch($match[2])
				{
					case '+': $code = $match[1] + $match[3]; break;
					case '-': $code = $match[1] - $match[3]; break;
					case '*': $code = $match[1] * $match[3]; break;
					case '/': $code = $match[1] / $match[3]; break;
				}
			}
		}
		return $code;
	}

	
	//广汽三菱
	public function getGmmcVin($vin)
	{
		$oCookie = new CookieJar();
		$oClient = new Client([
			'debug' => false,
			'timeout' => 10,
			'cookies' => true,
			'base_uri' => 'http://vcmpdf.gmmc.com.cn:8001'
		]);
		try {
			$oGuzzle = $oClient->get('/', ['cookies' => $oCookie,]);
			if (200 == $oGuzzle->getStatusCode())
			{
				$html = $oGuzzle->getBody()->getContents();
				if(preg_match_all('/type="hidden"[^>]+name="([^"]+)"[^>]+value="([^"]*)"/iUs',$html, $match))
				{
					foreach($match[1] as $mk=>$mv)
					{
						$filedArr[$mv] = $match[2][$mk];
					}
				}
			}
		} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			return ['error'=>'#again#页面token获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}
		if(empty($filedArr)) return ['error'=>'#again#input获取失败'.$html];
		$postArr = [
			'S_Type'=>'Rad_vin',
			'vinno'=>$vin,
			'cartype'=>'',
			'Button_sel.x'=>rand(20,50),
			'Button_sel.y'=>'17'
		];
		$postArr = array_merge($postArr, $filedArr);
		try
		{
			$oGuzzle = $oClient->post('/', [
				'cookies' => $oCookie,
				'form_params' =>$postArr
			]);
			if (200 == $oGuzzle->getStatusCode())
			{
				$html = $oGuzzle->getBody()->getContents();
				if(stripos($html, 'PDFVINNO/'.$vin.'.pdf'))
				{
					try {
						$oGuzzle = $oClient->get('/PDFVINNO/'.$vin.'.pdf', ['cookies' => $oCookie,]);
						if (200 == $oGuzzle->getStatusCode())
						{
							$html = $oGuzzle->getBody()->getContents();
							return ['error'=>'', 'html'=>$html];
						}
					} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
						return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
					}
				}
				else if(stripos($html, '查询VINNO不存在'))
				{
					return ['error'=>'#end#VINNO不存在'];
				}
				return ['error'=>'#again#'.$html, 'html'=>''];
			}
		} catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
		   return ['error'=>'#again#页面获取失败'.$oTransfer->getMessage()];
		}
	}

	public function curlCmd($cmd)
	{
		ob_start();
		passthru($cmd);
		$html = ob_get_contents();
		ob_end_clean();
		return $html;
	}



	public function getVolvocarsVin($vin, $run = 0)
	{
		$run++;
		$arr = ['error'=>'', 'html'=>''];
		$oClient = new Client([
            'debug' => false,
            'timeout' => 10,
            'cookies' => true,
            'base_uri' => 'https://eipv2-api-prod.volvocars.com.cn'
        ]);

        $sCache = '';
        $oCookie = new CookieJar();
        try {
            $oGuzzle = $oClient->get("/interface/Customer/createCaptcha", [
                'cookies' => $oCookie,
            ]);
            if (200 == $oGuzzle->getStatusCode())
            {
                $sCache = $oGuzzle->getBody()->getContents();
            }
        } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
			if($run < 5) return $this->getVolvocarsVin($vin, $run);
			return ['error'=>'#again#验证码图片获取失败'.$oTransfer->getMessage(), 'html'=>''];
		}
		$imgcodedata = base64_encode($sCache);
		if(strlen($imgcodedata) < 50){
			if($run < 5) return $this->getVolvocarsVin($vin, $run);
			else return ['error'=>'#again#验证码图片获取失败', 'html'=>''];
		}
		$OthCodeOcr = new OthCodeOcr();
		$imgres = $OthCodeOcr->getCodeOcr($imgcodedata, 'volvocars', 'self');
		$imgres = $imgres['data'];
        // 第三步请求信息
        if (isset($imgres['imgcode'])){
            try{
                $oGuzzle = $oClient->get('/interface/Customer/getFileInfo?vin='.$vin.'&code='.$imgres['imgcode'], ['cookies' => $oCookie]);
                if (200 == $oGuzzle->getStatusCode()) {
                    $html = $oGuzzle->getBody()->getContents();
					if(empty($html)) return ['error'=>'#end#数据没找到', 'html'=>$html];
					if(stripos($html, '验证码')){
						if($run < 5)
							return $this->getVolvocarsVin($vin, $run);
						else
							return ['error'=>'#again#验证码错误'.$html];
					}
					/*$dir = mvc::$cfg['PATH_MVC'].'../imgcod_volvocars/';
					@mkdir($dir);
					file_put_contents($dir.$imgres['imgcode'].'.png', base64_decode($imgcodedata));*/
					$htmlArr = json_decode($html, true);
					if(!is_array($htmlArr)) return ['error'=>'#again#pdf获取失败'.$html, 'html'=>''];
					if(!empty($htmlArr['file'])){
						try{
							$oGuzzle = $oClient->get('/interface/Customer/getFile?file='.$htmlArr['file'].'&name='.$htmlArr['name'], ['cookies' => $oCookie]);
							$html = $oGuzzle->getBody()->getContents();
							return ['error'=>'', 'html'=>$html];
						}catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
						   return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
						}
					}else if($htmlArr['status'] === -1){
						return ['error'=>'#end#null'];
					}
					return ['error'=>'#error#'.$html];
                }
            } catch (\GuzzleHttp\Exception\TransferException $oTransfer) {
               return ['error'=>'#again#pdf获取失败'.$oTransfer->getMessage(), 'html'=>''];
            }
        }else{
			 if($run < 5) return $this->getVolvocarsVin($vin, $run);
		}
	}

}