Paip. UnionPay payment interface Order Number UUID Algorithm

Source: Internet
Author: User

Paip. UnionPay payment interface Order No. UUIDAlgorithm

In the past few days, the project has received a UnionPay payment interface. The UUID algorithm of the interface order number is described as follows:

During UnionPay payment, the first four order numbers (16-byte numeric strings) submitted by merchants to the UnionPay payment system are customized. Merchants can customize the order numbers based on their business needs, the first four digits are different. For example, the ET Business is 4000, the mail business is 5000, and the physical sales business is 6000. In addition, the 5-9 digits of the order number must be the last 5 digits of the merchant's merid.

That is to say, there are 16 digits in total, of which 5 are occupied .. only 11 digits can be used effectively ..

The Order Number Format of my project is yyyymmdd_hhmmssfff, for example, 20120816_19180000034.

The length is up to 19 characters. It seems that the order number must be converted to the UnionPay format when passing the parameter. Because the time must be accurate to ms, the shortest is also in the yymmddhhmmssfff format and requires 15 characters ..

It seems that only the relative Ms count can be used. I will first set a benchmark time. I will use 00:00:00. 000, and then the current time minus the benchmark time to get the total number of milliseconds. First, calculate it with 11 bits and 9. The maximum loading and ending time is 09:46:39, which can be used cyclically .. start from 0 again ..

Then, the 11 order number is divided into two parts, and the last five digits of the merchant's merid are inserted in the middle .. The order number that meets the UnionPay interface standards is spelled out ..

 

------ Get the 11-digit order number, accurate to Ms ..
// From 2012.1.1
Public static string getuuid11 (string UUID)
{
// 20120816_19180000034
UUID = UUID. substring (0, 18 );
Datetime dt1 = new datetime (2012, 1, 1 );
Datetime dt2 = datetime. parseexact (UUID, "yyyymmdd_hhmmssfff", null );
/// Dt2.ticks = "634807414811230000 ";
Timespan Ts = dt2-dt1;
String MS = ts. totalmilliseconds. tostring ();
MS = pad0left (MS, 11 );
Return MS;
}

 

// Calculate the maximum load end time,
Private Static string Test2 ()
{
String totalmilliseconds = "99999999999 ";
Long ticks = long. parse (totalmilliseconds) * 10000;
Timespan Ts = new timespan (ticks );
Datetime dt1 = new datetime (2012, 1, 1 );

Datetime dt2 = dt1.add (TS); // {09:46:39


Return "";
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.