


PHP generates the relevant content of the request signature required by Tencent Cloud COS interface
This article mainly introduces the request signature required to create a COS interface using PHP. It is compared with the examples given in the official documents to verify the correctness of the algorithm. Friends in need can refer to it
What is COS and request signature
COS is the abbreviation and abbreviation of Tencent Cloud Object Storage. The request signature is created by a specific algorithm and needs to be provided by a third party on demand when calling COS related interfaces. A set of string information that will uniquely identify the current third-party identity and provide identification of both communicating parties. Only valid signed COS will provide services
Goal
Use PHP to create the request signature required for the COS interface, compare it with the example given in the official document, and verify the correctness of the algorithm
Understand the request signature
Come first Look at the request signature given in an official document
q-sign-algorithm=sha1&q-ak=[SecretID]&q-sign-time=[SignTime]&q-key-time=[KeyTime ]&q-header-list=[SignedHeaderList]&q-url-param-list=[SignedParameterList]&q-signature=[Signature]
Request signature feature summary
-
is a key-value pair format of a string
key=value, the key is a fixed value
There are 7 pairs of keys in total =value
sha1 is also a parameter, but as of the official release, only sha1 is supported, so you can directly assign values to
SignedHeaderList, SignedParameterList, and Signature. value needs to be generated through an algorithm
For detailed description of key-value pairs, please refer to the official documentation.
Breakdown one by one
Requesting a signature requires a total of 7 values. Let’s explain one by one below and break each one
q-sign-algorithm
Signature algorithm, official Currently only sha1 is supported, so just give the value directly
q-ak
The account ID, which is the user's SecretId, can be obtained on the console Cloud API Key page
q-sign-time
The valid start and end time of the current signature, Unix timestamp format, English half-width semicolon; separated, format such as 1480932292;1481012298
q-key-time
Same as q-sign-time value
q-header-list
Personal understanding, it consists of HTTP request headers, take all or part of the request headers, and change the request in the form of key:value The key part of the item is taken out, converted to lowercase, multiple keys are sorted according to the dictionary, and connected with the characters ; to finally form a string
For example, the original request header has two:
Host: bucket1-1254000000.cos.ap-beijing.myqcloud.com
Content-Type:image/jpeg
key is Host and Content-Type. After operation, content-type;host# is output.
##q-url-param-listPersonal understanding, it consists of HTTP request parameters, take all or part of the request parameters, take out the key part of the request parameter in the form of key=value, and convert it to lowercase. Multiple keys are sorted by dictionary, connected by characters ;, and finally formed into a string For example, the original HTTP request is:GET /?prefix=abc&max-keys=20key is prefix and max-keys. After operation, max-keys;prefix is output. If the request has no parameters such as put and post, it will be empty.q-signature
Calculate the signature based on the HTTP content. The algorithm is provided by COS. Just give the value as requiredOfficial examples and reference resultsBefore starting to write logic, take a look at the official examples. The reference value, as well as the calculated result, in order to compare the result with the logic developed by yourselfHTTP original request can also be understood as the HTTP request before calculating the signature or when no signature is required:
PUT /testfile2 HTTP/1.1The HTTP request you should get after calculating the signature:Host: bucket1-1254000000.cos.ap-beijing.myqcloud.com
Hello world
x-cos-content-sha1: 7b502c3a1f48c8609ae212cdfb639dee39673f5e
x-cos-storage -class: standard
PUT /testfile2 HTTP/1.1
Host: bucket1-1254000000.cos.ap-beijing.myqcloud.com
x-cos-content-sha1: 7b502c3a1f48c8609ae212cdfb639dee39673f5e
x-cos-storage -class: standard
Authorization: q-sign-algorithm=sha1&q-ak=AKIDQjz3ltompVjBni5LitkWHFlFpwkn9U5q&> q-sign-time=1417773892;1417853898&q-key-time=1417773892;1417853898&q-header-list =host;x-cos-content -sha1;x-cos-storage-class&q-url-param-list=&q-signature=14e6ebd7955b0c6da532151bf97045e2c5a64e10Hello world
Conclusion: If the algorithm can get the one after Authorization The string string is correct
Preparation work
Let’s take a look at the (officially provided) user information and HTTP information:
- ##SecretId: AKIDQjz3ltompVjBni5LitkWHFlFpwkn9U5q
- SecretKey: BQYIM75p8x0iWVFSIgqEKwFprpRSVHlz
- Signature valid start time: 1417773892
- Signature valid stop time: 1417853898
- HTTP original request header: According to the example in the previous section, it is not difficult to get that the HTTP original request has three contents: Host, x-cos-content-sha1 and x-cos-storage-class
- HTTP request parameters: Is it a PUT request, no? Parameters
Value(value) | Remark | |
---|---|---|
sha1 | Currently only supported sha1 signature algorithm | |
AKIDQjz3ltompVjBni5LitkWHFlFpwkn9U5q | SecretId field | |
1417773892;1417853898 | 2014/12/5 18:04:52 to 2014/12/6 16:18:18 | |
1417773892;1417853898 | 2014/12/5 18:04:52 to 2014/12/6 16:18:18 | |
host;x-cos-content-sha1;x-cos-storage-class | lexicographically sorted list of HTTP header keys | |
HTTP parameter list is empty |
||
14e6ebd7955b0c6da532151bf97045e2c5a64e10 | Calculated by code |
The above is the detailed content of PHP generates the relevant content of the request signature required by Tencent Cloud COS interface. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Altius, a crypto startup, recently announced a $11 million financing round led by FoundersFund and Pantera Capital. It is remarkable that Altius only posted one tweet before the announcement of the financing news, which added a sense of mystery to it. What exactly attracts top venture capital institutions such as Pantera Capital? The answer lies in Altius' innovative reshaping of the blockchain execution layer. Altius is not a traditional single public chain project. It is committed to building a modular, plug-and-play execution layer solution - AltiusStack. This solution can be seamlessly integrated with any public chain using virtual machine (VM) mechanism

Signs of recovery in the NFT market! Mocaverse floor price soared, with a 24-hour increase of up to 79%. According to OpenSea data, the floor price of the well-known NFT project Mocaverse has recently exceeded 2.9ETH, and the current price is 2.96ETH (approximately US$11,860), with an astonishing 24-hour increase of 79%, reaching a maximum of 3.49ETH. This significant growth has attracted widespread attention from the market. Will the NFT market return to its bull market? Mocaverse Floor Price Chart NFT sector leads the crypto market Coingecko data shows that the overall crypto market has risen in the past 24 hours, while the NFT sector tops the list with an increase of 8.53%. Some projects are particularly good

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

Configure the apscheduler timing task as a service on macOS platform, if you want to configure the apscheduler timing task as a service, similar to ngin...
