Table of Contents

Brief Introduction

Basic concepts

Functional Overview

Convention

Character encoding

  This document adopts UTF-8 character encoding format

Introduction to ISO8601 Standard

Date representation

  The year is composed of four digits, with the Gregorian calendar year 1 as 0001, the Gregorian calendar year 1 as 0000, the Gregorian calendar year 2 as -0001, and so on. The application of other chronological methods requires conversion to the Gregorian calendar, but if there is a mutually agreed upon other chronological method between the sending and receiving parties, they can apply it themselves.

Calendar date representation

  The year is 4 digits, the month is 2 digits, and the day of the month is 2 digits. For example, May 3, 2004 can be written as 2004-05-03 or 20040503 .

Sequential date representation

  The number of days within a year can be directly expressed as 365 days in a normal year and 366 days in a leap year. May 3, 2004 can be expressed as 2004-157 or 2004157.

Calendar week and day notation

  You can use two digits to represent the calendar week within the current year, and add one digit to represent the day within the calendar week. However, a capital letter W should be added before the calendar week, such as May 3, 2004, which can be written as 2004-W17-3 or 2004W173. But 2004-W011 started on January 5, 2004, and the previous few days belonged to the 54th calendar week of the previous year. Each calendar week started on Monday and Sunday was the 7th day.

Time representation of days

  The hours, minutes, and seconds are all represented by two digits, with a capital letter Z added at the end of UTC time. Other time zones are represented by actual time plus time difference. If 2:30pm UTC time is represented as 14:30:05Z or 143005Z , then Beijing time is represented as 22:30:05+08:00 or 223005+0800, which can also be simplified as 223005+08.

Combination representation of date and time

  When merging representations, a capital letter T should be added before the time. To represent 5:30pm and 8pm Beijing time on May 3, 2004, it can be written as 2004 05-03T17:30:08+08:00 or 20040503T093008+08.

Time period representation

  If you want to represent a certain time period as a period of time, add a capital letter P before it, but add the corresponding capital letter representing time after the time period. If it takes three months, five days, six hours, seven minutes, and thirty seconds in a year, it can be written as P1Y3M5DT6H7M30S.

Repetitive time representation

  Add a capital letter R before it. If you want to repeat for six months, five days, and three hours starting from 1 pm Beijing time on May 6, 2004, you need to repeat it three times, which can be expressed as R3/20040506T130000+08/P0Y6M5DT3H0M0S.

http Request Signature

Authentication Significance

When the BBU device interacts with the management end through the HTTP interface, the requested authentication is required The significance of authentication for the server lies in the following points:   1.Which account initiated the request   2.Avoiding requests being intercepted by third parties and conducting replay attacks   3.Avoiding requests from being tampered with by third parties The authentication mechanism refers to the OAuth1.0a protocol

Authentication Method

OAuth Request Header

The client must carry the following 6 headers when accessing the server API   1.OAuth-Version:The version number of the authentication protocol, currently version 1.0   2.OAuth-Token:The management side determines which device initiated the request, and this field is the token field returned by the login interface   3.OAuth-Nonce:Used to prevent replay attacks on the management end after third-party interception of user initiated requests. This field needs to be generated by the client at the time of each request and must ensure the uniqueness of each generation. It is recommended that users use the uuid library to generate it   4.OAuth-Timestamp:Used to indicate the time point at which the request was generated. This value needs to be set to the Unix timestamp (in seconds) at the time the request was initiated. The management side will reject old requests, so it is necessary to ensure clock synchronization between the client and server as much as possible   5.OAuth-Signature:This field is generated based on the HTTP request parameters and user key using the signature method specified by OAuth Signature Method. It is used by the management side to determine whether the request has been tampered with. Please refer to the signature mechanism section for the generation method   6.OAuth-Signature-Method:A signature method for generating OAuth Signature

key user_secret

Obtain the corresponding secret from the docking platform

Signature Mechanism

We need the following information for signature

http header required uniqued illustrate Key Value(Demo)
HTTP Method yes yes HTTP request method with all uppercase characters GET/POST/PUT/DELETE method POST
HTTP URL yes yes The requested HTTP address does not include URL request parameters url https://api.megvii-inc.com/login
HTTP URL Request parameters no no The request parameters added to the URL, if there are no URL request parameters, default to
For example, visitinghttps://api.megvii-inc.com?query_string_a=query_string_a_value&query_string_b=query_string_b_value
Resolve these two key value pairs, which arequery_string_a -> query_string_a_value, query_string_b -> query_string_b_value
query_string_a
query_string_b
query_string_a_value
query_string_b_value
Text based HTTP form parameters no no Request textual parameters for the form interface of the form form_string_a
form_string_b
form_string_a_value
form_string_b_value
File based HTTP form parameters no no Request the file type parameter of the form interface. Due to the relatively large file data, value is the md5 verification value of the file data form_file_a
form_file_b
md5(form_file_a_data)
md5(form_file_b_data)
HTTP POST request body no yes The HTTP request body of a non form interface, as the request body data may be large, value is the md5 verification value of the request body data body md5(request_body_data)
OAuth-Version yes yes Explanation in the reference authentication method OAuth-Version 1.0
OAuth-Nonce yes yes Explanation in the reference authentication method OAuth-Nonce kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg
OAuth-Timestamp yes yes Explanation in the reference authentication method OAuth-Timestamp 1574391078
OAuth-Token yes yes Explanation in the reference authentication method OAuth-Token GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb
OAuth-SignatureMethod yes yes Explanation in the reference authentication method OAuth-SignatureMethod SHA1
user_secret yes yes Explanation in the reference authentication method user_secret kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw
Generation Steps

1. All data involved in the signature defaults to UTF-8 encoding 2. All keys are sorted in ascending dictionary order after URL encoding (duplicate key values are not allowed) to generate keys_ List key_list = ['OAuth-Nonce', 'OAuth-Signature-Method', 'OAuth-Timestamp', 'OAuth-Token', 'OAuth-Version', 'body', 'form_file_a', 'form_file_b', 'form_string_a', 'form_string_b', 'method', 'query_string_a', 'query_string_b', 'url', 'user_secret']

3. Generate a string to be signed signature_str a. Define an empty string signature_str b. ergodic key_list, For each value, do the following   i. Encode the key value with a URL and concatenate it into the signature_ Str tail   ii. signature_str Add the '=' character at the end   iii. URL encoding the value value corresponding to the key value, And then concatenated to the signature_ Str tail   iv. signature_str Add '&' character at the end c. delete signature_str The '&' character at the end d. The final concatenated signature_ Str is as follows: signature_str = "OAuth-Nonce=kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg&OAuth-SignatureMethod=SHA1&OAuth-Timestamp=1574391078&OAuth-Token=GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb&OAuthVersion=1.0&body=md5%28request_body_data%29&form_file_a=md5%28form_file_a_data%29&form_file_b=md5% 28form_file_b_data% 29&form_string_a=form_string_a_value&form_string_b=form_string_b_value&method=POST&query_string_a=q uery_string_a_value&query_string_b=query_string_b_value&url=https%3A%2F%2Fapi.megvii-inc.com% 2Flogin&user_secret=kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw"

4. Use the method specified by OAuth-Signature-Method to modify the signature_ Str calculates the signature and generates binary data as the result 5. Perform base64 encoding on binary data to obtain the OAuth-Signature field as follows: signature = "1rAcfHg7uRRPr+KxmeaA0SphkDQ="

6. python The example code is as follows:))