How to generate UPS SHIPID or Shipment IdentifyID?
What's SHIPID?
UPS tracking number is format like 1Z4V90A96768678127, the SHIPID is short for it. For example.
Normal:1Z4V90A96768678127
ShipID:4V90A9N3SKP
If we know the normal one, I suppose we could calculate the ShipID from it.
But how?
After a lot of research, we could only find some pieces since useful.
Other's job
Generating the UPS shipment ID per packing list Conversion of a string
with BASE26 calculation
- Tracking ID: 1Z 123 X56 Y6 4400 0050
- Exclude the Data Identifier 1Z: __ 123 X56 Y6 4400 0050
- Exclude the shipper number: __ Y6 4400 0050
- Exclude the service indicator and check digit: _ __ 4400 005
- Calculate 4400 005 : 26**4 = 9,628
- Calculate (4400 005 - (9*264)) : 263 = 16,341
- Calculate (4400 005 - (9264) - (16263)) : 26**2 = 8,883
- Calculate (4400 005 - (9264) - (16263) - (826*2)) : 26 = 22,961
- Calculate 4400 005 - (9264) - (16263) - (8262) - (2226) = 25,000
5 intermediate results: 9 16 8 22- Base 26 cross reference
Value: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Converted Value: 3 4 7 8 9 B C D F G H J K L M N P Q R S T V W X Y Z
- G P F W Z
- Final Shipment Number: 123X 56GP FWZ
It is really not clear. What is the step 5 to step 9's mean?
But yes, someone has find out the way about the calculation!
Destination
Finally, after a lot of testing, I find out the way.
The tracking number 1Z4V90A96768678127 as an example:
- Extract 2 to 8 digits, 4V90A9
- Extract 10 to 17 digits (6867812), convert to 26 number system (f0jcg)
- if the length of result in step 2) less then 5, please put number 3 to its end.
Replace the value from the dictionary, For example, f=N. And so on, f0jcg=N3SKP
0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p 3 4 7 8 9 B C D F G H J K L M N P Q R S T V W X Y Z
- Flatten step 1) to get 4V90A9N3SKP
PHP sample
function upsSHID($longid) {
if (strlen ( $longid ) < 17) {
echo $longid;
exit ();
}
$acc = substr ( $longid, 2, 6 );
$num = substr ( $longid, 10, 7 );
$num26 = base_convert ( $num, 10, 26 );
$dict1 = array(
'0' => '0',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'A' => '10',
'B' => '11',
'C' => '12',
'D' => '13',
'E' => '14',
'F' => '15',
'G' => '16',
'H' => '17',
'I' => '18',
'J' => '19',
'K' => '20',
'L' => '21',
'M' => '22',
'N' => '23',
'O' => '24',
'P' => '25'
);
$dict2 = array (
'0' => '3',
'1' => '4',
'2' => '7',
'3' => '8',
'4' => '9',
'5' => 'B',
'6' => 'C',
'7' => 'D',
'8' => 'F',
'9' => 'G',
'10' => 'H',
'11' => 'J',
'12' => 'K',
'13' => 'L',
'14' => 'M',
'15' => 'N',
'16' => 'P',
'17' => 'Q',
'18' => 'R',
'19' => 'S',
'20' => 'T',
'21' => 'V',
'22' => 'W',
'23' => 'X',
'24' => 'Y',
'25' => 'Z'
);
$num26 = strtoupper ( $num26 );
$sid = '';
for($i = 0; $i < strlen ( $num26 ); $i ++) {
$k = substr ( $num26, $i, 1 );
$sid .= $dict2 [$dict1 [$k]];
}
return $acc . $sid;
}