Przeglądaj źródła

Use custom http post function to post json data

Jeff Wan 9 lat temu
rodzic
commit
5345e90cad
2 zmienionych plików z 30 dodań i 4 usunięć
  1. 30 3
      data/logic/delivery.logic.php
  2. 0 1
      mobile/index.php

+ 30 - 3
data/logic/delivery.logic.php

@@ -68,8 +68,35 @@ class deliveryLogic {
         }
         $data = array('type' => 'PUT_TRADE', 'data' => $delivery_order_list);
         $sign = $this->_getSign($data);
-        $param = array('v_appkey' => self::$appkey, 'v_sign' => $sign, 'data' => $data);
-        $result = json_decode(http_request(self::$appURL, $param, 'POST'));
-        return $result['data'][0];
+        $headers = array('v_appkey: '.self::$appkey, 'v_sign: '.$sign, 'Content-Type: application/json');
+        $result = json_decode($this->_http_json_post(self::$appURL, json_encode($data), $headers));
+        return $result;
+    }
+
+    private function _http_json_post($url, $params = array(), $headers = array())
+    {
+        if (!function_exists('curl_init')) {
+            return NULL;
+        }
+
+        $ci = curl_init();
+        curl_setopt($ci, CURLOPT_URL, $url);
+        if ($headers) {
+            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+        }
+        curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ci, CURLOPT_POST, 1);
+        curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
+
+        $response = curl_exec($ci);
+
+        if($response){
+            curl_close($ci);
+            return $response;
+        } else {
+            $error = curl_errno($ci);
+            curl_close($ci);
+            return array('curl error code: '.$error);
+        }
     }
 }

+ 0 - 1
mobile/index.php

@@ -11,7 +11,6 @@ define('BASE_PATH',str_replace('\\','/',dirname(__FILE__)));
 
 ////框架扩展
 require_once (BASE_PATH.'/framework/function/function.php');
-require_once (BASE_CORE_PATH.'/framework/function/http.php');
 require_once (BASE_PATH.'/control/control.php');
 
 //Base::run();