获取数据
<?php header("Content-Type:text/html;charset=UTF-8"); require_once 'util.php'; $appKey = 'test'; $appSecret = 'test'; $sessionkey= 'test'; //参数数组 $paramArr = array( 'app_key' => $appKey, 'session_key' => $sessionkey, 'method' => 'taobao.user.seller.get', 'format' => 'json', 'v' => '2.0', 'sign_method'=>'md5', 'timestamp' => date('Y-m-d H:i:s'), 'fields' => 'nick,type,user_id', // 'nick' => 'sandbox_c_1' ); //生成签名 $sign = createSign($paramArr); //组织参数 $strParam = createStrParam($paramArr); $strParam .= 'sign='.$sign; //访问服务 $url = 'http://gw.api.tbsandbox.com/router/rest?'.$strParam; //沙箱环境调用地址 $result = file_get_contents($url); $result = json_decode($result); echo "json的结构为:"; print_r($result); echo "<br>"; echo "用户名称为:".$result->user_get_response->user->nick; echo "<br>"; echo "买家信用等级为:".$result->user_get_response->user->buyer_credit->level; ?> |
Util类
<?php //签名函数 function createSign ($paramArr) { global $appSecret; $sign = $appSecret; ksort($paramArr); foreach ($paramArr as $key => $val) { if ($key != '' && $val != '') { $sign .= $key.$val; } } $sign.=$appSecret; $sign = strtoupper(md5($sign)); return $sign; } //组参函数 function createStrParam ($paramArr) { $strParam = ''; foreach ($paramArr as $key => $val) { if ($key != '' && $val != '') { $strParam .= $key.'='.urlencode($val).'&'; } } return $strParam; } ?> |