Notify.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * 此类为了处理各个平台订单统一获取订单的相关信息
  5. */
  6. class Notify extends Start_Controller {
  7. public function __construct(){
  8. parent::__construct();
  9. $this->load->library('session');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'smt')//添加
  15. {
  16. $this->_smt();
  17. }
  18. else
  19. {
  20. exit('No direct script access allowed');
  21. }
  22. }
  23. public function _smt(){
  24. $appkey = '26004389';
  25. $secretKey = 'd880d725c67b449c8a601e9b0766955d';
  26. $code = isset($_GET['code']) ? $_GET['code'] : '';
  27. // $code = $_POST['code'] ?? $authCode;
  28. // 构建请求参数
  29. $params = [
  30. 'grant_type' => 'authorization_code',
  31. 'client_id' => $appkey,
  32. 'client_secret' => $secretKey,
  33. 'code' => $code,
  34. 'redirect_uri' => "https://1.wepolicy.cn/notify/smt"
  35. ];
  36. // 发送POST请求
  37. $ch = curl_init('https://api.aliexpress.com/token');
  38. curl_setopt($ch, CURLOPT_POST, true);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  41. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
  42. $response = curl_exec($ch);
  43. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  44. if (curl_errno($ch)) {
  45. throw new Exception('cURL Error: ' . curl_error($ch));
  46. }
  47. curl_close($ch);
  48. // 处理响应
  49. $data = json_decode($response, true);
  50. echo "<pre>";
  51. var_dump($data);
  52. }
  53. // https://api-sg.aliexpress.com/oauth/authorize?response_type=code&force_auth=true&redirect_url=https://1.wepolicy.cn/notify/smt&client_id=26004389
  54. }