|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
|
namespace app\api\controller;
|
|
|
-class Kuaishou
|
|
|
+class Kuaishou extends Base
|
|
|
{
|
|
|
public $appKey = 'ks698620896473026758';
|
|
|
public $appSecret = 'cvbOgiVC6rSvPs0sBASfkg';
|
|
@@ -11,11 +11,114 @@ class Kuaishou
|
|
|
public $webSite = '1688';
|
|
|
public $access_token = '';
|
|
|
public $debug = false;
|
|
|
+
|
|
|
+ public static function getAccessToken()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function apiPost()
|
|
|
+ {
|
|
|
+ $apiType = "open.item.list.get";
|
|
|
+ $method = 'get';
|
|
|
+ $param = input('post.param');
|
|
|
+ $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);
|
|
|
+ $this->success('ok',$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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static function getMillisecond() {
|
|
|
+ list($t1, $t2) = explode(' ', microtime());
|
|
|
+ return sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
+class Alibabahelper {
|
|
|
+ function __construct() {
|
|
|
+ }
|
|
|
+ private function curl_get_contents($url, $data = array(), $https = false) {
|
|
|
+ $results['error'] = '';
|
|
|
+ $results['status'] = 0;
|
|
|
+ $results['data'] = array();
|
|
|
+ $user_agent = $_SERVER['HTTP_USER_AGENT'];
|
|
|
+ $curl = curl_init();
|
|
|
+ if (!empty($data) && is_array($data)) {
|
|
|
+ curl_setopt($curl, CURLOPT_POST, TRUE);
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
|
|
|
+ }
|
|
|
+ if ($https) {
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
|
|
|
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
|
|
|
+
|
|
|
+ }
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);
|
|
|
+ curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
|
|
|
+ $results['data'] = curl_exec($curl);
|
|
|
+ if (curl_errno($curl)) {
|
|
|
+ $results['error'] = curl_error($curl);
|
|
|
|
|
|
+ }
|
|
|
+ curl_close($curl);
|
|
|
+ return $results['data'];
|
|
|
+
|
|
|
+ }
|
|
|
+ public function curl_https_post($url, $data) {
|
|
|
+ return $this->curl_get_contents($url, $data, true);
|
|
|
+ }
|
|
|
+ public function curl_https_get($url) {
|
|
|
+ return $this->curl_get_contents($url, array(), true);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
|