Browse Source

提交速卖通的api

lvhao 6 ngày trước cách đây
mục cha
commit
0e26590220
2 tập tin đã thay đổi với 63 bổ sung29 xóa
  1. 34 29
      core/CoreApp/controllers/Shop.php
  2. 29 0
      core/CoreApp/models/Model_apismt.php

+ 34 - 29
core/CoreApp/controllers/Shop.php

@@ -9,6 +9,7 @@ class Shop extends Start_Controller {
 		$this->load->_model('Model_warehouse','warehouse');
 		$this->load->_model('Model_productprice','productprice');
 		$this->load->_model('Model_apiyy','apiyy');
+		$this->load->_model('Model_apismt','apismt');
 	}
 	//定义方法的调用规则 获取URI第二段值
     public function _remap($arg,$arg_array)
@@ -342,37 +343,41 @@ class Shop extends Start_Controller {
 			}
 
 			$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;
+			$res = $this->apismt->getAccessToken($code);
 			echo "<pre>";
-			print_r($params);
+			print_r($res);
+			// $setting['appkey'] = '26004389';
+			// $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";
 			
-			$headerA = [
-				"Content-Type: application/json;;charset=utf-8",
-			];
-			$ch = curl_init();
-			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 = json_decode($output,true);
-			print_r($output);
+			// $params['sign'] = $sign;
+			// echo "<pre>";
+			// print_r($params);
+			
+			// $headerA = [
+			// 	"Content-Type: application/json;;charset=utf-8",
+			// ];
+			// $ch = curl_init();
+			// 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 = json_decode($output,true);
+			// print_r($output);
 
 
 			// $code = $_GET['code'];

+ 29 - 0
core/CoreApp/models/Model_apismt.php

@@ -583,4 +583,33 @@ function __construct(){
     return urlencode(base64_encode(md5($data.$appkey)));
     }
 	//快递鸟查询快递信息结束
+
+
+	//获取access_token
+	public function getAccessToken($code){
+		$ch = curl_init();
+		//$url = 'http://39.100.97.180/start/obtain';
+		$url = 'http://39.100.97.180/smt.php';
+		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;
+        curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
+		$res = curl_exec($ch);
+		curl_close($ch);
+		$res = json_decode($res,true);
+   	    if(isset($res))
+		{
+			return $res;
+		}
+	}
+	//通过refresh_token获取access_token
+	public function getTokenByrefresh(){
+
+	}
 }  //end class