1
2
3
|
client_id varchar(20) 客户端ID client_secret varchar(20) 客户端(加密)密钥 |
<?php //获取GET参数值 $module = $_GET[‘module‘]; $controller = $_GET[‘controller‘] $action = $_GET[‘action‘]; $client_id = $_GET[‘client_id‘]; $api_token = $_GET[‘‘api_token]; //根据客户端传过来的client_id,查询数据库,获取对应的client_secret $client_secret = getClientSecret($client_id); //服务端重新生成一个api_token $api_token_server = md5($module . $controller . $action . date(‘Y-m-d‘, time()) . $client_secret); //客户端传过来的api_token与服务端生成的api_token进行校对,如果不相等,则表示验证失败 if ($api_token != $api_token_server) { exit(‘access deny‘); //拒绝访问 } //验证通过,返回数据给客户端 ?>
1
2
3
4
5
|
user_id int(11) 用户ID user_token varchar(36) 用户token expire_time int 过期时间(Unix时间戳) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
URL: http: //www.api.com/demo/index/add-demo?client_id=wt373uesksklwkskx36sr5858t6&api_token=880fed4ca2aabd20ae9eessa74711de2&user_token=etye0fgkgk4ca2asehxlejeje5dd77471fgf&user_id=12 请求方式: POST POST参数:title=哈喽&content=我的世界 返回数据: { ‘code‘ => 1, // 1:成功 0:失败 ‘msg‘ => ‘成功/失败,无权访问‘ ‘data‘ => [] } |
原文:https://www.cnblogs.com/applelife/p/11344348.html