Browse Source

http header ok

stanley-king 9 năm trước cách đây
mục cha
commit
2b5cf09a6b

+ 7 - 14
data/logic/payment.logic.php

@@ -8,7 +8,6 @@ defined('InShopNC') or exit('Access Invalid!');
 
 class paymentLogic
 {
-
     /**
      * 取得实物订单所需支付金额等信息
      * @param int $pay_sn
@@ -41,16 +40,18 @@ class paymentLogic
         $pd_amount = $obj_member->getPdAmount($member_id);
         //计算本次需要在线支付的订单总金额
         $pay_amount = 0;
-        if (!empty($order_list)) {
+        if (!empty($order_list))
+        {
             $model_order = Model('order');
             $model_pd = Model('predeposit');
-            $obj_member = Model('member');
 
             $member_id = intval($member_id);
             $usebonus = $_GET['usebonus'];
 
-            foreach ($order_list as $order_info) {
-                if (intval($usebonus) === 1) {  // 使用全部预存款(红包逻辑)
+            foreach ($order_list as $order_info)
+            {
+                if (intval($usebonus) === 1)
+                {  // 使用全部预存款(红包逻辑)
                     $data_order = array();
                     $change_type = '';
                     if (floatval($pd_amount) > floatval($order_info['order_amount'])) {
@@ -68,7 +69,7 @@ class paymentLogic
                     }
                     $data_pd = array();
                     $data_pd['member_id'] = $member_id;
-                    $data_pd['member_name'] = "红包系统";
+                    $data_pd['member_name'] = "红包系统"; //
                     $data_pd['amount'] = $order_info['pd_amount'];
                     $data_pd['order_sn'] = $order_info['order_sn'];
                     //预存款立即支付,订单支付完成
@@ -114,17 +115,9 @@ class paymentLogic
         $condition['pay_sn'] = $pay_sn;
         $order_list = $model_order->getNormalOrderList($condition);
 
-        // 获取余额数据
-        $obj_member = Model('member');
-        $pd_amount = $obj_member->getPdAmount($member_id);
         //计算本次需要在线支付的订单总金额
         $pay_amount = 0;
         if (!empty($order_list)) {
-            $model_order = Model('order');
-            $model_pd = Model('predeposit');
-            $obj_member = Model('member');
-
-            $member_id = intval($member_id);
             foreach ($order_list as $order_info) {
                 $pay_amount += ncPriceFormat(floatval($order_info['order_amount']) - floatval($order_info['pd_amount']));
             }

+ 9 - 8
data/model/predeposit.model.php

@@ -247,7 +247,8 @@ class predepositModel extends Model {
      * @throws Exception
      * @return unknown
      */
-    public function changePd($change_type,$data = array()) {
+    public function changePd($change_type,$data = array())
+    {
         $data_log = array();
         $data_pd = array();
         $data_msg = array();
@@ -259,7 +260,8 @@ class predepositModel extends Model {
 
         $data_msg['time'] = date('Y-m-d H:i:s');
         $data_msg['pd_url'] = urlShop('predeposit', 'pd_log_list');
-        switch ($change_type){
+        switch ($change_type)
+        {
             case 'order_pay':
                 $data_log['lg_av_amount'] = -$data['amount'];
                 $data_log['lg_desc'] = '下单,支付预存款,订单号: '.$data['order_sn'];
@@ -362,7 +364,7 @@ class predepositModel extends Model {
                 $data_msg['freeze_amount'] = -$data['amount'];
                 $data_msg['desc'] = $data_log['lg_desc'];
                 break;
-                case 'bonus_add_money':
+            case 'bonus_add_money':
                 $data_log['lg_av_amount'] = $data['amount'];
                 $data_log['lg_desc'] = '红包系统调节预存款【增加】,充值单号: '.$data['pdr_sn'];
                 $data_log['lg_admin_name'] = $data['admin_name'];
@@ -373,7 +375,7 @@ class predepositModel extends Model {
                 $data_msg['desc'] = $data_log['lg_desc'];
                 break;
 				////////////////////zmr>v20////////////////////////////////////
-				case 'sys_add_money':
+            case 'sys_add_money':
                 $data_log['lg_av_amount'] = $data['amount'];
                 $data_log['lg_desc'] = '管理员调节预存款【增加】,充值单号: '.$data['pdr_sn'];
                 $data_log['lg_admin_name'] = $data['admin_name'];
@@ -383,7 +385,7 @@ class predepositModel extends Model {
                 $data_msg['freeze_amount'] = 0;
                 $data_msg['desc'] = $data_log['lg_desc'];
                 break;
-				case 'sys_del_money':
+            case 'sys_del_money':
                 $data_log['lg_av_amount'] = -$data['amount'];
                 $data_log['lg_desc'] = '管理员调节预存款【减少】,充值单号: '.$data['pdr_sn'];
                 $data_pd['available_predeposit'] = array('exp','available_predeposit-'.$data['amount']);
@@ -392,7 +394,7 @@ class predepositModel extends Model {
                 $data_msg['freeze_amount'] = 0;
                 $data_msg['desc'] = $data_log['lg_desc'];
                 break;
-				case 'sys_freeze_money':
+            case 'sys_freeze_money':
                 $data_log['lg_av_amount'] = -$data['amount'];
                 $data_log['lg_freeze_amount'] = $data['amount'];
 				$data_log['lg_desc'] = '管理员调节预存款【冻结】,充值单号: '.$data['pdr_sn'];
@@ -403,7 +405,7 @@ class predepositModel extends Model {
                 $data_msg['freeze_amount'] = $data['amount'];
                 $data_msg['desc'] = $data_log['lg_desc'];
                 break;
-				case 'sys_unfreeze_money':
+            case 'sys_unfreeze_money':
                 $data_log['lg_av_amount'] = $data['amount'];
                 $data_log['lg_freeze_amount'] = -$data['amount'];
                 $data_log['lg_desc'] = '管理员调节预存款【解冻】,充值单号: '.$data['pdr_sn'];
@@ -417,7 +419,6 @@ class predepositModel extends Model {
                 break;
 				
 				//////////////////////////////////////////////////////
-
             default:
                 throw new Exception('参数错误');
                 break;

+ 1 - 3
fcgi_run.php

@@ -65,13 +65,11 @@ function run_fcgi()
             joutput_error($ex->getCode(),$ex->getMessage().'@@@@@'.$ex->getTraceAsString());
         }
 
-        $sheader =  http_header::instance()->end();
-        fcgi_echo($sheader);
+        fcgi_headers_sent();
 
         $contents = ob_get_clean();
         fcgi_echo($contents);
 
-        //Log::record($contents,Log::DEBUG);
         fcgi_finish();
     }
 

+ 178 - 8
helper/http_header.php

@@ -17,21 +17,83 @@ class http_header
     const COOKIE_HTTPONLY   = "; HttpOnly";
 
     private static $stHeader = NULL;
+    private static $http_status_map = array(100 =>"Continue",
+                                            101 =>"Switching Protocols" ,
+                                            200 =>"OK" ,
+                                            201 =>"Created" ,
+                                            202 =>"Accepted" ,
+                                            203 =>"Non-Authoritative Information" ,
+                                            204 =>"No Content" ,
+                                            205 =>"Reset Content" ,
+                                            206 =>"Partial Content" ,
+                                            300 =>"Multiple Choices" ,
+                                            301 =>"Moved Permanently" ,
+                                            302 =>"Found" ,
+                                            303 =>"See Other" ,
+                                            304 =>"Not Modified" ,
+                                            305 =>"Use Proxy" ,
+                                            307 =>"Temporary Redirect" ,
+                                            308 =>"Permanent Redirect" ,
+                                            400 =>"Bad Request" ,
+                                            401 =>"Unauthorized" ,
+                                            402 =>"Payment Required" ,
+                                            403 =>"Forbidden" ,
+                                            404 =>"Not Found" ,
+                                            405 =>"Method Not Allowed" ,
+                                            406 =>"Not Acceptable" ,
+                                            407 =>"Proxy Authentication Required" ,
+                                            408 =>"Request Timeout" ,
+                                            409 =>"Conflict" ,
+                                            410 =>"Gone" ,
+                                            411 =>"Length Required" ,
+                                            412 =>"Precondition Failed" ,
+                                            413 =>"Request Entity Too Large" ,
+                                            414 =>"Request-URI Too Long" ,
+                                            415 =>"Unsupported Media Type" ,
+                                            416 =>"Requested Range Not Satisfiable" ,
+                                            417 =>"Expectation Failed" ,
+                                            426 =>"Upgrade Required" ,
+                                            428 =>"Precondition Required" ,
+                                            429 =>"Too Many Requests" ,
+                                            431 =>"Request Header Fields Too Large" ,
+                                            500 =>"Internal Server Error" ,
+                                            501 =>"Not Implemented" ,
+                                            502 =>"Bad Gateway" ,
+                                            503 =>"Service Unavailable" ,
+                                            504 =>"Gateway Timeout" ,
+                                            505 =>"HTTP Version Not Supported" ,
+                                            506 =>"Variant Also Negotiates" ,
+                                            511 =>"Network Authentication Required");
 
     private $mHeader = NULL;
+    private $mStatusLine = '';
+    private $mStatusCode = 200;
+    private $mSended = false;
 
-    private function __construct()
+    public function start()
     {
+        $this->mHeader = new SplDoublyLinkedList();
+        $this->mStatusCode = 200;
+        $this->mSended = false;
     }
 
-    public function start()
+    public function sent()
     {
-        $this->mHeader = new SplDoublyLinkedList();
+        if($this->sended == false) {
+            $this->mSended = true;
+            $sHeader = $this->to_string();
+            fcgi_echo($sHeader);
+        }
+
+        return $this->mSended;
     }
 
-    public function end()
+    private function to_string()
     {
         $sheader = '';
+
+        $status_line = sprintf("HTTP/1.1 %d %s\r\n",$this->mStatusCode,self::$http_status_map[$this->mStatusCode]);
+        $sheader .= $status_line;
         foreach($this->mHeader as $val)
         {
             $sheader .= $val . "\r\n";
@@ -132,24 +194,127 @@ class http_header
         $this->mHeader->push($string);
     }
 
-    public function header ($string, $replace = true, $http_response_code = null)
+    private function newline_check($string)
     {
-        if(empty($string)) return;
-
         $datas = str_split($string);
         foreach($datas as $val) {
             if($val == '\r' || $val == '\n') {
                 Log::record("Header may not contain more than a single header, new line detected",Log::ERR);
-                return;
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private function extract_response_code($header_line)
+    {
+        $code = 200;
+        $nodes = explode($header_line);
+        if(count($nodes) > 1)
+        {
+            $datas = str_split($nodes[1]);
+
+            $max = intval('0') + 9;
+            $min = intval('0');
+
+            foreach($datas as $ch)
+            {
+                if($ch >$max || $ch < $min) {
+                    return false;
+                }
+            }
+
+            $code = intval($nodes[1]);
+        }
+
+        return $code;
+    }
+
+
+
+    private function special_line($header_line,$http_response_code)
+    {
+        $len = strlen($header_line);
+
+        if($len >= 5 && strncasecmp($header_line,"HTTP/", 5) == 0)
+        {
+            $this->mStatusCode = $this->extract_response_code($header_line);
+            $this->mStatusLine = $header_line;
+            return 0;
+        }
+        else
+        {
+            $colon_offset = strchr($header_line, ':');
+            if($colon_offset)
+            {
+                if (!strcasecmp($header_line, "Location",strlen("Location")))
+                {
+                    if( ($this->mStatusCode < 300 || $this->mStatusCode > 399) && $this->mStatusCode != 201)
+                    {
+                        $method = strtolower(request_helper::method());
+                        if ($http_response_code) { /* user specified redirect code */
+                            $this->mStatusCode = $http_response_code;
+                        } else if ($method == 'get') {
+                            $this->mStatusCode = 303;
+                        } else {
+                            $this->mStatusCode = 302;
+                        }
+                    }
+                }
+                else if(!strcasecmp($header_line, "WWW-Authenticate",strlen("WWW-Authenticate"))) {
+                    $this->mStatusCode = 401;
+                }
             }
         }
 
+        return 1;
+    }
+
+    public function header ($string, $replace = true, $http_response_code = null)
+    {
+        if(empty($string)) return;
+        if($this->newline_check($string) == false) return;
+
+        if($this->special_line($string,$http_response_code) == 0) {
+            return false;
+        }
+        if($http_response_code) {
+            $this->mStatusCode = $http_response_code;
+        }
+
         if($replace) {
             $this->replace($string);
         } else {
             $this->mHeader->push($string);
         }
     }
+
+    public function remove($name)
+    {
+        if(empty($name)) {
+            $this->mHeader->clear();
+        }
+        else
+        {
+            $reg = '/^([^:]*): (.*)/i';
+
+            $index = 0;
+            for($this->mHeader->rewind();$this->mHeader->valid();$this->mHeader->next())
+            {
+                $val = $this->mHeader->current();
+                if(preg_match($reg,$val,$m))
+                {
+                    $hname = strtolower($m[1]);
+                    if(strcmp($name,$hname) == 0) {
+                        $this->mHeader->offsetUnset($index);
+                        break;
+                    }
+                    $index++;
+                }
+            }
+        }
+    }
 }
 
 function init_cookie($cookie)
@@ -195,5 +360,10 @@ function fcgi_header($string, $replace = true, $http_response_code = null)
 
 function fcgi_header_remove($name)
 {
+    return http_header::instance()->remove($name);
+}
 
+function fcgi_headers_sent()
+{
+    return http_header::instance()->sent();
 }

+ 27 - 27
mobile/control/member_order.php

@@ -193,33 +193,33 @@ class member_orderControl extends mobileMemberControl
      */
     public function search_deliverOp()
     {
-        $order_id = intval($_POST['order_id']);
-        if ($order_id <= 0) {
-            return joutput_error(errcode::ErrOrder, '订单不存在');
-        }
-        $model_order = Model('order');
-        $condition['order_id'] = $order_id;
-        $condition['buyer_id'] = $this->member_info['member_id'];
-        $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods'));
-
-        if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
-            return joutput_error(errcode::ErrOrder, '订单不存在');
-        }
-
-        $express = rkcache('express', true);
-        $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_code'];
-        $e_name = $express[$order_info['extend_order_common']['shipping_express_id']]['e_name'];
-
-        $key = "express_" . $order_info['shipping_code'];
-        $deliver_info = rkcache($key);
-        if(empty($deliver_info))
-        {
-            $deliver_info = $this->_get_express($e_code, $order_info['shipping_code']);
-            if ($deliver_info === false) {
-                return;
-            }
-            wkcache($key,$deliver_info,3600);
-        }
+//        $order_id = intval($_POST['order_id']);
+//        if ($order_id <= 0) {
+//            return joutput_error(errcode::ErrOrder, '订单不存在');
+//        }
+//        $model_order = Model('order');
+//        $condition['order_id'] = $order_id;
+//        $condition['buyer_id'] = $this->member_info['member_id'];
+//        $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods'));
+//
+//        if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
+//            return joutput_error(errcode::ErrOrder, '订单不存在');
+//        }
+//
+//        $express = rkcache('express', true);
+//        $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_code'];
+//        $e_name = $express[$order_info['extend_order_common']['shipping_express_id']]['e_name'];
+//
+//        $key = "express_" . $order_info['shipping_code'];
+//        $deliver_info = rkcache($key);
+//        if(empty($deliver_info))
+//        {
+//            $deliver_info = $this->_get_express($e_code, $order_info['shipping_code']);
+//            if ($deliver_info === false) {
+//                return;
+//            }
+//            wkcache($key,$deliver_info,3600);
+//        }
 
         $e_name = '韵达';
         $deliver_info = $this->_get_express('shentong', '3304531668888');

+ 4 - 2
mobile/templates/default/express_info.php

@@ -1,4 +1,6 @@
-<?php defined('InShopNC') or exit('Access Invalid!'); ?>
+<?php defined('InShopNC') or exit('Access Invalid!');
+//<?php echo RESOURCE_SITE_URL;
+?>
 
 <!doctype html>
 <html lang="en">
@@ -8,7 +10,7 @@
     <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
     <meta content="email=no" name="format-detection" />
     <meta name="format-detection" content="telephone=no" />
-    <link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL; ?>/wap/css/express.css">
+    <link rel="stylesheet" type="text/css" href="http://localhost/wap/css/express.css">
 </head>
 <body>
 <header>

+ 3 - 0
research/research_run.php

@@ -7,6 +7,9 @@
     
 Base::run_test();
 
+$header_line = 'HTTP/HTTP/HTTP';
+$ret = strncasecmp($header_line,"HTTP/", 5);
+
 
 //https://img.alicdn.com/bao/uploaded/i3/90919986/TB2IOb_hXXXXXa6XXXXXXXXXXXX_!!90919986.jpg