首页 > 代码库 > CURL
CURL
//-----登录要提交的表单数据---------------
$time = time();
$hash = hash_hmac(‘sha1‘,"appKey=KEY×tamp=$time",‘密钥‘);
$vars[‘appKey‘] = ‘Appkey‘;
$vars[‘appSignature‘] = $hash;
$vars[‘grantType‘] = ‘authorization_code‘;
$vars[‘timestamp‘] = $time;
$method_post = true;
//登录提交的url地址(表单中的action的绝对地址)
$url = ‘http://cloud.189.cn/open/oauth2/accessToken.action‘;
//----------------------------
$ch = curl_init();
$params[CURLOPT_URL] = $url; //请求url地址
$params[CURLOPT_HEADER] = false; //是否返回响应头信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$params[CURLOPT_USERAGENT] = ‘Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1‘;
$postfields = ‘‘;
foreach ($vars as $key => $value){
$postfields .= urlencode($key) . ‘=‘ . urlencode($value) . ‘&‘;
}
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $postfields;
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
$content = json_decode($content,true); //输出登录结果
/*
//---------登录成功后再次请求其他地址,如果有多个可以循环执行---------
echo ‘
‘;
$nexturl = ‘http://****.com/test‘;
$params[CURLOPT_URL] = $nexturl;
$params[CURLOPT_POSTFIELDS] = ‘‘;
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
echo $content; //输出请求结果
//-------------------------------------------------
*/
curl_close($ch); //关闭连接
#./GooCalendar/codebase/jquery-1.3.2.min.js
CURL