//curl請求
function http_request($url,$headers = array(),$data = null)
{
$curl = curl_init();
if (count($headers) >= 1) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
示例
$sUrl = "http://open-api.shuyun.com";
$param = array(
'cardPlanId' => '3988',
'memberId' => '1515151',
'fields' => 'cardPlanId,memberId',
);
$sUrl .= "?".http_build_query($param);
// echo $sUrl;return;
$sign = MD5($secret.'cardPlanId'.$param['cardPlanId'].'Gateway-Request-Time'.$time.'memberId'.$param['memberId'].'fields'.$param['fields'].$secret);
$header = array(
'Gateway-Authid:'.$appId,//申請的appId
'Gateway-Request-Time:'. $time,//前請求時間,服務端會驗證該時間,需要±2min以內的日期
'Gateway-Sign:'.$sign,
'Gateway-Action-Method:shuyun.loyalty.member.detail.query',//接口名稱
'Gateway-Access-Token:'.$token,
);
//請求地址
$sResult = $this->http_request($sUrl, $header,'');
$aResData = json_decode($sResult, true);
//顯示返回數據
echo "<pre>";
print_r($aResData);
//HTTP請求(支持HTTP/HTTPS,支持GET/POST)
private function http_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
file_put_contents('/tmp/heka_weixin.' . date("Ymd") . '.log', date('Y-m-d H:i:s') . "\t" . $output . "\n", FILE_APPEND);
return $output;
}