/**
  * 支付结果返回
  */
 public function notify()
 {
     $apitype = I('get.apitype');
     $apitype = safe_replace($apitype);
     //过滤
     /* 支付设置 */
     $payment = array('tenpay' => array('key' => C('TENPAYKEY'), 'partner' => C('TENPAYPARTNER')), 'alipay' => array('email' => C('ALIPAYEMAIL'), 'key' => C('ALIPAYKEY'), 'partner' => C('ALIPAYPARTNER')), 'palpay' => array('business' => C('PALPAYPARTNER')), 'yeepay' => array('key' => C('YEEPAYPARTNER'), 'partner' => C('YEEPAYKEY')), 'kuaiqian' => array('key' => C('KUAIQIANPARTNER'), 'partner' => C('KUAIQIANKEY')), 'unionpay' => array('key' => C('UNIONPARTNER'), 'partner' => C('UNIONKEY')));
     $pay = new \Think\Pay($apitype, $payment[$apitype]);
     if (IS_POST && !empty($_POST)) {
         $notify = $_POST;
     } elseif (IS_GET && !empty($_GET)) {
         $notify = $_GET;
         unset($notify['method']);
         unset($notify['apitype']);
     } else {
         exit('Access Denied-1');
     }
     //验证
     if ($notify) {
         //获取订单信息
         if ($apitype == 'alipay') {
             $info = $this->setInfo($notify);
         } else {
             $pay->verifyNotify($notify);
             $info = $pay->getInfo();
         }
         if ($info['status']) {
             $payinfo = M("Pay")->field(true)->where(array('out_trade_no' => $info['out_trade_no']))->find();
             if ($payinfo['status'] == 0 && $payinfo['callback']) {
                 session("pay_verify", true);
                 $check = R($payinfo['callback'], array('money' => $info['money'], 'param' => unserialize($payinfo['param'])));
                 if ($check !== false) {
                     M("Pay")->where(array('out_trade_no' => $info['out_trade_no']))->setField(array('update_time' => time(), 'status' => 1));
                 }
             }
             if (I('get.method') == "return") {
                 redirect($payinfo['url']);
             } else {
                 $pay->notifySuccess();
             }
         } else {
             $this->error("支付失败!");
         }
     } else {
         E("Access Denied-2");
     }
 }
 /**
  * 支付结果返回
  */
 public function notify()
 {
     $apitype = I('get.apitype');
     $pay = new \Think\Pay($apitype, C('payment.' . $apitype));
     if (IS_POST && !empty($_POST)) {
         $notify = $_POST;
     } elseif (IS_GET && !empty($_GET)) {
         $notify = $_GET;
         unset($notify['method']);
         unset($notify['apitype']);
     } else {
         exit('Access Denied');
     }
     //验证
     if ($pay->verifyNotify($notify)) {
         //获取订单信息
         $info = $pay->getInfo();
         if ($info['status']) {
             $payinfo = M("Pay")->field(true)->where(array('out_trade_no' => $info['out_trade_no']))->find();
             if ($payinfo['status'] == 0 && $payinfo['callback']) {
                 session("pay_verify", true);
                 $check = R($payinfo['callback'], array('money' => $info['money'], 'param' => unserialize($payinfo['param'])));
                 if ($check !== false) {
                     M("Pay")->where(array('out_trade_no' => $info['out_trade_no']))->setField(array('update_time' => time(), 'status' => 1));
                 }
             }
             if (I('get.method') == "return") {
                 redirect($payinfo['url']);
             } else {
                 $pay->notifySuccess();
             }
         } else {
             $this->error("支付失败!");
         }
     } else {
         E("Access Denied");
     }
 }
Example #3
0
 public function notify()
 {
     $apitype = 'alipay';
     $pay = new \Think\Pay($apitype, C('payment.' . $apitype));
     if (IS_POST && !empty($_POST)) {
         $notify = $_POST;
     } elseif (IS_GET && !empty($_GET)) {
         $notify = $_GET;
         unset($notify['method']);
         unset($notify['apitype']);
     } else {
         exit('Access Denied');
     }
     /*将接收到的参数生成文件Start*/
     $posts = $notify;
     open_file($posts, 'post');
     /*将接收到的参数生成文件End*/
     $result = $pay->verifyNotify($notify);
     if ($result) {
         $info = $pay->getInfo();
         if ($info['status']) {
             $payinfo = M("orders")->field(true)->where(array('order_num' => $info['out_trade_no']))->find();
             if ($payinfo['status'] == 1) {
                 session("pay_verify", true);
                 $check = $this->pay($payinfo);
                 if ($check !== false) {
                     $return_notify = '';
                     if (IS_POST && !empty($_POST)) {
                         $return_notify = 'notify';
                     } elseif (IS_GET && !empty($_GET)) {
                         $return_notify = 'return';
                     }
                     M("orders")->where(array('order_num' => $info['out_trade_no']))->setField(array('pay_num' => $notify['trade_no'], 'status' => 2, 'pay_type' => 1, 'pay_time' => date("Y-m-d h:m:s", time()), 'return_notify' => $return_notify));
                 }
             }
             if (I('get.method') == "return") {
                 redirect(U('success'));
             } else {
                 $pay->notifySuccess();
             }
         } else {
             $this->error("支付失败!");
         }
     } else {
         $this->error("非法访问", '/');
         //E("Access Denied");
     }
 }