您的位置:68399皇家赌场 > 集群主机 > CI框架源码研读(路由解析)

CI框架源码研读(路由解析)

发布时间:2019-11-24 03:06编辑:集群主机浏览(114)

    咱俩不经常候在CI框架中须求自定义配置文件,那要怎么管理吧?下边就给您介绍管理的点子。布置文件config/expert.php复制代码 代码如下: '124', '1' => '81', '2' => '136');?>得到配置数据示例$this->config->load;$expertid = $this->config->item;

    1. 配置运维情形
      1.1  安装java,自行到oracle官方网站下载 java,然后安装,并安顿不错的 情状变量。
      1.2  把 测量试验的证件导入到java 设想机;
       keytool " -import -keystore "java虚构机放置证书之处" -storepass changeit -alias test_bocommca -file "证书路线" 完结导入。
       例子:keytool" -import -keystore "C:\Program Files\Java\jre1.5\lib\security\cacerts" -storepass changeit -alias test_bocommca -file "C:\socket\cert\test_root.cer"

    复制代码 代码如下:/*|--------------------------------------------------------------------------| Enable/Disable System Hooks|--------------------------------------------------------------------------|| If you would like to use the 'hooks' feature you must enable it by| setting this variable to TRUE . See the user guide for details.|*/$config['enable_hooks'] = TRUE;

    2、Router.php

    大家进来Router.php中大器晚成探毕竟,Router类中的构造函数宗旨是此处:

    $this->_set_routing();

    _set_routing方法其实宗旨做这几步操作:

    $_d = $this->config->item('directory_trigger');

    $this->set_directory;

    $_c = trim($this->config->item('controller_trigger'));

    $this->set_class($_GET[$_c]);

    $_f = trim($this->config->item('function_trigger'));

    $this->set_method($_GET[$_f]);

    $this->_parse_routes();

    分级从全局变量_GET数组中拿走 directory,class,method,他们的trigger能够在布局文件中配备。本来那是在 enable_query_strings 设置为true的景色下。接下来就步向了最重大的艺术中_parse_routes方法:

    大家在CI的路由配置中,可以如下配置:

    $route['products']['put']='product/insert';

    正是因为在_parse_routes中的这段代码:

    $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli';

    $val = array_change_key_case($val, CASE_LOWER);

    if (isset($val[$http_verb])){

    $val = $val[$http_verb];}

    else{continue;}

    HTTP verbs (GET, PUT, POST, DELETE, PATCH) 有这么二种.而小编辈在配置中得以那样配置:

    $route['product/']='catalog/product_lookup_by_id/$1';

    是因为_parse_routes中的这段代码:

    $key = str_replace(array(':any', ':num'), array('[^/] ', '[0-9] '), $key);

    路由配置中特别能够配备回调函数如:

    $route['products/([a-zA-Z] )/edit/']=function($product_type,$id){return'catalog/product_edit/'.strtolower($product_type).'/'.$id;};

    是因为有这段代码:

    if ( ! is_string && is_callable{

    array_shift;

    $val = call_user_func_array($val, $matches);

    }

    而貌似的布局:

    else if (strpos !== FALSE && strpos($key, ' !== FALSE){

    $val = preg_replace('#^'.$key.'$#', $val, $uri);

    }

    终极调用了:

    $this->_set_request(array_values($this->uri->segments));

    _set_request方法个中

    $this->set_class($segments[0]);

    if (isset($segments[1])){

    $this->set_method($segments[1]);

    }else{

    $segments[1] = 'index';

    }

    set了class和method,那就得到了我们在起头CodeIgniter.php中所须求的class和method

      //以下是 新接口须要的参数
      $config['socketUrl']         ="tcp://127.0.0.1:8891";  #socket url
      $config['merID']     ='301310063009501';    #商户id 3013100630095012
    2.2 Model

    4、编写具体的权能调控Acl类

    上篇小说当中大家关系,在CodeIgniter.php中,拆解解析出你拜见的url所对应的controllers和action,然后在调用call_user_func_array()方法,步入到action中,而这里是何等获得那些相应关系的呢,那正是大家今后要探讨的始末。

    2.1  将不变的参数 配置 写入配置文件:

    复制代码 代码如下:/*
    Hooks
    -------------------------------------------------------------------------
    This file lets you define "hooks" to extend CI without hacking the core
    files. Please see the user guide for info:
    */$hook['post_controller_constructor']

    3、Uri.php

    这边要说下那几个地点uri的来路:

    $uri = implode('/', $this->uri->segments);

    我们进去Uri类中查阅终归:

    着力的点子是_parse_request_uri,在方法体中,

    $uri = parse_url(']);

    $query = isset($uri['query']) ? $uri['query'] : '';

    $uri = isset($uri['path']) ? $uri['path'] : '';

    return $this->_remove_relative_directory;

    重在是用parse_url拆解剖析出url个中的path和query,然后开展删减相对路线的管理。

    $this->uri->segments那几个成员变量中蕴藏的正是explode('/', trim($uri, '/') 后的数组,在_set_uri_string方法中赋值。

    /**
     * 建设银行支付类
     */
    class Bocom extends CI_Model {
     private $arrReturn=array();
     private $socket;
     public function __construct() {
      parent::__construct ();
      //加载邮储配备文件
      $this->config->load('bocom');
      $this->socket=$this->config->item('socketUrl');
     }
     /**
      * 支付办法
      *
      * @param unknown $arr_data=array(
      *  'bill_no'=>
      * )
      */
     public  function pay($arr_data){
      //获得表单传过来的数目
      $this->arrReturn['interfaceVersion'] = $this->config->item('interfaceVersion');
      $this->arrReturn['merID']       = $this->config->item('merID'); //商行号为稳固
      $this->arrReturn['orderid']  = $arr_data['bill_no'];
      $this->arrReturn['orderDate']  = $arr_data['bill_date'];
      $this->arrReturn['orderTime']  = $arr_data['bill_time'];
      $this->arrReturn['tranType']  = $this->config->item('tranType');
      $this->arrReturn['amount']    = $arr_data['bill_fee'];
      $this->arrReturn['curType']  = $this->config->item('curType');
      $this->arrReturn['orderContent']  = isset($arr_data['bill_title'])?iconv('utf-8','gb2312',$arr_data["bill_title"]): '';   #订单内容
      $this->arrReturn['orderMono']     = isset($arr_data['bill_mono'])? iconv('utf-8','gb2312',$arr_data['bill_mono']):'';     #信用合作社备注
      $this->arrReturn['phdFlag']       = isset($arr_data['phpFlag'])?$arr_data['phpFlag']:'';
      $this->arrReturn['notifyType']    = $this->config->item('notifyType');
      $this->arrReturn['merURL']        = $this->config->item('merURL');
      $this->arrReturn['goodsURL']      = $this->config->item('goodsURL');
      $this->arrReturn['jumpSeconds']   = $this->config->item('jumpSeconds');
      $this->arrReturn['payBatchNo']    = $this->config->item('payBatchNo');
      $this->arrReturn['proxyMerName']  = $this->config->item('proxyMerName');
      $this->arrReturn['proxyMerType']  = $this->config->item('proxyMerType');
      $this->arrReturn['proxyMerCredentials']= $this->config->item('proxyMerCredentials');
      $this->arrReturn['netType']        = $this->config->item('netType');
      //以下参数 不到场签定
      $this->arrReturn['issBankNo']      =isset($arr_data['code_id'])? trim($arr_data['code_id']):'';
      $tranCode = "cb2200_sign";
      $source='';
      $len = count($this->arrReturn)-1;$j=1;
      foreach($this->arrReturn as $v){
       if($j<=$len){
        $source.=$v."|";
       }
       $j ;
      }
      $source= substr($source, 0,strlen($source)-1);
         $fp= stream_socket_client($this->socket,$errno, $errstr, 30);   
         $retMsg="";
         if (!$fp) {
          log_message("info","socket连接战败");
          return false;
         } else
         {
         $in  = "<?xml version='1.0' encoding='gbk2312'?>";
      $in .= "<Message>";
      $in .= "<TranCode>".$tranCode."</TranCode>";
      $in .= "<MsgContent>".$source."</MsgContent>";
      $in .= "</Message>";
      fwrite($fp, $in);
           while (!feof($fp)) {
            $retMsg =$retMsg.fgets($fp, 1024);
           }
           fclose($fp);
         }
        if(false!==$xml_arr=$this->xmlParse($retMsg)){
           if(is_array($xml_arr)){
            foreach($xml_arr as $k=>$v){
             $this->arrReturn[$k]=$v;
            }
           }else{
            return false;
           }
        }else{
          return false;
        }
        return $this->arrReturn;
     }
     
     /**
      * 解析XML
      */
     public function xmlParse($retMsg){
      $arr=array();
      //拆解分析重临xml
      $dom = new DOMDocument;
      $dom->loadXML($retMsg);
      $retCode = $dom->getElementsByTagName('retCode');
      $retCode_value = $retCode->item(0)->nodeValue;
      $errMsg = $dom->getElementsByTagName('errMsg');
      $errMsg_value = $errMsg->item(0)->nodeValue;
      $signMsg = $dom->getElementsByTagName('signMsg');
      $signMsg_value = $signMsg->item(0)->nodeValue;
      $orderUrl = $dom->getElementsByTagName('orderUrl');
      $orderUrl_value = $orderUrl->item(0)->nodeValue;
      $MerchID = $dom->getElementsByTagName('MerchID');
      $merID = $MerchID->item(0)->nodeValue;
      if($retCode_value != "0"){
       log_message("info","交易重临码:".$retCode_value);
       log_message("info","交易错误消息:".$errMsg_value);
                return false;
            }
       $arr['merSignMsg'] = $signMsg_value;
       $arr['merID']      = $merID;
        $arr['orderUrl']   = $orderUrl_value;     
       return $arr;
     }
     /**
      * 民生银行 支付文告
      * @return boolean|unknown
      */
     public function notify(){
      $tranCode = "cb2200_verify";
      if(!isset($_REQUEST['notifyMsg'])){
       log_message("error","网银支付布告·违法央浼");
       return false;
      }
         $notifyMsg = $_REQUEST["notifyMsg"];
      log_message("error",$notifyMsg."回调....");
      
      $lastIndex = strripos($notifyMsg,"|");
      $signMsg = substr($notifyMsg,$lastIndex 1); //签字消息
      $srcMsg = substr($notifyMsg,0,$lastIndex 1);//原文
      $merID = $this->config->item('merID');
      $fp = stream_socket_client($this->socket, $errno, $errstr, 30);
      $retMsg="";
      //
      if (!$fp) {
       echo "$errstr ($errno)<br />\n";
       log_message("error","$errstr ($errno)<br />\n");
      } else{  
       $in  = "<?xml version='1.0' encoding='gb2312'?>";
       $in .= "<Message>";
       $in .= "<TranCode>".$tranCode."</TranCode>";
       $in .= "<merchantID>".$merID."</merchantID>";
       $in .= "<MsgContent>".$notifyMsg."</MsgContent>";
       $in .= "</Message>";
      fwrite($fp, $in);
        while (!feof($fp)) {
         $retMsg =$retMsg.fgets($fp, 1024); 
        }
        fclose($fp);
      }
      //深入分析重回xml
      $dom = new DOMDocument;
      $dom->loadXML($retMsg); 
      $retCode = $dom->getElementsByTagName('retCode');
      $retCode_value = $retCode->item(0)->nodeValue;
      $errMsg = $dom->getElementsByTagName('errMsg');
      $errMsg_value = $errMsg->item(0)->nodeValue;
      if($retCode_value != '0')
      {
       log_message("error","交易错误音讯:" .$errMsg_value."<br>");
       return false;
      }else{
       $arr = preg_split("/\|{1,}/",$srcMsg);
       if($arr[9]=="1"){
        return $this->updateBill($arr[1]);
       }
       log_message("error","交易战败:".$arr[13]."<br/>");
       return false;
      } 
     }
     private function updateBill($billNo){
      // 更新 订单状态
     }
     //end class
    }
    2.3 控制器
    $this->load->model("Bocom");
     支付办法:
     $this->arrData =$this->Bocom->pay($this->data);
     通知:
       $this->arrData =$this->Bocom->notify();

    复制代码 代码如下:class Acl { private $url_model; private $url_method; private $CI; function Acl() { $this->CI =& get_instance(); $this->CI->load->library; $this->url_model = $this->CI->uri->segment; $this->url_method = $this->CI->uri->segment { $user = $this->CI->session->userdata; if $user->status = 0; $this->CI->load->config; $AUTH = $this->CI->config->item; if(in_array($user->status, array_keys{ $controllers = $AUTH[$user->status]; if(in_array($this->url_model, array_keys{ if(!in_array($this->url_method, $controllers[皇家赌场 ,$this->url_model])){ show_error('您无权访谈该意义,该错误已经被记录!点击返回'); } }else{ show_error('您无权访谈该模块,该错误已经被记录!点击返回'); } } else show_error('错误的客户类型,该错误已经被记录!点击返回'); }}

    1、CodeIgniter.php

    我们率先来到CodeIgniter.php,开掘那其实是在Router类中落到实处的,如下源码:

    $RTR =& load_class('Router', 'core', isset ? $routing : NULL);

    $class = ucfirst($RTR->class);

    $method = $RTR->method;

    本文由68399皇家赌场发布于集群主机,转载请注明出处:CI框架源码研读(路由解析)

    关键词: 68399皇家赌场 脚本 之家 自定义 配置文件

上一篇:php array数组生成csv文件

下一篇:没有了