1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- /**
- * 此类为了处理各个平台订单统一获取订单的相关信息
- */
- class Notify extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
-
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'smt')//添加
- {
- $this->_smt();
- }
- else
- {
- exit('No direct script access allowed');
- }
- }
- public function _smt(){
- $appkey = '26004389';
- $secretKey = 'd880d725c67b449c8a601e9b0766955d';
- $code = isset($_GET['code']) ? $_GET['code'] : '';
- // $code = $_POST['code'] ?? $authCode;
-
- // 构建请求参数
- $params = [
- 'grant_type' => 'authorization_code',
- 'client_id' => $appkey,
- 'client_secret' => $secretKey,
- 'code' => $code,
- 'redirect_uri' => "https://1.wepolicy.cn/notify/smt"
- ];
-
- // 发送POST请求
- $ch = curl_init('https://api.aliexpress.com/token');
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
-
- $response = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- if (curl_errno($ch)) {
- throw new Exception('cURL Error: ' . curl_error($ch));
- }
-
- curl_close($ch);
-
- // 处理响应
- $data = json_decode($response, true);
- echo "<pre>";
- var_dump($data);
- }
- // https://api-sg.aliexpress.com/oauth/authorize?response_type=code&force_auth=true&redirect_url=https://1.wepolicy.cn/notify/smt&client_id=26004389
-
- }
|