<?php
header("Content-Type:text/html;charset=UTF-8");
/**
* 手机服务端体系
* 入口文件 mclientapi.php
* 所有其他文件位置
* mclientapi
* api 前端直接跟这个下面的文件通信
* library 各种库
* update.xml 版本说明文件
*/
/**
* 签名算法
*
* @param
unknown_type $action 对应
* @param
unknown_type $params 参数
* @return unknown
*/
function sign($action, $params) {
global $apikey;
$arg = 'callback=' . $action . '¶ms=' . $params;
$sign = md5($arg . '&' . $apikey);
return $sign;
}
$apikey
= '3ef80953238309268588094e7741gg'; //通信密钥
$host = 'http://www.bbs.com/phpwind87'; //手机端地址
$threadarray
= array(// action 对应/mclientapi/api/thread.class.php 里面的getcomments 方法
'thread.getcomments'
=>
array('params' => '["244800","0","20","1"]', //请求参数
'type' => 'get')//请求方法[GET/POST] /mclientapi/api/ 下面文件的 $methodsType 有说明调用的方法 ,默认GET
);
foreach ($threadarray as $action => $params) {
$sign = sign($action, $params['params']);
$url = $host . 'mclientapi.php?callback=' . $action . '¶ms=' . $params['params'] . '&sign=' . $sign;
echo $url . "\n";
$content = file_get_contents($url);
if ($params['type'] == 'post') {
$content = request($url,array('wuyong'=>1)); //请
} else {
$content = file_get_contents($url);
}
//echo $content;
$content = json_decode($content);
print_r($content);
}
function post($url, $post = null) {
$context = array();
if (is_array($post)) {
ksort($post);
$context['http'] = array(
'timeout' => 60, 'method' => 'POST', 'header' => "Content-type:
application/x-www-form-urlencoded\r\n" . "Content-length:" . strlen($data) . "\r\n" . "Cookie: foo=bar\r\n" . "\r\n", 'content' => http_build_query($post, '', '&'));
}
return file_get_contents($url, false, stream_context_create($context));