CMXX - Included VIN API in cartest

This commit is contained in:
“VeLiTi”
2024-11-16 15:40:23 +01:00
parent f716e80360
commit 974efdf323
7 changed files with 107 additions and 31 deletions

View File

@@ -68,7 +68,7 @@ if ($stmt->rowCount() == 1) {
$stmt_service->execute([$user_data['service'], $user_data['id']]); $stmt_service->execute([$user_data['service'], $user_data['id']]);
} }
$token = createCommunicationToken($user_data['service']); $token = createCommunicationToken($user_data['userkey']);
$user = array( $user = array(
'id' => $user_data['id'], 'id' => $user_data['id'],

View File

@@ -3,17 +3,16 @@ defined($security_key) or exit;
//------------------------------------------ //------------------------------------------
// VIN Decoder // VIN Decoder
// //------------------------------------------
//--------------START ---------------------
// translated from JS (kevinboutin on 3/11/18) to PHP // translated from JS (kevinboutin on 3/11/18) to PHP
// https://gist.github.com/kevboutin/3ac029e336fc7cafd20c05adda42ffa5 // https://gist.github.com/kevboutin/3ac029e336fc7cafd20c05adda42ffa5
//------------------------------------------ //------------------------------------------
// Transliterate VIN characters for validation // Transliterate VIN characters for validation
function transliterate($c) { function transliterate($c) {
$index = strpos('0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ', $c); $index = strpos('0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ', $c);
return $index % 10; return $index % 10;
} }
// Determine the check digit to validate the VIN // Determine the check digit to validate the VIN
function getCheckDigit($vin) { function getCheckDigit($vin) {
$map = '0123456789X'; $map = '0123456789X';
@@ -24,51 +23,65 @@ function getCheckDigit($vin) {
} }
return $map[$sum % 11]; return $map[$sum % 11];
} }
// Validate the VIN // Validate the VIN
function validateVIN($vin) { function validateVIN($vin) {
if (strlen($vin) !== 17) return false; if (strlen($vin) !== 17) return false;
return getCheckDigit($vin) === $vin[8]; return getCheckDigit($vin) === $vin[8];
} }
// Determine the year of the vehicle //------------------------------------------
function getYear($pos7, $pos10) { //-------- END --------------------------
$years = [1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039]; //------------------------------------------
$values = "ABCDEFGHJKLMNPRSTVWXY123456789ABCDEFGHJKLMNPRSTVWXY123456789";
$index = is_numeric($pos7) ? strpos($values,$pos10) : strrpos($values, $pos10); //GET WMI - world manufacturer ID
return $years[$index]; function getWMI($vin){
//WMI = first 3 digits
$wmi = substr($vin, 0, 3);
return $wmi;
}
// VDS - vehicle descriptor
function getVDS($vin){
//WMI = first 3 digits
$vds = substr($vin, 3, 5);
return $vds;
}
// VIS - serialnumber
function getVIS($vin){
//WMI = first 3 digits
$vis = substr($vin, 9, 8);
return $vis;
} }
// Get the manufacturing country of the vehicle // Get the manufacturing country of the vehicle
function getCountry($wmi) { function getCountry($wmi) {
$codes = ['AAV', 'AHT', 'AFA', 'CL9', 'JA', 'JC1', 'JF', 'JHL', 'JHM', 'JMB', 'JM6', 'JN', 'JS', 'JT', 'JY', 'KL', 'KM', 'KN', 'KPT', 'L6T', 'LBE', 'LBV', 'LDC', 'LE4', 'LFM', 'LFP', 'LFV', 'LGB', 'LGJ', 'LGW', 'LGX', 'LH1', 'LHG', 'LJ1', 'LJD', 'LLV', 'LMG', 'LPA', 'LS5', 'LSG', 'LSJ', 'LSV', 'LTV', 'LVG', 'LVH', 'LVR', 'LVS', 'LVV', 'LWV', 'LZW', 'MS0', 'NMT', 'NMO', 'PL1', 'SAJ', 'SAL', 'SAR', 'SAT', 'SB1', 'SCC', 'SCF', 'SCE', 'SFD', 'SHH', 'SHS', 'SJN', 'TCC', 'TMA', 'TMB', 'TRU', 'TSM', 'U5Y', 'UU9', 'VA0', 'VF1', 'VF2', 'VF3', 'VF4', 'VF5', 'VF6', 'VF7', 'VF8', 'VF9', 'VFE', 'VNK', 'VSS', 'VV9', 'WAG', 'WAU', 'WAP', 'WBA', 'WBS', 'WBX', 'WDB', 'WDC', 'WDD', 'WMX', 'WEB', 'WF0', 'WJM', 'WJR', 'WKK', 'WMA', 'WME', 'WMW', 'WP0', 'WP1', 'WUA', 'WVG', 'WVW', 'WV1', 'WV2', 'W09', 'W0L', 'W0SV', 'XLR', 'YK1', 'YS2', 'YS3', 'YS4', 'YTN', 'YV1', 'YV2', 'YV3', 'ZA9', 'ZAM', 'ZAR', 'ZCF', 'ZFA', 'ZFF', 'ZGA', 'ZHW', 'ZLA', '1B', '1C', '1F', '1G', '1G1', '1G3', '1G9', '1GC', '1GM', '1HG', '1J', '1L', '1M', '1N', '1VW', '1YV', '2DG', '2F', '2G', '2G1', '2G2', '2HG', '2HH', '2HJ', '2HK', '2HM', '2M', '2T', '3F', '3G', '3HG', '3HM', '3KP', '3N', '3VW', '4F', '4J', '4M', '4S3', '4S4', '4S6', '4T', '4US', '5FN', '5J6', '5L', '5N', '5T', '5U', '5X', '5YJ', '55', '6F', '6G', '6G1', '6G2', '6H', '6MM', '6T1', '7A3', '8AP', '8AF', '8AG', '8AW', '8AJ', '8A1', '8AC', '8BC', '8AD', '8C3', '8AT', '9BD', '9BG', '9BW', '9BF', '93H', '9BR', '936', '935', '93Y', '93X', '9BH', '95P', '94D', '98R', '988', '98M', '9BM', '99A', '99J', '9C2', '9C6', '9CD', '93W', '93Z', '953', '9BS', '9BV', '9UJ', '9UK', '9UW']; include './settings/settingsvin.php';
$countries = ['South Africa', 'South Africa', 'South Africa', 'Tunisia', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'Japan', 'South Korea', 'South Korea', 'South Korea', 'South Korea', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China','China','China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'China', 'Myanmar', 'Turkey', 'Turkey', 'Malaysia', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'United Kingdom', 'Switzerland', 'Czech Republic', 'Czech Republic', 'Hungary', 'Hungary', 'Slovakia', 'Romania', 'Austria', 'France', 'France', 'France', 'France', 'France', 'France', 'France', 'France', 'France', 'France', 'France', 'Spain', 'Spain', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Germany', 'Netherlands', 'Finland', 'Sweden', 'Sweden', 'Sweden', 'Sweden', 'Sweden', 'Sweden', 'Sweden', 'Italy', 'Italy', 'Italy', 'Italy', 'Italy', 'Italy', 'Italy', 'Italy', 'Italy', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Canada', 'Mexico', 'Mexico', 'Mexico', 'Mexico', 'Mexico', 'Mexico', 'Mexico', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'United States', 'Australia', 'Australia', 'Australia', 'Australia', 'Australia', 'Australia', 'Australia', 'New Zealand', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Argentina', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil','Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Brazil', 'Uruguay', 'Uruguay', 'Uruguay']; return $countries[substr($wmi, 0, 2)] ?? 'Unknown';
$i = array_search($wmi, $codes);
if ($i === false) $i = array_search(substr($wmi, 0, 2), $codes);
return $countries[$i] ?? 'Unknown';
} }
// Get the manufacturer of the vehicle // Get the manufacturer of the vehicle
function getManufacturer($wmi) { function getManufacturer($wmi) {
$codes = ['AAV', 'AHT', 'AFA', 'CL9', 'JA', 'JC1', 'JF', 'JHL', 'JHM', 'JMB', 'JM6', 'JN', 'JS', 'JT', 'JY', 'KL', 'KM', 'KN', 'KPT', 'L6T', 'LBE', 'LBV', 'LDC', 'LE4', 'LFM', 'LFP', 'LFV', 'LGB', 'LGJ', 'LGW', 'LGX', 'LH1', 'LHG', 'LJ1', 'LJD', 'LLV', 'LMG', 'LPA', 'LS5', 'LSG', 'LSJ', 'LSV', 'LTV', 'LVG', 'LVH', 'LVR', 'LVS', 'LVV', 'LWV', 'LZW', 'MS0', 'NMT', 'NMO', 'PL1', 'SAJ', 'SAL', 'SAR', 'SAT', 'SB1', 'SCC', 'SCF', 'SCE', 'SFD', 'SHH', 'SHS', 'SJN', 'TCC', 'TMA', 'TMB', 'TRU', 'TSM', 'U5Y', 'UU9', 'VA0', 'VF1', 'VF2', 'VF3', 'VF4', 'VF5', 'VF6', 'VF7', 'VF8', 'VF9', 'VFE', 'VNK', 'VSS', 'VV9', 'WAG', 'WAU', 'WAP', 'WBA', 'WBS', 'WBX', 'WDB', 'WDC', 'WDD', 'WMX', 'WEB', 'WF0', 'WJM', 'WJR', 'WKK', 'WMA', 'WME', 'WMW', 'WP0', 'WP1', 'WUA', 'WVG', 'WVW', 'WV1', 'WV2', 'W09', 'W0L', 'W0SV', 'XLR', 'YK1', 'YS2', 'YS3', 'YS4', 'YTN', 'YV1', 'YV2', 'YV3', 'ZA9', 'ZAM', 'ZAR', 'ZCF', 'ZFA', 'ZFF', 'ZGA', 'ZHW', 'ZLA', '1B', '1C', '1F', '1G', '1G1', '1G3', '1G9', '1GC', '1GM', '1HG', '1J', '1L', '1M', '1N', '1VW', '1YV', '2DG', '2F', '2G', '2G1', '2G2', '2HG', '2HH', '2HJ', '2HK', '2HM', '2M', '2T', '3F', '3G', '3HG', '3HM', '3KP', '3N', '3VW', '4F', '4J', '4M', '4S3', '4S4', '4S6', '4T', '4US', '5FN', '5J6', '5L', '5N', '5T', '5U', '5X', '5YJ', '55', '6F', '6G', '6G1', '6G2', '6H', '6MM', '6T1', '7A3', '8AP', '8AF', '8AG', '8AW', '8AJ', '8A1', '8AC', '8BC', '8AD', '8C3', '8AT', '9BD', '9BG', '9BW', '9BF', '93H', '9BR', '936', '935', '93Y', '93X', '9BH', '95P', '94D', '98R', '988', '98M', '9BM', '99A', '99J', '9C2', '9C6', '9CD', '93W', '93Z', '953', '9BS', '9BV', '9UJ', '9UK', '9UW']; include './settings/settingsvin.php';
$manufacturers = ['Volkswagen', 'Toyota', 'Ford', 'Wallyscar', 'Isuzu', 'Fiat Automobiles/Mazda', 'Fuji Heavy Industries', 'Honda', 'Honda', 'Mitsubishi', 'Mazda', 'Nissan', 'Suzuki', 'Toyota', 'Yamaha', 'Daewoo/GM Korea', 'Hyundai', 'Kia', 'SsangYong', 'Geely', 'Beijing Hyundai', 'BMW Brilliance', 'Dongfeng Peugeot-Citroen', 'Beijing Benz', 'FAW Toyota (Sichuan)', 'FAW Car', 'FAW-Volkswagen', 'Dongfeng Nissan', 'Dongfeng Fengshen', 'Great Wall (Havel)', 'BYD Auto', 'FAW Haima', 'Guangzhou Honda', 'JAC', 'Dongfeng Yueda Kia', 'Lifan', 'GAC Trumpchi', 'Changan PSA (DS Automobiles)', 'Changan Suzuki', 'SAIC General Motors', 'SAIC MG', 'SAIC Volkswagen', 'FAW Toyota (Tianjin)', 'GAC Toyota', 'Dongfeng Honda', 'Changan Mazda', 'Changan Ford', 'Chery', 'GAC Fiat', 'SAIC GM Wuling', 'KIA Myanmar', 'Toyota', 'Ford Otosan', 'Proton', 'Jaguar', 'Land Rover', 'Rover', 'Triumph', 'Toyota', 'Lotus Cars', 'Aston Martin Lagonda Limited', 'DeLorean', 'Alexander Dennis', 'Honda', 'Honda', 'Nissan', 'Micro Compact Car AG (SMART 1998-1999)', 'Hyundai', 'Skoda', 'Audi', 'Suzuki', 'Kia', 'Dacia', 'OAF', 'Renault', 'Renault', 'Peugeot', 'Talbot', 'Iveco Unic SA', 'Renault Trucks/Volvo', 'Citroen', 'Matra/Talbot/Simca', 'Bugatti', 'IvecoBus', 'Toyota', 'SEAT', 'Tauro Sport Auto', 'Neoplan', 'Audi', 'Alpina', 'BMW', 'BMW M', 'BMW', 'Mercedes-Benz', 'DaimlerChrysler AG/Daimler AG', 'DaimlerChrysler AG/Daimler AG', 'DaimlerChrysler AG/Daimler AG', 'EvoBus', 'Ford of Europe', 'Iveco', 'Irmscher', 'Karl Kassbohrer Fahrzeugwerke', 'MAN', 'Smart', 'Mini', 'Porsche car', 'Porsche SUV', 'Quattro', 'Volkswagen', 'Volkswagen', 'Volkswagen Commercial Vehicles', 'Volkswagen Commercial Vehicles', 'Ruf Automobile', 'Opel/Vauxhall', 'Opel Special Vehicles', 'DAF Trucks', 'Saab', 'Scania, Sodertalje', 'Saab', 'Scania, Katrineholm', 'Saab NEVS', 'Volvo Cars', 'Volvo Trucks', 'Volvo Buses', 'Bugatti', 'Maserati', 'Alfa Romeo', 'Iveco', 'Fiat Automobiles', 'Ferrari', 'IvecoBus', 'Lamborghini', 'Lancia', 'Dodge', 'Chrysler', 'Ford', 'General Motors', 'Chevrolet', 'Oldsmobile', 'Google', 'Chevrolet', 'Pontiac', 'Honda', 'Jeep', 'Lincoln', 'Mercury', 'Nissan', 'Volkswagen', 'Mazda', 'Ontario Drive & Gear', 'Ford', 'General Motors', 'Chevrolet', 'Pontiac', 'Honda', 'Acura', 'Honda', 'Honda', 'Hyundai', 'Mercury', 'Toyota', 'Ford', 'General Motors', 'Honda', 'Honda', 'Kia', 'Nissan', 'Volkswagen', 'Mazda', 'Mercedes-Benz', 'Mercury', 'Subaru', 'Subaru', 'Honda', 'Toyota', 'BMW', 'Honda', 'Honda', 'Lincoln', 'Hyundai', 'Toyota', 'BMW', 'Hyundai/Kia', 'Tesla', 'Mercedes-Benz', 'Ford', 'General Motors', 'Chevrolet', 'Pontiac', 'Holden', 'Mitsubishi', 'Toyota', 'Honda', 'Fiat', 'Ford', 'General Motors', 'Volkswagen', 'Toyota', 'Renault', 'Mercedes-Benz', 'Citroen', 'Peugeot', 'Honda', 'Iveco', 'Fiat Automoveis', 'General Motors', 'Volkswagen', 'Ford', 'Honda', 'Toyota', 'Peugeot', 'Citroen', 'Renault', 'Souza Ramos - Mitsubishi/Suzuki', 'Hyundai Motor Company/Hyundai', 'CAOA/Hyundai', 'Nissan', 'Chery', 'Jeep', 'BMW', 'Mercedes-Benz', 'Audi', 'JLR Jaguar Land Rover', 'Honda Motorcycles', 'Yamaha', 'Suzuki Motorcycles', 'Fiat Professional', 'Iveco', 'VW Trucks/MAN', 'Scania', 'Volvo Trucks', 'Chery', 'Lifan', 'Kia']; return $manufacturers[$wmi] ?? 'Unknown';
$i = array_search($wmi, $codes);
if ($i === false) $i = array_search(substr($wmi, 0, 2), $codes);
return $manufacturers[$i] ?? 'Unknown';
} }
function getYear($vis){
include './settings/settingsvin.php';
//first character = year
return $years[substr($vis, 0, 1)] ?? 'Unknown';
}
// Check if get_content has 17 characters, then expect VIN // Check if get_content has 17 characters, then expect VIN
if (strlen($get_content) == 17){ if (strlen($get_content) == 17){
$vin = strtoupper($get_content); $vin = strtoupper($get_content);
$messages = [ $messages = [
"VIN" => $vin, "VIN" => $vin,
"IsValid" => (validateVIN($vin) ? "Yes" : "No"), "IsValid" => (validateVIN($vin) ? "Yes" : "No"),
"Manufacturer" => getManufacturer(substr($vin, 0, 3)), "Manufacturer" => getManufacturer(getWMI($vin)),
"Country" => getCountry(substr($vin, 0, 3)), "year" => getYear(getVIS($vin))
"year" => getYear($vin[6], $vin[9])
]; ];
} }
else { else {

View File

@@ -1127,3 +1127,40 @@ a.document.write('</body></html>');
a.document.close(); a.document.close();
a.print(); a.print();
} }
//------------------------------------------
// decodeVIN api
//------------------------------------------
function decodeVIN(){
var vin = document.getElementById("VIN").value;
var token = document.getElementById("token").innerHTML;
var action = '/v2/vin/'+vin;
var url = link+action;
var bearer = 'Bearer ' + token;
fetch(url, {
method: 'GET',
withCredentials: true,
credentials: 'include',
headers: {
'Authorization': bearer,
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(vin_details=> {
console.log(vin_details);
document.getElementById("year").value = vin_details['year'];
var carbrands = document.getElementById("carbrands");
carbrands.options[carbrands.selectedIndex].value = vin_details['Manufacturer'];
carbrands.options[carbrands.selectedIndex].innerHTML = vin_details['Manufacturer'];
})
.catch(error => {
console.log(error)
})
}

View File

@@ -91,6 +91,10 @@ $view .= ' <div class="content-block order-details">
<h3>'.$cartest_cartype.'</h3> <h3>'.$cartest_cartype.'</h3>
<p>'.$cartest->cartype.'</p> <p>'.$cartest->cartype.'</p>
</div> </div>
<div class="order-detail">
<h3>'.$general_year.'</h3>
<p>'.(isset($cartest_header['year']) ? $cartest_header['year']: '').'</p>
</div>
<div class="order-detail"> <div class="order-detail">
<h3>'.$cartest_carvin.'</h3> <h3>'.$cartest_carvin.'</h3>
<p>'.$cartest_header['CarVIN'].'</p> <p>'.$cartest_header['CarVIN'].'</p>

View File

@@ -39,6 +39,7 @@ $cartest = [
'cartype' => '', 'cartype' => '',
'header' => [ 'header' => [
'CarVIN' => '', 'CarVIN' => '',
'year' => '',
'NameTester'=> $_SESSION['username'], 'NameTester'=> $_SESSION['username'],
'SN' =>'', 'SN' =>'',
'HW' =>'', 'HW' =>'',
@@ -189,6 +190,11 @@ $view .= ' <div class="content-block order-details">
<div class="block-header"> <div class="block-header">
<i class="fa-solid fa-circle-info"></i></i>'.$cartest_information.' <i class="fa-solid fa-circle-info"></i></i>'.$cartest_information.'
</div> </div>
<div class="order-detail">
<h3>'.$cartest_carvin.'</h3>
<p><input id="VIN" type="text" name="header[CarVIN]" onchange="decodeVIN()" value="'.$cartest['header']['CarVIN'].'"></p>
<p id="token" value="" hidden>'.$bearertoken.'</p>
</div>
<div class="order-detail"> <div class="order-detail">
<h3>'.$cartest_carbrand.'</h3> <h3>'.$cartest_carbrand.'</h3>
<p>'.$carbrands_input.' <p>'.$carbrands_input.'
@@ -200,8 +206,8 @@ $view .= ' <div class="content-block order-details">
<p><input type="text" name="cartype" value="'.$cartest['cartype'].'"></p> <p><input type="text" name="cartype" value="'.$cartest['cartype'].'"></p>
</div> </div>
<div class="order-detail"> <div class="order-detail">
<h3>'.$cartest_carvin.'</h3> <h3>'.$general_year.'</h3>
<p><input type="text" name="header[CarVIN]" value="'.$cartest['header']['CarVIN'].'"></p> <p><input id="year" type="text" name="header[year]" value="'.$cartest['header']['year'].'"></p>
</div> </div>
</div> </div>
'; ';

View File

@@ -64,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_SESSION['profile'] = $responses->profile; $_SESSION['profile'] = $responses->profile;
$_SESSION['userkey'] = $responses->userkey; $_SESSION['userkey'] = $responses->userkey;
$_SESSION['language'] = $responses->language; $_SESSION['language'] = $responses->language;
$_SESSION['token'] = $responses->token;
$language_user = trim($responses->language) ?? 'US'; $language_user = trim($responses->language) ?? 'US';
if($responses->profile == 'firmwaretool,application'){ if($responses->profile == 'firmwaretool,application'){

15
settings/settingsvin.php Normal file

File diff suppressed because one or more lines are too long