Home  >  Article  >  Backend Development  >  这种怎么完整写出来求大神指教

这种怎么完整写出来求大神指教

WBOY
WBOYOriginal
2016-06-13 12:00:44795browse

这种如何完整写出来求大神指教
这种一般是双方约定一个key,然后md5后传过去验证
例:
发送方:
$key='123456789';//双方约定并保密
$time = time();
$token = md5($key.$time);
 file_get_contents("www.baidu.com/api/api.php?time=".$time."&token=".token);

接收方:
$time = $_GET['time'];
$token= $_GET['token'];
$key = '123456789';//与上面保持一样
if( md5($key.$time) == $token )
{ echo "true"; }
else{ echo "false"; }

怎么写服务端和客户端求大神写范例
------解决方案--------------------
client.php


$key='123456789';//双方约定并保密
$time = time();
$token = md5($key.$time);
$data = file_get_contents("http://www.baidu.com/api/api.php?time=".$time."&token=".$token);
$result = json_decode($data, true);

if($result['success']){
echo 'success';
}else{
echo 'fail';
}


api.php

$time = isset($_GET['time'])? $_GET['time'] : '';
$token= isset($_GET['token'])? $_GET['token'] : '';
$key = '123456789';//与上面保持一样

$ret = array();

if(md5($key.$time)==$token){
$ret['success'] = true;
}else{
$ret['success'] = false;
}

header('content-type:application/json;charset=utf8');

echo json_encode($ret);

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