Home  >  Article  >  Backend Development  >  How to request interface with token in php

How to request interface with token in php

(*-*)浩
(*-*)浩Original
2019-09-30 14:28:504100browse

How to request interface with token in php

PHP Token(Token)

Token means "token", which is a string of characters generated by the server. An identifier for the client to make the request.

In view of the above characteristics, communication between the mobile terminal and the server requires 2 keys, that is, 2 tokens. (Recommended learning: PHP video tutorial)

The first token is for the interface (api_token);

The second token is for the user (user_token);

Let’s talk about the first token (api_token) first

Its responsibility is to maintain the concealment and effectiveness of interface access and ensure that the interface can only be used by one’s own family. How?

The reference idea is as follows:

Generate a random string based on the common attributes owned by the server and the client. The client generates this string, and the server also generates it according to the same algorithm. A string used to verify the client's string.

The current interface is basically MVC mode, and the URL is basically restful style. The general format of the URL is as follows:

http://blog.snsgou.com/模块名/控制器名/方法名?参数名1=参数值1&参数名2=参数值2&参数名3=参数值3

The interface token generation rules are as follows:

api_token = md5 ('模块名' + '控制器名' + '方法名' + '2013-12-18' + '加密密钥') = 770fed4ca2aabd20ae9a5dd774711de2

1. '2013-12-18' is the time of the day

2. 'Encryption key' is private Encryption key. After the mobile phone needs to register an "Interface User" account on the server, the system will assign an account and password. The data table design reference is as follows:

Field Name Field Type Comment

client_id varchar(20) Client ID

client_secret varchar(20) Client (encryption) key

Server interface verification, PHP implementation process is as follows:

The above is the detailed content of How to request interface with token in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn