Esempio n. 1
0
<?php

require_once dirname(dirname(dirname(__FILE__))) . '/app.php';
$_input_charset = 'utf-8';
$partner = $INI['alipay']['mid'];
$security_code = $INI['alipay']['sec'];
$sign_type = 'MD5';
$transport = 'http';
$alipay = new AlipayNotify($partner, $security_code, $sign_type, $_input_charset, $transport);
$verify_result = $alipay->notify_verify();
$out_trade_no = $_POST['out_trade_no'];
$trade_no = strval($_POST['trade_no']);
$total_fee = $_POST['total_fee'];
@(list($_, $order_id, $city_id, $_) = explode('-', $out_trade_no, 4));
if (Table::Fetch('pay', $out_trade_no)) {
    die('success');
}
if ($_ == 'charge') {
    if ($verify_result) {
        if ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') {
            @(list($_, $user_id, $create_time, $_) = explode('-', $out_trade_no, 4));
            ZFlow::CreateFromCharge($total_fee, $user_id, $create_time, 'alipay', $trade_no);
        }
    }
    die('success');
}
if ($verify_result) {
    //$guarantee = strtoupper($INI['alipay']['guarantee']) == 'Y';
    $guaranteewait = strtoupper($INI['alipay']['guaranteesuccess']) == 'N';
    $guarantee = $guaranteewait && $_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS';
    if ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS' || $guarantee) {
Esempio n. 2
0
 public function verifyNotify()
 {
     $alipayNotify = new AlipayNotify($this->alipay_config);
     return $alipayNotify->notify_verify();
 }
 /**
  *显示页.
  *
  *@param $code
  */
 public function return_code($code, $is_notify = 0, $equipment_type = "pc")
 {
     Configure::write('debug', 1);
     if ($is_notify == 1) {
         Configure::write('debug', 0);
     }
     $this->pageTitle = '支付完成' . ' - ' . $this->configs['shop_name'];
     $this->ur_heres[] = array('name' => $this->ld['checkout_center'], 'url' => '');
     $price_format = !empty($this->configs['price_format']) ? $this->configs['price_format'] : '¥%s元';
     $payment = $this->Payment->findbycode($code);
     //添加到model中
     if (empty($payment)) {
         $this->redirect('/');
     }
     $payment_config = unserialize($payment['Payment']['config']);
     $alipay_amount = 0;
     $trade_status = 0;
     if ($equipment_type == 'wap' && $code == 'alipay') {
         //手机支付宝支付回调
         $alipay_config = array();
         //合作身份者id,以2088开头的16位纯数字
         $alipay_config['partner'] = isset($payment_config['partner']) ? $payment_config['partner'] : '';
         //收款支付宝账号,一般情况下收款账号就是签约账号
         $alipay_config['seller_id'] = isset($payment_config['partner']) ? $payment_config['partner'] : '';
         //商户的私钥(后缀是.pen)文件相对路径
         $alipay_config['private_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_private_key.pem';
         //支付宝公钥(后缀是.pen)文件相对路径
         $alipay_config['ali_public_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_public_key.pem';
         //签名方式 不需修改
         $alipay_config['sign_type'] = strtoupper('RSA');
         //字符编码格式 目前支持 gbk 或 utf-8
         $alipay_config['input_charset'] = strtolower('utf-8');
         //ca证书路径地址,用于curl中ssl校验
         //请保证cacert.pem文件在当前文件夹目录中
         $alipay_config['cacert'] = ROOT . '/vendors/payments/alipaywap/cacert.pem';
         //访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
         $alipay_config['transport'] = 'http';
         $alipaySubmit_classfile = ROOT . "/vendors/payments/alipaywap/alipay_notify.class.php";
         include_once $alipaySubmit_classfile;
         $alipayNotify = new AlipayNotify($alipay_config);
         $verify_result = $alipayNotify->verifyReturn();
         $payment_api_log_id_str = isset($_REQUEST['out_trade_no']) ? $_REQUEST['out_trade_no'] : 0;
         $payment_api_log_id_arr = split("_", $payment_api_log_id_str);
         $payment_api_log_id = $payment_api_log_id_arr[0];
         //支付记录Id
         //		$payment_api_log_id=isset($_REQUEST['out_trade_no'])?$_REQUEST['out_trade_no']:0;
         $verify_result = $alipayNotify->verifyReturn();
         $alipay_amount = isset($_REQUEST['total_fee']) ? $_REQUEST['total_fee'] : 0;
         $alipay_trade_status = isset($_REQUEST['trade_status']) ? $_REQUEST['trade_status'] : '';
         $trade_status = 0;
         if ($alipay_trade_status == 'TRADE_FINISHED' || $alipay_trade_status == 'TRADE_SUCCESS') {
             $trade_status = 1;
         }
     } else {
         App::import('Vendor', 'payments/' . $payment['Payment']['code']);
         $response_payment = new $code();
         $response_payment->notify($payment_config);
         $payment_api_log_id = $response_payment->get_track_id();
         if ($code == 'authorizenet_aim' && isset($_SESSION['aim']) && !empty($_SESSION['aim'])) {
             $response_payment = unserialize(base64_decode($_SESSION['aim']));
             unset($_SESSION['aim']);
         }
         $trade_status = $response_payment->get_trade_status();
         if ($is_notify == 1) {
             $verify_result = $alipayNotify->notify_verify();
         } else {
             $verify_result = $response_payment->return_verify();
         }
     }
     $payment_api_log = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $payment_api_log_id)));
     if (empty($payment_api_log) && $is_notify == 0) {
         $this->flash('支付失败', '/pages/home', 60);
     } else {
         if (empty($payment_api_log) && $is_notify == 1) {
             echo "fail";
             die;
         }
     }
     if ($payment_api_log['PaymentApiLog']['type'] == '2') {
         //充值支付
         $back_url = '/users/deposit';
     } else {
         $amount_result = false;
         if (isset($response_payment)) {
             $amount_result = $response_payment->check_amount($payment_api_log['PaymentApiLog']['amount']);
         } else {
             if (isset($alipay_amount)) {
                 $amount_result = floatval($alipay_amount) == floatval($payment_api_log['PaymentApiLog']['amount']) ? true : false;
             }
         }
         //订单支付
         if (constant('Product') == 'AllInOne') {
             $this->loadModel('Order');
             $this->loadModel('OrderProduct');
             $this->loadModel('OrderAction');
             $orderp_info = $this->OrderProduct->find('first', array('conditions' => array('OrderProduct.order_id' => $payment_api_log['PaymentApiLog']['type_id'])));
             $foo = $this->Order->find('first', array('conditions' => array('Order.id' => $payment_api_log['PaymentApiLog']['type_id'])));
             if (!empty($foo)) {
                 $back_url = '/orders/view/' . $payment_api_log['PaymentApiLog']['type_id'];
             }
             $this->set('order_code', $foo['Order']['order_code']);
             $this->set('need_pay', $foo['Order']['total']);
             if ($foo['Order']['referer'] != 'unknow') {
             }
         }
     }
     if (isset($payment_api_log['PaymentApiLog']['is_paid'])) {
         //获得支付记录id号,判断支付状态
         if ($payment_api_log['PaymentApiLog']['is_paid'] == 1) {
             //已经标志完成了的
             $response['code'] = '101';
             $response['msg'] = '支付已完成';
         } else {
             //获取完成状态
             if ($trade_status == 1) {
                 if (!$amount_result) {
                     //判断金额
                     $response['code'] = '102';
                     //金额错误,
                     $response['msg'] = '系统错误';
                 } elseif ($verify_result) {
                     //判断签名
                     $response['code'] = '103';
                     //签名错误
                     $response['msg'] = '系统错误';
                 } else {
                     $response['code'] = '0';
                     $response['msg'] = '支付成功 ';
                     //.$response_payment->get_remark();
                 }
             } elseif ($status == 2) {
                 $response['code'] = '202';
                 $response['msg'] = '支付等待 ';
                 //.$response_payment->get_remark();
             } else {
                 $response['code'] = '104';
                 //付款状态错误
                 $response['msg'] = '系统错误';
             }
         }
     } else {
         $response['code'] = '100';
         //支付记录号不存在
         $response['msg'] = '系统错误';
     }
     if ($response['code'] == 0) {
         if ($payment_api_log['PaymentApiLog']['type'] == '2') {
             //充值支付
             $user_id = $payment_api_log['PaymentApiLog']['type_id'];
             $add_money = $payment_api_log['PaymentApiLog']['amount'];
             $user_Info = $this->User->find('first', array('conditions' => array('User.id' => $user_id)));
             if (!empty($user_Info)) {
                 $user_money = $user_Info['User']['balance'];
                 $user_money = $user_money + $add_money;
                 $user_data['id'] = $user_id;
                 $user_data['balance'] = $user_money;
                 $this->User->save($user_data);
                 $user_Info['User']['balance'] = $user_money;
                 $_SESSION['User'] = $user_Info;
                 $payment_api_log['is_paid'] = '1';
                 $this->PaymentApiLog->save($payment_api_log);
                 //添加资金日志
                 $BalanceLog['UserBalanceLog']['user_id'] = $user_id;
                 $BalanceLog['UserBalanceLog']['amount'] = $payment_api_log['PaymentApiLog']['amount'];
                 $BalanceLog['UserBalanceLog']['admin_user'] = $user_Info['User']['balance'];
                 $BalanceLog['UserBalanceLog']['admin_note'] = '';
                 $BalanceLog['UserBalanceLog']['system_note'] = '用户余额:' . $user_data['balance'] . '元';
                 $BalanceLog['UserBalanceLog']['log_type'] = 'B';
                 $BalanceLog['UserBalanceLog']['type_id'] = $payment_api_log['PaymentApiLog']['id'];
                 $BalanceLog['UserBalanceLog']['created'] = date('Y-m-d H:i:s', time());
                 $this->UserBalanceLog->save($BalanceLog);
             }
             $msg = '支付成功';
         } else {
             //订单支付
             if (constant('Product') == 'AllInOne') {
                 $this->loadModel('Order');
                 $this->loadModel('OrderProduct');
                 $this->update_order($payment_api_log, $orderp_info);
                 $this->ex_pay_to($foo, $orderp_info['OrderProduct']['product_name']);
                 $msg = $this->ld['your_order'] . ':' . $foo['Order']['order_code'] . '&nbsp;' . $this->ld['order_total'] . ':' . sprintf($price_format, $payment_api_log['PaymentApiLog']['amount']) . $this->ld['successful_to_pay'];
                 $this->OrderAction->saveAll(array('OrderAction' => array('order_id' => $foo['Order']['id'], 'from_operator_id' => 0, 'user_id' => $foo['Order']['user_id'], 'order_status' => 1, 'payment_status' => 2, 'shipping_status' => $foo['Order']['shipping_status'], 'action_note' => $this->ld['successful_to_pay'])));
                 $payment_api_log['is_paid'] = '1';
             }
         }
     } elseif ($response['code'] == '101') {
         if (constant('Product') == 'AllInOne') {
             $this->loadModel('Order');
             $this->loadModel('OrderProduct');
             $this->ex_pay_to($foo, $orderp_info['OrderProduct']['product_name']);
             $msg = $this->ld['your_order'] . ':' . $foo['Order']['order_code'] . '&nbsp;' . $this->ld['order_total'] . ':' . sprintf($price_format, $payment_api_log['PaymentApiLog']['amount']) . $this->ld['successful_to_pay'];
         }
     } else {
         $msg = $this->ld['failure_to_pay'];
     }
     $this->PaymentApiLog->save($payment_api_log);
     $this->Cookie->write('pay_type', $payment_api_log['PaymentApiLog']['payment_code']);
     $this->page_init();
     $this->set('response', $response);
     if ($is_notify == 0) {
         if (isset($back_url)) {
             $this->flash($msg, $back_url, 60);
         } else {
             $this->flash($msg, '/pages/home', 60);
         }
     } else {
         if ($response['code'] == 0 || $response['code'] == '101') {
             echo "success";
         } else {
             echo "fail";
         }
         die;
     }
 }
Esempio n. 4
0
 public function verifyNotify()
 {
     $notify = new AlipayNotify($this->partner, $this->key, $this->sign_type, $this->_input_charset, $this->transport);
     return $notify->notify_verify();
 }