private function func_pay($order_status) { // //自动通关代码 // $this->load->model('checkout/order'); // $order_info = $this->model_checkout_order->getOrder("201507150987851"); // $order_totals=$this->model_checkout_order->Gettotals($order_info["order_id"]); // $products=$this->model_checkout_order->getproducts($order_info["order_id"]); // $cardifo_query= $this->db->query("SELECT * FROM " . DB_PREFIX . "card where customer_id='".$order_info['customer_id']."'"); // $sign=new sign(); // $sign->creareorder($order_info, $order_totals, $products, $cardifo_query,$this->db); // exit; require_once "tenpay_class/PayResponseHandler.class.php"; /* 密钥 */ $key = $this->config->get('tenpay_key'); /* 创建支付应答对象 */ $resHandler = new PayResponseHandler(); $resHandler->setKey($key); $this->log->debug("Tenpay :: exciting PayResponseHandler."); //判断签名 if ($resHandler->isTenpaySign()) { $this->load->model('checkout/order'); // 获取订单号 $order_id = $resHandler->getParameter("sp_billno"); $this->log->debug(' order_id ' . $order_id); $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($order_id); if ($order_info) { $order_status_id = $order_info["order_status_id"]; $order_info = $this->model_checkout_order->getOrder($order_id); //交易单号 $transaction_id = $resHandler->getParameter("transaction_id"); //金额,以分为单位 $total_fee = $resHandler->getParameter("total_fee"); //支付结果 $pay_result = $resHandler->getParameter("pay_result"); if ("0" == $pay_result) { $this->log->debug(' pay_result ' . $pay_result); //------------------------------ //处理业务开始 //------------------------------ $this->log->debug(); $this->log->debug(' order_status_id ' . $this->config->get('tenpay_order_status_id') . ' order_status_id ' . $order_status_id); $this->model_checkout_order->confirm($order_id, $this->config->get('tenpay_order_status_id'), $transaction_id); //自动通关代码 $order_totals = $this->model_checkout_order->Gettotals($order_info["order_id"]); $products = $this->model_checkout_order->getproducts($order_info["order_id"]); $cardifo_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "card where customer_id='" . $order_info['customer_id'] . "'"); $sign = new sign(); $sign->creareorder($order_info, $order_totals, $products, $cardifo_query, $this->db); //注意交易单不要重复处理 //注意判断返回金额 //------------------------------ //处理业务完毕 //------------------------------ //调用doShow, 打印meta值跟js代码,告诉财付通处理成功,并在用户浏览器显示$show页面. $show = HTTPS_SERVER . 'index.php?route=checkout/success'; $resHandler->doShow($show); } else { //当做不成功处理 echo "<br/>" . iconv('utf-8', 'gbk', "支付失败") . "<br/>"; } } else { echo "<br/>" . iconv('utf-8', 'gbk', "支付失败") . "<br/>"; } } else { echo "<br/>" . iconv('utf-8', 'gbk', "认证签名失败") . "<br/>"; } }
//log文件路径 //$log_->log_result($log_name,"【接收到的notify通知】:\n".$xml."\n"); if ($notify->checkSign() == TRUE) { if ($notify->data["return_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【通信出错】:\n" . $xml . "\n"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【支付成功】:\n" . $xml . "\n"); } // ($notify->data["out_trade_no"], '17',$notify->data["transaction_id"]); $order = new ModelCheckoutOrder($registry); $order->confirm($notify->data["out_trade_no"], '17', $notify->data["transaction_id"]); echo "SUCCESS"; //自动通关代码 $order_info = $order->getOrder($notify->data["out_trade_no"]); $order_totals = $order->Gettotals($order_info["order_id"]); $products = $order->getproducts($order_info["order_id"]); $cardifo_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "card where customer_id='" . $order_info['customer_id'] . "'"); $sign = new sign(); $sign->creareorder($order_info, $order_totals, $products, $cardifo_query, $this->db); //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } else { echo "FAIL"; }
public function callback() { // $this->load->model('checkout/order'); // $order_info = $this->model_checkout_order->getOrder('201507150987851'); // $order_totals=$this->model_checkout_order->Gettotals($order_info["order_id"]); // $products=$this->model_checkout_order->getproducts($order_info["order_id"]); // $cardifo_query= $this->db->query("SELECT * FROM " . DB_PREFIX . "card where customer_id='".$order_info['customer_id']."'"); // $sign=new sign(); // $sign->creareorder($order_info, $order_totals, $products, $cardifo_query,$this->db); // exit; //trade_create_by_buyer 双接口 ,create_direct_pay_by_user 直接到帐,create_partner_trade_by_buyer 担保接口 $trade_type = $this->config->get('alipay_trade_type'); $this->log->debug("Alipay :: exciting callback function."); $oder_success = FALSE; $this->load->library('encryption'); $seller_email = $this->config->get('alipay_seller_email'); // 商家邮箱 $partner = $this->config->get('alipay_partner'); //合作伙伴ID $security_code = $this->config->get('alipay_security_code'); //安全检验码 $_input_charset = "utf-8"; //$_input_charset = "GBK"; $sign_type = "MD5"; $transport = 'http'; $alipay = new alipay_notify($partner, $security_code, $sign_type, $_input_charset, $transport); $verify_result = $alipay->notify_verify(); // Order status TODO we need a config page to set these. $order_status = array("Canceled" => 7, "Canceled_Reversal" => 9, "Chargeback" => 13, "Complete" => 5, "Denied" => 8, "Failed" => 10, "Pending" => 1, "Processing" => 2, "Refunded" => 11, "Reversed" => 12, "Shipped" => 3); $this->log->debug("Alipay :: trade_type " . $trade_type . " :: verify_result = " . $verify_result); if ($verify_result) { $order_id = $_POST['out_trade_no']; //$_POST['out_trade_no']; $lsh = $_POST['trade_no']; $trade_status = $_POST['trade_status']; $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($order_id); $this->log->debug("Alipay order_id :: " . $order_id); if ($order_info) { $order_status_id = $order_info["order_status_id"]; $this->log->debug("Alipay order_id :: " . $order_id . " order_status_id = " . $order_status_id . " , trade_status :: " . $trade_status); $this->log->debug("Alipay order_id :: Complete status = " . $order_status['Complete']); // 确定订单没有重复支付 if ($order_status_id != $order_status['Complete']) { $currency_code = 'CNY'; $total = $order_info['total']; $currency_value = $this->currency->getValue($currency_code); $amount = $total * $currency_value; $total = $_POST['total_fee']; //$_POST['total_fee']; // 确定支付和订单额度一致 $this->log->debug("Alipay total :: " . $_POST['total_fee'] . ",amount :: " . $amount); if ($total < $amount) { $this->log->debug("Alipay order_id :: " . $order_id . " total < amount, order_status_id = " . $order_status_id); $this->model_checkout_order->confirm($order_id, $order_status['Canceled'], $lsh); echo "success"; //自动通关代码 $order_totals = $this->model_checkout_order->Gettotals($order_info["order_id"]); $products = $this->model_checkout_order->getproducts($order_info["order_id"]); $cardifo_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "card where customer_id='" . $order_info['customer_id'] . "'"); $sign = new sign(); $sign->creareorder($order_info, $order_totals, $products, $cardifo_query, $this->db); } else { // 根据接口类型动态使用支付方法 if ($trade_type == 'trade_create_by_buyer') { $this->func_trade_create_by_buyer($order_id, $order_status_id, $order_status, $trade_status); echo "success"; } else { if ($trade_type == 'create_direct_pay_by_user') { $this->func_create_direct_pay_by_user($order_id, $order_status_id, $order_status, $trade_status); echo "success"; } else { if ($trade_type == 'create_partner_trade_by_buyer') { $this->func_create_partner_trade_by_buyer($order_id, $order_status_id, $order_status, $trade_status); echo "success"; } } } } } else { echo "fail"; } } else { $this->log->debug("Alipay No Order Found."); echo "fail"; } } }