获取接口数据
<?PHP
header('content-type:text/html;charset=utf-8');
$url = "********************************";//接口访问地址
$uname = '************';//账号
$pass = '*****************';//密钥
$goodid= '201504302011356399';//商品ID
$sign = md5(md5("goodid=$goodid&method=product_info&pass=$pass&uname=$uname").$pass);
var_dump(md5("goodid=$goodid&method=product_info&pass=$pass&uname=$uname"));//设置签名
/*获取接口数据*/
$post_data = array (
"uname" => $uname,
"pass" => $pass,
"sign" => $sign,
"method" => 'product_info',
"goodid" => $goodid,
);
$ch = curl_init();//初始化链接句柄
curl_setopt($ch, CURLOPT_URL, $url);//请求的url地址
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
$output = curl_exec($ch);//执行并获取html文档内容
$contents = curl_multi_getcontent($ch);
curl_close($ch);//释放curl句柄
$jiekouList = json_decode($output);
var_dump($jiekouList);
$jkList = $jiekouList->list;
//var_dump($jiekouList);
/**
* [std_class_object_to_array 将对象数组转成普通数组]
* @param [stdclass] $stdclassobject [对象]
* @return [array] [数组]
*/
function std_class_object_to_array($stdclassobject){
$_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject;
foreach ($_array as $key => $value) {
$value = ((is_array($value) || is_object($value))) ? std_class_object_to_array($value) : $value;
$array[$key] = $value;
}
return $array;
}
$jkList = std_class_object_to_array($jkList);
// var_dump($jkList);
$contents = std_class_object_to_array(json_decode($contents));
$img = $jkList['subjectimage'];
echo "<img src='img.php?img=".$img."'>";
chu
处理图片文件
<?PHP
header('Content-type: image/JPEG');
$img=$_GET['img'];
// $header = array(
// //'Host: p0.coolshow.net',
// //'Connection: keep-alive',
// //'Cache-Control: max-age=0',
// //'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
// //'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
// //'Accept-Encoding: gzip, deflate, sdch',
// //'Accept-Language: zh-CN,zh;q=0.8'
// );
$ch = curl_init();//初始化链接句柄
curl_setopt($ch, CURLOPT_URL, $img);//请求的url地址
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_HEADER, 0); //设置获取的信息以文件流的形式返回,而不是直接输出。
$output = curl_exec($ch);//执行并获取html文档内容
$contents = curl_multi_getcontent($ch);
curl_close($ch);//释放curl句柄
echo $contents;