Esempio n. 1
0
 public function richcard_http()
 {
     if (!empty($_GET) && empty($_POST)) {
         $_POST = $_GET;
     }
     unset($_GET);
     if (empty($_POST)) {
         die('data error!');
     }
     $_GET = $_POST;
     unset($_GET['btn_submit_x']);
     unset($_GET['btn_submit_y']);
     unset($_GET['btn_submit']);
     $returnURL = $_GET['returnURL'];
     $post_data = '';
     foreach ($_GET as $k => $v) {
         $post_data .= $k . "=" . $v . "&";
     }
     //提交地址
     $payUrl = $_REQUEST['paymentUrl'];
     $ssl = substr($payUrl, 0, 8) == "https://" ? TRUE : FALSE;
     $wesite = "http://" . $_SERVER['HTTP_HOST'];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $payUrl);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     curl_setopt($ch, CURLOPT_REFERER, $wesite);
     if ($ssl) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     }
     $paymentResult = curl_exec($ch);
     curl_close($ch);
     self::$Model = D("Orders");
     //查询订单相关信息
     $orderinfo = self::$Model->where("sn='" . $_GET['orderNo'] . "'")->find();
     if (empty($orderinfo)) {
         die('Signature error!');
     }
     $this->orderinfo = $orderinfo;
     $order_product_info = D('OrdersProducts')->where("orders_id='{$orderinfo['id']}'")->select();
     if ($order_product_info) {
         foreach ($order_product_info as $k => $val) {
             $order_product_info[$k]['name'] = $val['products_name'];
         }
     }
     $this->order_product_info = $order_product_info;
     $error_msg = 'Paid failed, return and try it again!';
     if (!empty($paymentResult)) {
         //解析返回的xml参数
         $payXml = simplexml_load_string($paymentResult);
         if (!empty($payXml)) {
             $tradeNo = (string) $payXml->tradeNo;
             $orderNo = (string) $payXml->orderNo;
             $amount = (string) $payXml->amount;
             $currency = (string) $payXml->currency;
             $succeed = (string) $payXml->succeed;
             $bankInfo = (string) $payXml->bankInfo;
             $md5Info = (string) $payXml->md5Info;
             $md5Info = strtoupper($md5Info);
             $errorMsg = (string) $payXml->errorMsg;
             $this->writePaymentLog((string) $payXml->orderNo, (string) $payXml->errorCode, (string) $payXml->errorMsg);
             /* 校验数据 */
             $merKey = trim(GetValue('richcard_key'));
             $signSrc = $tradeNo . $orderNo . $merKey . $succeed . $currency . $amount;
             $mysign = strtoupper(md5($signSrc));
             //根据得到的数据  进行相对应的操作
             //$succeed支付状态 0-支付失败 1-支付成功 2和3-支付待处理
             /* 验证支付结果 */
             if ($md5Info == $mysign) {
                 if ($succeed == '1') {
                     $data['orders_status'] = '2';
                     self::$Model->where("sn='" . $orderNo . "'")->save($data);
                     //修改订单支付状态
                     give_member_points($orderNo);
                     //赠送用户积分
                     $error_msg = '';
                     $this->display('succeed');
                 } else {
                     $data['orders_status'] = '1';
                     self::$Model->where("sn='" . $orderNo . "'")->save($data);
                     //修改订单状态为正在付款中
                 }
             }
         }
     }
     $this->error_msg = $error_msg;
     $this->display('failure');
 }
   public function return_95pay()
   {
       //MD5私钥
       $MD5key = GetSettValue('	_95epay_key');
       //支付平台流水号
       $TradeNo = $_POST["TradeNo"];
       //供商户在支付平台查询订单时使用,请合理保存
       //支付状态
       $PaymentResult = $_POST["PaymentResult"];
       //返回码: 1 :表示交易成功 ; 0: 表示交易失败
       //订单号
       $BillNo = $_POST["BillNo"];
       //币种
       $Currency = $_POST["Currency"];
       //金额
       $Amount = $_POST["Amount"];
       //支付状态
       $Succeed = $_POST["Succeed"];
       //支付结果
       $Result = $_POST["Result"];
       //取得的MD5校验信息
       $MD5info = $_POST["MD5info"];
       //备注
       $Remark = $_POST["Remark"];
       //金额单位
       $currencyName = $_POST["currencyName"];
       /**
        **判断是哪次返回的数据【顾客支付完立即返回,还是支付处理完以后返回的数据】
        */
       //服务器返回数据开始
       if (isset($TradeNo) && !empty($TradeNo) && isset($PaymentResult) && !empty($PaymentResult)) {
           //校验源字符串
           $returnMd5src = $TradeNo . $BillNo . $Currency . $Amount . $PaymentResult . $MD5key;
           //本地MD5检验结果
           $returnMd5sign = strtoupper(md5($returnMd5src));
           if ($returnMd5sign == $MD5info) {
               if ($PaymentResult == '1') {
                   //支付已成功
                   //请修改订单状态为成功状态
               } else {
                   if ($PaymentResult == '0') {
                       //支付已失败
                       //请修改订单状态为失败状态
                   }
               }
           }
           exit;
           //处理完以后返回的数据.只要根据订单号改变数据库订单状态就可以了。
       }
       //服务器返回数据结束
       //校验源字符串
       $md5src = $BillNo . $Currency . $Amount . $Succeed . $MD5key;
       //MD5检验结果
       $md5sign = strtoupper(md5($md5src));
       self::$Model = D("Orders");
       if ($MD5info == $md5sign) {
           //MD5验证成功
           echo '<html><head><title>php</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><table width="728" border="0" cellspacing="0" cellpadding="0" align="center"> <tr>
   <td  align="right" valign="top">Your order number is:</td>  <td  align="left" valign="top">$BillNo</td>
 </tr>  <tr>    <td  align="right" valign="top">Amount:</td>    <td align="left" valign="top">$Amount $currencyName</td>  </tr>  <tr>   <td  align="right" valign="top">Payment result:</td>';
           if ($Succeed == "88") {
               //支付成功,返回绿色的提示信息,可修改订单状态为付款成功
               $data['orders_status'] = "2";
               self::$Model->where("sn='" . $BillNo . "'")->save($data);
               //赠送用户积分
               give_member_points($BillNo);
               echo '<td align="left" valign="top" style="color:green;">' . urldecode($Result) . '</td>';
           } elseif ($Succeed == "1" || $Succeed == "9" || $Succeed == "19") {
               //提交支付信息成功,返回绿色的提示信息,可修改订单状态为正在付款中
               $data['orders_status'] = "1";
               self::$Model->where("sn='" . $BillNo . "'")->save($data);
               echo '<td align="left" valign="top" style="color:green;">' . urldecode($Result) . '</td>';
           } else {
               //提交支付信息失败,返回红色的提示信息
               echo '<td  align="left" valign="top" style="color:red;">' . urldecode($Result) . '&nbsp;&nbsp;&nbsp;&nbsp;' . $Succeed . '</td>';
           }
           echo '</tr>	</table>';
       } else {
           //MD5验证失败
           echo '<table width="728" border="0" cellspacing="0" cellpadding="0" align="center"> <tr>    <td  align="center" valign="top" style="color:red;">Validation failed!</td>	</tr>	</table>';
       }
       echo '<p align="center"><a href="#" onClick="javascript:window.close()"><font size=2 color=blove>Close</font></a></p></body></html>';
   }