|
@@ -324,36 +324,52 @@ class Shop extends Start_Controller {
|
|
{
|
|
{
|
|
header('Location:'.$setting['code'].'?response_type=code&client_id='.$setting['appkey'].'&redirect_uri='.'http://'.$_SERVER['HTTP_HOST'].'/shop/code'.'&state='.$arg_array[0].'&view=web&sp=ae');exit;
|
|
header('Location:'.$setting['code'].'?response_type=code&client_id='.$setting['appkey'].'&redirect_uri='.'http://'.$_SERVER['HTTP_HOST'].'/shop/code'.'&state='.$arg_array[0].'&view=web&sp=ae');exit;
|
|
}
|
|
}
|
|
- $code = $_GET['code'];
|
|
|
|
- $url = $setting['token'];
|
|
|
|
- $postfields= array('grant_type'=>'authorization_code',
|
|
|
|
- 'client_id'=>$setting['appkey'],
|
|
|
|
- 'client_secret'=>$setting['secret'],
|
|
|
|
- 'code'=>$_GET['code'],
|
|
|
|
- 'sp'=>'ae',
|
|
|
|
- 'redirect_uri'=>'http://'.$_SERVER['HTTP_HOST'].'/shop/code');
|
|
|
|
- $post_data = '';
|
|
|
|
- foreach($postfields as $key=>$value){
|
|
|
|
- $post_data .="$key=".urlencode($value)."&";}
|
|
|
|
-
|
|
|
|
|
|
|
|
- $url = 'http://39.100.97.180/smt.php';
|
|
|
|
|
|
+ $code = $_GET['code'];
|
|
|
|
+ $time = (int)time()."000";
|
|
|
|
+ $params = [
|
|
|
|
+ "app_key" =>$setting['appkey'],
|
|
|
|
+ "code" => $code,
|
|
|
|
+ "sign_method" =>"sha256",
|
|
|
|
+ "simplify" => "true",
|
|
|
|
+ "timestamp" => $time
|
|
|
|
+ ];
|
|
|
|
+ $sign = $this->signApiRequest($params, $setting['secret'], 'sha256','/auth/token/create');
|
|
|
|
+ $url = "http://api-sg.aliexpress.com/rest/auth/token/create";
|
|
|
|
+
|
|
|
|
+ $params['sign'] = $sign;
|
|
|
|
+ echo "<pre>";
|
|
|
|
+ print_r($params);
|
|
|
|
+
|
|
|
|
+ $headerA = [
|
|
|
|
+ "Content-Type: application/json;;charset=utf-8",
|
|
|
|
+ ];
|
|
$ch = curl_init();
|
|
$ch = curl_init();
|
|
- curl_setopt($ch,CURLOPT_URL,$url);
|
|
|
|
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
|
|
|
|
- curl_setopt($ch,CURLOPT_HEADER,0);
|
|
|
|
- curl_setopt($ch,CURLOPT_POST, 1);
|
|
|
|
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
|
|
|
|
- //设置post数据
|
|
|
|
- $post = array();
|
|
|
|
- $post['get_token_by_code'] = 1;
|
|
|
|
- $post['code'] = $code;
|
|
|
|
- var_dump($post);
|
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
|
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
|
|
|
|
+ curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
|
+ curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
|
+ //指定post数据
|
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
+ //添加变量
|
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)) ;
|
|
$output = curl_exec($ch);
|
|
$output = curl_exec($ch);
|
|
- curl_close($ch);
|
|
|
|
|
|
+ $output = json_decode($output,true);
|
|
|
|
+ print_r($output);
|
|
|
|
|
|
|
|
|
|
|
|
+ // $code = $_GET['code'];
|
|
|
|
+ // $url = $setting['token'];
|
|
|
|
+ // $postfields= array('grant_type'=>'authorization_code',
|
|
|
|
+ // 'client_id'=>$setting['appkey'],
|
|
|
|
+ // 'client_secret'=>$setting['secret'],
|
|
|
|
+ // 'code'=>$_GET['code'],
|
|
|
|
+ // 'sp'=>'ae',
|
|
|
|
+ // 'redirect_uri'=>'http://'.$_SERVER['HTTP_HOST'].'/shop/code');
|
|
|
|
+ // $post_data = '';
|
|
|
|
+ // foreach($postfields as $key=>$value){
|
|
|
|
+ // $post_data .="$key=".urlencode($value)."&";}
|
|
// $ch = curl_init();
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_URL, $url);
|
|
// curl_setopt($ch, CURLOPT_URL, $url);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
@@ -364,14 +380,45 @@ class Shop extends Start_Controller {
|
|
// //添加变量
|
|
// //添加变量
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data,0,-1));
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data,0,-1));
|
|
// $output = curl_exec($ch);
|
|
// $output = curl_exec($ch);
|
|
- $output = json_decode($output,true);
|
|
|
|
- echo "<pre>";
|
|
|
|
- print_r($output);
|
|
|
|
- die;
|
|
|
|
- $this->shop->save(array('code'=>$output["access_token"],'codetime'=>substr($output["expire_time"],0,10)),$_GET['state']);
|
|
|
|
- header('Location:http://'.$_SERVER['HTTP_HOST'].'/user/');exit;
|
|
|
|
|
|
+ // $output = json_decode($output,true);
|
|
|
|
+ // print_r($output);
|
|
|
|
+ // $this->shop->save(array('code'=>$output["access_token"],'codetime'=>substr($output["expire_time"],0,10)),$_GET['state']);
|
|
|
|
+ // header('Location:http://'.$_SERVER['HTTP_HOST'].'/user/');exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function signApiRequest($params, $appSecret, $signMethod, $apiName) {
|
|
|
|
+ // 对参数键名进行排序
|
|
|
|
+ $keys = array_keys($params);
|
|
|
|
+ sort($keys);
|
|
|
|
+
|
|
|
|
+ // 拼接基础字符串:先添加 API 名称
|
|
|
|
+ $query = $apiName;
|
|
|
|
+
|
|
|
|
+ // 遍历排序后的键值对
|
|
|
|
+ foreach ($keys as $key) {
|
|
|
|
+ $value = $params[$key];
|
|
|
|
+ $query .= $key . $value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 使用指定方法签名
|
|
|
|
+ $bytes = null;
|
|
|
|
+ if ($signMethod === 'sha256') {
|
|
|
|
+ $bytes = $this->encryptHMACSHA256($query, $appSecret);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 转换为大写HEX字符串
|
|
|
|
+ return $this->byte2hex($bytes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function encryptHMACSHA256($data, $secret) {
|
|
|
|
+ var_dump($data);
|
|
|
|
+ return hash_hmac('sha256', $data, $secret, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function byte2hex($bytes) {
|
|
|
|
+ $hex = bin2hex($bytes);
|
|
|
|
+ return strtoupper($hex);
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|