appKey = $appKey = 'appKey '; $Kwaixiaodian->appSecret = $appSecret = 'appSecret '; $Kwaixiaodian->signSecret = 'signSecret '; $Kwaixiaodian->debug = 1;; $Kwaixiaodian->access_token = 'access_token'; $arr = $Kwaixiaodian->api('open.item.list.get', array()); //$arr =$Kwaixiaodian->api('open.user.seller.get',array()); echo '
'; print_r($arr); echo ''; class Kwaixiaodian { public $appKey; public $appSecret; public $signSecret; public $syncAPIClient; public $serverHost = "https://open.kwaixiaodian.com/"; public $webSite = '1688'; public $access_token = ''; public $debug = false; public function Api($apiType, $param, $method = 'get') { $arr['appkey'] = $this->appKey; $arr['version'] = '1'; $arr['access_token'] = $this->access_token; $arr['timestamp'] = $this->getMillisecond(); $arr['method'] = trim($apiType); $arr['param'] = $param ? json_encode($param) : '{}'; $arr['signMethod'] = 'MD5'; ksort($arr); // 排序 $arr['sign'] = $this->getSign($arr, $this->signSecret); $apiInfo = str_replace('.', '/', $arr['method']); $url = $this->serverHost . $apiInfo; $Alibabahelper = new Alibabahelper(); if ($method == 'get') { $s = $Alibabahelper->curl_https_get($url. '?' . http_build_query($arr, '', '&'), array()); } else { $s = $Alibabahelper->curl_https_post($url, $arr); } $s = json_decode($s, true); return $s; } public function getSign($params, $key) { $unSignParaString = $this->formatQueryParaMap($params, false); $signStr = (md5($unSignParaString . "&signSecret=" . $this->signSecret)); return $signStr; } public function formatQueryParaMap(array $paraMap, $urlEncode = false) { $buff = ""; ksort($paraMap); foreach ($paraMap as $k => $v) { if (null != $v && "null" != $v) { if ($urlEncode) { $v = urlencode($v); } $buff.= $k . "=" . $v . "&"; } } $reqPar = ''; if (strlen($buff) > 0) { $reqPar = substr($buff, 0, strlen($buff) - 1); } return $reqPar; } /*获取13位时间戳*/ private static function getMillisecond() { list($t1, $t2) = explode(' ', microtime()); return sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); } public function getAPIClient($redirectUrl,$scope='merchant_comment,merchant_item,merchant_logistics,merchant_order,merchant_servicemarket,merchant_user,user_info') { $get_code_url = $this->serverHost . "oauth2/connect?app_id={$this->appKey}&scope={$scope}&response_type=code&redirect_uri={$redirectUrl}&state=your_state"; return $get_code_url; } public function getToken($code, $redirectUrl = '') { $url = $this->serverHost . "oauth2/access_token?app_id={$this->appKey}&app_secret={$this->appSecret}&code={$code}&grant_type=authorization_code"; $Alibabahelper = new Alibabahelper(); $s = $Alibabahelper->curl_https_get($url); $s = json_decode($s, true); return $s; } /*用长时令牌refreshToken刷新访问令牌accessToken*/ public function refreshToken($refreshToken) { $url = $this->serverHost . "oauth2/refresh_token?app_id={$this->appKey}&app_secret={$this->appSecret}&refresh_token={$refreshToken}&grant_type=refresh_token"; $Alibabahelper = new Alibabahelper(); $s = $Alibabahelper->curl_https_get($url); $s = json_decode($s, true); return $s; } function debug($msg) { if ($this->debug) { print '
"; print_r($msg); echo ""; print '