/** * 根据订单号,业务标识进行跳转 * 该方法只作跳转,不作具体业务处理 */ public function redirectOrder(){ $data = I('get.data'); if(!preg_match('/[A-Za-z0-9]{10}/i',$data)) { //TODO 这里应该显示错误页面 $this->response(createResult(403,"非法单号"),'json'); return; } // 截取业务类型 $businessType = substr($data, 0, 1); $order_s = make_bit10(substr("$data",3,7)); // 还原单号 $orderId = substr($data,1,2); if(strlen($order_s) == 12){ $orderId = 'B' . substr($orderId,0,2) . make_bit10(substr("$data",3,7)) . 'd'; }else{ $orderId = 'B' . substr($orderId,0,2) .'0'.make_bit10(substr("$data",3,7)) . 'd'; } $order = M('order'); $map['order_id'] = $orderId; $company_id = $order->where($map)->getField('company_id'); $company = M('company'); $C_map['company_id'] = $company_id; $company_name = $company->where($C_map)->getField('company_name'); // 校验订单是否存在 $count = M('order')->where(['order_id' => $orderId])->count(); if (!$count) { //TODO 这里应该显示错误页面 $this->response(createResult(404,"订单不存在"),'json'); return; } // 根据不一样的业务类型跳转到不一样的页面 switch ($businessType){ case R: header("location: http://fb.cube-y.com/wx/index.php?pages=login&act=login&Idcard=courier&company_name=$company_name&order_id=$orderId"); break; } }
在thinkphp的.htacess文件加上这段,限制订单号为10位 #RewriteRule ^[A-Za-z0-9]{10}$ /index.php/RestAPI/Common/redirectOrder/data/$1 [L]
更多php技术交流,可加Q群:884743303,里面各路大神为您保驾护航,php