【CI】易宝php支付功能代码

Continue Read..
PHP代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Yb extends CI_Controller {
//	public function __construct(){
//		parent::__construct();
//		$this->load->model('mfun');
//	}
	
	function index(){
		$this->load->view('ybindex');
	}
	
	function queren(){
		$data['p0_Cmd'] = "Buy";
		$data['p1_MerId'] = "10001126856";
		$data['p2_Order'] = $_POST['p2_Order'];
		$data['p3_Amt'] = $_POST['p3_Amt'];
		$data['p4_Cur'] = "CNY";
		$data['p5_Pid'] = "";
		$data['p6_Pcat'] = "";
		$data['p7_Pdesc'] = "";
		$data['p8_Url'] = "http://xxx.com/yb/chenggong";
		$data['p9_SAF'] = "0";
		$data['pa_MP'] = "";
		$data['pd_FrpId'] = $_POST['pd_FrpId'];
		$data['pr_NeedResponse'] = "1";
		
		
		
		$str = "";
		$str .= $data['p0_Cmd'];
		$str .= $data['p1_MerId'];
		$str .= $data['p2_Order'];
		$str .= $data['p3_Amt'];
		$str .= $data['p4_Cur'];
		$str .= $data['p5_Pid'];
		$str .= $data['p6_Pcat'];
		$str .= $data['p7_Pdesc'];
		$str .= $data['p8_Url'];
		$str .= $data['p9_SAF'];
		$str .= $data['pa_MP'];
		$str .= $data['pd_FrpId'];
		$str .= $data['pr_NeedResponse'];
		
		$key = "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl";
		
		$data['hmac'] = $this->HmacMd5($str,$key);
		$this->load->view('ybqueren',$data);
	}
	
	function chenggong(){
		$data['p1_MerId'] = "10001126856";
		$data['r0_Cmd'] = $_REQUEST['r0_Cmd'];
		$data['r1_Code'] = $_REQUEST['r1_Code'];
		$data['r2_TrxId'] = $_REQUEST['r2_TrxId'];
		$data['r3_Amt'] = $_REQUEST['r3_Amt'];
		$data['r4_Cur'] = $_REQUEST['r4_Cur'];
		$data['r5_Pid'] = $_REQUEST['r5_Pid'];
		$data['r6_Order'] = $_REQUEST['r6_Order'];
		$data['r7_Uid'] = $_REQUEST['r7_Uid'];
		$data['r8_MP'] = $_REQUEST['r8_MP'];
		$data['r9_BType'] = $_REQUEST['r9_BType'];
		$data['hmac'] = $_REQUEST['hmac'];
		
		//不参与hmac
		$data['rb_BankId'] = $_REQUEST['rb_BankId'];
		$data['rp_PayDate'] = $_REQUEST['rp_PayDate'];
		$data['rq_CardNo'] = $_REQUEST['rq_CardNo'];
		$data['ru_Trxtime'] = $_REQUEST['ru_Trxtime'];
		
		$str="";
		$str .= $data['p1_MerId'];
		$str .= $data['r0_Cmd'];
		$str .= $data['r1_Code'];
		$str .= $data['r2_TrxId'];
		$str .= $data['r3_Amt'];
		$str .= $data['r4_Cur'];
		$str .= $data['r5_Pid'];
		$str .= $data['r6_Order'];
		$str .= $data['r7_Uid'];
		$str .= $data['r8_MP'];
		$str .= $data['r9_BType'];
		$key = "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl";
		$hmac = $this->HmacMd5($str,$key);
		if($data['hmac'] == $hmac){
			if($data['r1_Code'] == 1){
				if($data['r9_BType'] == 1){
					echo "交易成功!"."
";
					echo "点单编号:".$data['r6_Order']."
";
					echo "所付金额:".$data['r3_Amt']."
";
					echo "易宝支付订单号:".$data['r2_TrxId']."
";
					echo "浏览器重定向"."
";
				}elseif($data['r9_BType'] == 2){
					echo "success";
					echo "交易成功!"."
";
					echo "点单编号:".$data['r6_Order']."
";
					echo "所付金额:".$data['r3_Amt']."
";
					echo "易宝支付订单号:".$data['r2_TrxId']."
";
					echo "服务器点对点通讯"."
";
				}
				
			}else{
				echo "交易失败";
			}
		}else{
			echo "签名被篡改";
		}
		
		
		
	}
	
	function HmacMd5($data,$key){
		// RFC 2104 HMAC implementation for php.
		// Creates an md5 HMAC.
		// Eliminates the need to install mhash to compute a HMAC
		// Hacked by Lance Rushing(NOTE: Hacked means written)
		
		//需要配置环境支持iconv,否则中文参数不能正常处理
		$key = iconv("GB2312","UTF-8",$key);
		$data = iconv("GB2312","UTF-8",$data);
		
		$b = 64; // byte length for md5
		if (strlen($key) > $b) {
		$key = pack("H*",md5($key));
		}
		$key = str_pad($key, $b, chr(0x00));
		$ipad = str_pad('', $b, chr(0x36));
		$opad = str_pad('', $b, chr(0x5c));
		$k_ipad = $key ^ $ipad ;
		$k_opad = $key ^ $opad;
		
		return md5($k_opad . pack("H*",md5($k_ipad . $data)));
	}
}

 

 

 

提交代码

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>易宝测试</title>

</head>

<body>

<form action="/yb/queren/" method="post" name="form" id="form">

<table>

<tr>

<td colspan="4">

订单编号:<input type="text" name="p2_Order" />

支付金额:<input type="text" name="p3_Amt" />

</td>

</tr>

<tr><td colspan="4">请选择网站支付银行</td></tr>

<tr>

<td>

<input type="radio" name="pd_FrpId" value="ICBC-NET" />工商银行

<input type="radio" name="pd_FrpId" value="CMBCHINA-NET" />招商银行

<input type="radio" name="pd_FrpId" value="ABC-NET" />农业银行

<input type="radio" name="pd_FrpId" value="CCB-NET" />建设银行

</td>

</tr>

<tr><td colspan="4"><input type="submit" value="确认" /></td></tr>

</table>

</form>

</body>

</html>

 

 

确认代码

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>易宝测试</title>

</head>

<body>

<form action="https://www.yeepay.com/app-merchant-proxy/node" method="post" name="form" id="form">

<table>

<tr>

<td colspan="4">

你的订单编号是:<?php echo $p2_Order;  ?>

支付金额是:<?php echo $p3_Amt;  ?>

</td>

</tr>

<tr>

<td>

<input type="hidden" name="p0_Cmd" value="<?php echo $p0_Cmd;?>" />

<input type="hidden" name="p1_MerId" value="<?php echo $p1_MerId;?>" />

<input type="hidden" name="p2_Order" value="<?php echo $p2_Order;?>" />

<input type="hidden" name="p3_Amt" value="<?php echo $p3_Amt;?>" />

<input type="hidden" name="p4_Cur" value="<?php echo $p4_Cur;?>" />

<input type="hidden" name="p5_Pid" value="<?php echo $p5_Pid;?>" />

<input type="hidden" name="p6_Pcat" value="<?php echo $p6_Pcat;?>" />

<input type="hidden" name="p7_Pdesc" value="<?php echo $p7_Pdesc;?>" />

<input type="hidden" name="p8_Url" value="<?php echo $p8_Url;?>" />

<input type="hidden" name="p9_SAF" value="<?php echo $p9_SAF;?>" />

<input type="hidden" name="pa_MP" value="<?php echo $pa_MP;?>" />

<input type="hidden" name="pd_FrpId" value="<?php echo $pd_FrpId;?>" />

<input type="hidden" name="pr_NeedResponse" value="<?php echo $pr_NeedResponse;?>" />

<input type="hidden" name="hmac" value="<?php echo $hmac;?>" />

</td>

</tr>

<tr><td colspan="4"><input type="submit" value="确认" /></td></tr>

</table>

</form>

</body>

</html>


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

ci整合ucenter同步登陆的注意点(nginx)

Continue Read..

环境是lnmp

项目换了ci,整合ucenter的同步登录的时候出现问题,在uc后台发现出现通信不成功的情况。

在本地测试都是正常的,但是在显示就不行了,检查通信吧,uc检查通信的时候是去请求项目的/api/uc.php文件,

如:http://wulin.aliapp.com/api/uc.php

我们直接访问这个文件。发现路径url没变,页面内容却是主页的,也就是没有访问到这个文件,通信当然就不成功了。

然后测试发现,所有二级页面下的php文件都是这样,仔细想想,应该是nginx的配置出了问题 


ci的配置uri模式是“AUTO”,$config['uri_protocol'] = 'AUTO';

下面给出正确的配置

server

        {

                listen       80;

                server_name aaa.wulin.cn;

                root /www/wulin;

                index index.html index.htm index.php index.shtml;

                //这里是隐藏index.php的

                location / {

                        if ($request_filename !~* /(upload|api|tc|js|javascript|css|images|fckeditor|userfiles|crontab|

 

robots\.txt|index\.php)/) {

 

                        rewrite ^/(.*)$ /index.php?$1 last;

                        break;

                     }

                }

                //主要是下面这段

                //发现url里面有uc.php的时候就指向那个文件,其他文件要访问同理

                location ~ uc\.php{

                        fastcgi_param  SCRIPT_FILENAME  /www/wulin/api/uc.php;

                        fastcgi_index index.php;

                        fastcgi_pass 127.0.0.1:9000;

                        include fastcgi_params;

                        fastcgi_param PATH_INFO $fastcgi_script_name;

                }

 

                #access_log /var/log/192.168.10.60-access.log;

 

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

                {

                        expires      30d;

                }

 

                location ~ .*\.(js|css)?$

                {

                        expires      1h;

                }

                location ~ \.php$ {

                        fastcgi_param  SCRIPT_FILENAME  /www/wulin/index.php;

                        fastcgi_index index.php;

                        fastcgi_pass 127.0.0.1:9000;

                        include fastcgi_params;

                        fastcgi_param PATH_INFO $fastcgi_script_name;

                }

 

                location ~ /\.ht

                {

                    deny all;

                }

        }

 

这下就好了,重新载入配置即可。

/etc/init.d/nginx reload

 

在访问http://wulin.aliapp.com/api/uc.php,出现:Authracation has expiried

这就对了,在到uc后台查看,发现通信成功了,测试同步登陆退出也正常了。

ci貌似在nginx下的配置确实有点麻烦。。。

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【CodeIgniter】扩展CI的sql。自己写了一个分页类

Continue Read..

 /*
  * 分页函数
  * 参数1:查询类型   0:查询数量   1:查询数据
  * 参数2:表
  * 参数3:查询条件  where 条件  格式arrar(array('k1'=>v1),array('k2'=>v2))
  * 参数4:order 条件 格式array('字段'=>排序)  
  * 参数5:分页数
  * 参数6:分页偏移量
  * 参数7:like条件  因为用的少..所以放后面..以后全部同理   用法   条件 格式array('字段'=>值)  ==  WHERE title LIKE '%value%'  目前用的是最简单的like   以后遇到复杂的在改  
  * 参数8:joinArr   join连接表  格式  array(array('表名','连接条件','连接方向'))
  * 参数9:要查询的字段  $string
  * 参数10:加入in查询    传入array('字段'=>'值的数组') 例如  $names = array('Frank', 'Todd', 'James'); $this->db->where_in('username', $names); 生成: WHERE username IN ('Frank', 'Todd', 'James')
  * 参数11:orlike条件  用法和like一样...没有把这2个合并是因为括号不兼容
  * 参数12:加入not in查询   用法和in一样...主要是SB  CI不支持" and c.isnew != 1 and c.isnew != 3"这种模式..只能用not in 来代替
  */
 
 function get_fenye_fun($type,$table,$whereArr=array(),$orderArr=array(),$page,$offset=0,$likeArr=array(),$joinArr=array(),$selectStr='',$inWhereArr=array(),$orlikeArr=array(),$noinWhereArr=array()){
//   $this->db->from('kehu_member_gendan');
//      return $this->db->count_all_results();
  if(!empty($whereArr)){
   foreach($whereArr as $k=>$v){
//    var_dump($v);
    foreach($v as $kk=>$vv){
     $this->db->where($kk,$vv);
    }
   }
  }
  if(!empty($orderArr)){
   foreach($orderArr as $k=>$v){
    $this->db->order_by($k,$v);
   }
  }
  if(!empty($likeArr)){
   foreach($likeArr as $k=>$v){
    $this->db->like($k,$v);
   }
  }
  if(!empty($orlikeArr)){
   foreach($orlikeArr as $k=>$v){
    $this->db->or_like($k,$v);
   }
  }
  if(!empty($joinArr)){
   foreach($joinArr as $k=>$v){
    $this->db->join($v[0], $v[1], $v[2]);
   }
  }
  if(!empty($selectStr)){
   $this->db->select($selectStr);
  }
  if(!empty($inWhereArr)){
   foreach($inWhereArr as $k=>$v){
    $this->db->where_in($k,$v);
   }
  }
  if(!empty($noinWhereArr)){
   foreach($noinWhereArr as $k=>$v){
    $this->db->where_not_in($k,$v);
   }
  }
  
  if(empty($type)){
   $this->db->from($table);
      return $this->db->count_all_results();
  }else{
   $this->db->limit($page, $offset);
   return $this->db->get($table);
  }
 }

 

 

用法

 function czlist(){
  //查询区域
  $data['areaArr']= $this->mfun->get_area_class_fun()->result_array();
//  var_dump("<pre>",$data['areaArr']);
  //房屋类型
  $data['fwTypeArr'] = $this->mfun->get_ershou_data('fw_type');
  
  $whereArr = array();
  $wi = 1;
//  $whereArr[0]= array('ershou_chuzhu.area'=>$this->mfun->get_site_area());
//  $whereArr[2]= array('rent <'=>600);
//  $whereArr[3]=array('rent >'=>800);
  $joinArr=array(array('ershou_xiaoqu as xq','xq.xqid = dede_ershou_chuzhu.xqid','left'));
  $selectStr='ershou_chuzhu.*,ershou_chuzhu.rent as rent1,xq.pqid,xq.address,xq.cityid';
  
  //区域
  $data['area'] = $this->uri->segment(3,0);
  if(!empty($data['area'])){
   $whereArr[$wi++]= array('ershou_chuzhu.area'=>$this->mfun->get_site_area());
//   $whereArr[]['cityid'] = $data['area'] ;
  }
  
  //租金
  $data['zj'] = $this->uri->segment(4,0);
  switch ($data['zj']){
   case 1 : $whereArr[$wi++]= array('rent <='=>600);
   case 2 : $whereArr[$wi++]= array('rent >='=>600);$whereArr[$wi++]= array('rent <='=>800);
   case 3 : $whereArr[$wi++]= array('rent >='=>800);$whereArr[$wi++]= array('rent <='=>1000);
   case 4 : $whereArr[$wi++]= array('rent >='=>1000);$whereArr[$wi++]= array('rent <='=>1500);
   case 4 : $whereArr[$wi++]= array('rent >='=>1500);$whereArr[$wi++]= array('rent <='=>1500);
  }
//  var_dump("<pre>",$whereArr);die;
  
  $config['base_url'] = "/xershou/czlist/".$data['area'].'/'.$data['zj'];//分页连接
  $data['page']=$config['per_page'] = 10;//分页数
  $data['cur_page'] = $config['cur_page'] = $this->uri->segment(5,0);
  $config['uri_segment'] = 5;
  $data['total_rows'] = $config['total_rows'] = $total_num = $this->mfun->get_fenye_fun(0,'ershou_chuzhu',$whereArr,array('ershou_chuzhu.czid'=>'desc'),$config['per_page'],$config['cur_page'],array(),$joinArr,$selectStr);
  $this->pagination->initialize($config);
  $data['pagination'] = $this->pagination->create_links();
  $data['chuzhuArr'] = $this->mfun->get_fenye_fun(1,'ershou_chuzhu',$whereArr,array('ershou_chuzhu.czid'=>'desc'),$config['per_page'],$config['cur_page'],array(),$joinArr,$selectStr)->result_array();
  
  $this->load->view('xershou_chuzu_list',$data);
 }

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【CodeIgniter】修改核心like的代码

Continue Read..

今天写程序的时候碰到个问题

就是类似这样的sql

cname=1 and(aa like '%aa%' or bb like '%XX%'  )

 

CI不会处理加了括号的sql语句

这里加不加括号的区别很大...所以我就把CI的核心代码改了

修改  system/database/DB_active_rec.php   中的_compile_select函数

 

//  if (count($this->ar_like) > 0)
//  {
//   if (count($this->ar_where) > 0)
//   {
//    $sql .= "\nAND ";
//   }
//
//   $sql .= implode("\n", $this->ar_like);
//  }
        //自己给like加()
  if (count($this->ar_like) > 0){
   if (count($this->ar_where) > 0){
    $sql .= "\nAND (";
   }
 
   $sql .= implode("\n", $this->ar_like);
   if (count($this->ar_where) > 0){
    $sql .= ")";
   }
  }

 

注释的是系统本身的...下面是我自己改的..这样就能加括号了

 

但是这个改法比较局限...只适合加了需要加括号的like   不我我觉得写sql的时候   同时用

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权