STUDY WHILE YOU ARE BORING


  • 首頁

  • 搜索

  • 技术

  • Tags

  • 关于我

How to generate UPS SHIPID or Shipment IdentifyID?

發表於 May 27, 2019   |   作者: Tim   |   分类: 技术   |   评论

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

  1. Tracking ID: 1Z 123 X56 Y6 4400 0050
  2. Exclude the Data Identifier 1Z: __ 123 X56 Y6 4400 0050
  3. Exclude the shipper number: __ Y6 4400 0050
  4. Exclude the service indicator and check digit: _ __ 4400 005
  5. Calculate 4400 005 : 26**4 = 9,628
  6. Calculate (4400 005 - (9*264)) : 263 = 16,341
  7. Calculate (4400 005 - (9264) - (16263)) : 26**2 = 8,883
  8. Calculate (4400 005 - (9264) - (16263) - (826*2)) : 26 = 22,961
  9. Calculate 4400 005 - (9264) - (16263) - (8262) - (2226) = 25,000
    5 intermediate results: 9 16 8 22
  10. 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

  1. G P F W Z
  2. 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:

  1. Extract 2 to 8 digits, 4V90A9
  2. Extract 10 to 17 digits (6867812), convert to 26 number system (f0jcg)
  3. if the length of result in step 2) less then 5, please put number 3 to its end.
  4. 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
  5. 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;
}
ups, SHIPID
Generate OUTLINE client compatible ACCESSKEY
搭建mutt+msmtp发信服务

钜添

56 文章
2 分類
1 页面
GitHub 日记技术
php apache centos macos mysql https shadowsocks mac 微信 ups svn javascript outline accesskey Chrome Extension letsencrypt ssl free certification certbo wildcard renew cloudflare pgsql 归档 binlog isset array_key_exists redmine axure
© 2026 钜添   |   文章 RSS     |  登录
由 Typecho 强力驱动
主題 - NexT
Send message encrypted and private - Msg2
Build your Under Construction Page without hosting - UnderConstruct.IO