public function Pin() { $pname = $_GET['type']; import('@.ORG.Payment.' . $pname); $p = new $pname(); if ($pname == "Paypal") { self::$Model = D("Orders"); $data['orders_status'] = "2"; /* if($p->validate_ipn()==true){ self::$Model->where("sn=".$p->ipn_data['item_number'])->save($data); }*/ if (strcasecmp($_POST['payer_status'], 'verified') == 0) { if (!empty($_POST['item_number'])) { self::$Model->where("sn=" . $_POST['item_number'])->save($data); //赠送用户积分 give_member_points($_POST['item_number']); } } } if ($pname == "Alipay") { $alipay = new alipay_notify(GetValue($pname . "_" . "partner"), GetValue($pname . "_security_code"), "MD5", GetValue($pname . "_" . "input_charset")); $verify_result = $alipay->notify_verify(); //计算得出通知验证结果 if ($verify_result) { $dingdan = $_POST['out_trade_no']; //获取支付宝传递过来的订单号 $total = $_POST['price']; //获取支付宝传递过来的总价格 if ($_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS' || $_GET['trade_status'] == 'TRADE_FINISHED') { //担保交易和即时到账 self::$Model = D("Orders"); $data['orders_status'] = "2"; self::$Model->where("sn=" . $dingdan)->save($data); give_member_points($_POST['item_number']); } } } }
'说明: '以下代码只是方便商户测试,提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 '该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 */ require_once "classes/alipay_notify.php"; empty($_POST) && ($_POST =& $_GET); require_once dirname(dirname(__FILE__)) . '/pay_base.php'; $pay = new pay_base('alipay'); $pay->by = 'orders'; $pay->order_sn = $_GET['out_trade_no']; if (!$pay->getData()) { //log_result ("order_failed"); exit("fail"); } $alipay = new alipay_notify($pay->partner, $pay->keyt, 'MD5', $mcharset, 'http'); $verify_result = $alipay->notify_verify(); if ($verify_result) { //认证合格 //获取支付宝的反馈参数 $dingdan = $_POST['out_trade_no']; //获取支付宝传递过来的订单号 $total = $_POST['total_fee']; //获取支付宝传递过来的总价格 /* $receive_name =$_POST['receive_name']; //获取收货人姓名 $receive_address =$_POST['receive_address']; //获取收货人地址 $receive_zip =$_POST['receive_zip']; //获取收货人邮编 $receive_phone =$_POST['receive_phone']; //获取收货人电话 $receive_mobile =$_POST['receive_mobile']; //获取收货人手机 获取支付宝反馈过来的状态,根据不同的状态来更新数据库
public function verifyNotifyUrl() { /*{{{*/ $alipay = new alipay_notify($this->partner, $this->security_code, $this->sign_type, $this->_input_charset, 'http'); return $alipay->notify_verify(); }
public function callback_international() { //trade_create_by_buyer 双接口 ,create_direct_pay_by_user 直接到帐,create_partner_trade_by_buyer 担保接口 log_result("Alipay :: exciting callback_international function."); $oder_success = FALSE; $this->load->library('encryption'); $trade_type = "alipay.trade.direct.forcard.pay"; $seller_email = "*****@*****.**"; // 商家邮箱 $partner = "2088011357497434"; //合作伙伴ID $security_code = "qo58xp4g1ywibtiiyns1gftw5mbv5rs3"; //安全检验码 $_input_charset = "utf-8"; $sign_type = "MD5"; $transport = 'http'; $alipay = new alipay_notify($partner, $security_code, $sign_type, $_input_charset, $transport); $verify_result = $alipay->notify_verify(); $order_status = array("paying" => 1, "payed" => 2, "shiping" => 3, "shipped" => 4, "stayin" => 5, "storage" => 6); if ($verify_result) { $order_id = $_POST['out_trade_no']; //$_POST['out_trade_no']; $trade_status = $_POST['trade_status']; $total_fee = $_POST['total_fee']; //log_result("order_id:" . $order_id . "trade_status:" . $trade_status . "total_fee:" . $total_fee); if (strpos($order_id, 'cz')) { if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { $order_id_array = explode("-", $order_id); $order_id = $order_id_array[1]; $customer_id = $order_id_array[2]; //log_result("alipay_international_cz this is test order_id:" . $order_id . "this is test customer_id". $customer_id); $data = array('state' => 1, 'successtime' => time(), 'remark' => "OK", 'rid' => $order_id); $this->load->model('account/rechargerecord'); $this->load->model('account/customer'); $this->model_account_rechargerecord->updateRechargerecord($data); $money = $this->model_account_rechargerecord->getMoneybyid($order_id); $this->model_account_customer->editBalance($money, $customer_id); echo "success"; } else { echo "fail"; } } else { if (strpos($order_id, 'yd')) { $this->load->model('order/order'); $sendorder_id_array = explode("-", $order_id); $sendorder_id = $sendorder_id_array[1]; $customer_id = $sendorder_id_array[2]; //log_result("sendorder0".$sendorder_id_array[0]."-sendorder1".$sendorder_id_array[1]."-sendorder2".$sendorder_id_array[2]); //log_result("kennewei".$sendorder_id); $sendorder_array = explode(",", $sendorder_id); //$sendorder_array = array_filter($sendorder_array); $sendorder_info = $this->model_order_order->getSendorderById($sendorder_array[0]); if ($sendorder_info['state'] < 1) { if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { $this->model_order_order->UpdateSendorderPay($sendorder_array); //插入消费记录 $this->load->model('account/customer'); $customer_info = $this->model_account_customer->getCustomer($customer_id); $first_name = $customer_info['firstname']; $accountmoney = $customer_info['money']; $data2 = array('uid' => $customer_id, 'firstname' => $first_name, 'payname' => '支付宝支付', 'money' => -$total_fee, 'accountmoney' => $accountmoney, 'remark' => "提交运单费用,运单ID:" . $sendorder_id, 'remarktype' => 2, 'remarkdetails' => $sendorder_id, 'addtime' => time()); //log_result("firstname".$first_name . "---money".$total_fee . "---accountmoney".$accountmoney ."---sendorder_id".$value); $this->load->model('account/record'); $this->model_account_record->addRecord($data2); echo "success"; } else { echo "fail"; } } else { echo "fail"; } } else { $this->load->model('checkout/order'); $order_customer = explode("-", $order_id); $order_id = $order_customer[0]; $customer_id = $order_customer[1]; $orders_id = explode(",", $order_id); $order_id = $orders_id[0]; $order_info = $this->model_checkout_order->getOrder($order_id); //log_result("Alipay order_id :: " . $order_id); if ($order_info) { $order_status_id = $order_info["order_status_id"]; //log_result("Alipay order_id :: " . $order_id . " order_status_id = " . $order_status_id . " , trade_status :: " . $trade_status); //log_result("Alipay order_id :: Complete status = " . $order_status['Complete']); // 确定订单没有重复支付 if ($order_status_id < $order_status['payed']) { // 根据接口类型动态使用支付方法,默认使用直接到账接口类型 $this->func_create_direct_pay_by_user($orders_id, $order_status_id, $order_status, $trade_status); //插入消费记录 $this->load->model('account/customer'); $customer_info = $this->model_account_customer->getCustomer($customer_id); $first_name = $customer_info['firstname']; $accountmoney = $customer_info['money']; $order_record = implode(",", $orders_id); $data1 = array('uid' => $customer_id, 'firstname' => $first_name, 'payname' => '支付宝支付', 'money' => -$total_fee, 'accountmoney' => $accountmoney, 'remark' => "提交代购订单费用,订单ID:" . $order_record, 'remarktype' => 1, 'remarkdetails' => $order_record, 'addtime' => time()); $this->load->model('account/record'); $this->model_account_record->addRecord($data1); echo "success"; } else { echo "fail"; } } else { //log_result("Alipay No Order Found."); echo "fail"; } } } } }
public function callback() { //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']; $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']); echo "success"; } 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"; } } }
///////////页面功能说明/////////////// //创建该页面文件时,请留心该页面文件中无任何HTML代码及空格。 //该页面不能在本机电脑测试,请到服务器上做测试。请确保外部可以访问该页面。 //该页面调试工具请使用写文本函数log_result,该函数已被默认开启,见alipay_notify.php中的函数notify_verify //WAIT_BUYER_PAY(表示买家已在支付宝交易管理中产生了交易记录,但没有付款); //WAIT_SELLER_SEND_GOODS(表示买家已在支付宝交易管理中产生了交易记录且付款成功,但卖家没有发货); //WAIT_BUYER_CONFIRM_GOODS(表示卖家已经发了货,但买家还没有做确认收货的操作); //TRADE_FINISHED(表示买家已经确认收货,这笔交易完成); //该服务器异步通知页面面主要功能是:防止订单未更新。如果没有收到该页面打印的 success 信息,支付宝会在24小时内按一定的时间策略重发通知 ///////////////////////////////////// require_once("class/alipay_notify.php"); require_once("alipay_config.php"); $alipay = new alipay_notify($partner,$key,$sign_type,$_input_charset,$transport); //构造通知函数信息 $verify_result = $alipay->notify_verify(); //计算得出通知验证结果 if($verify_result) {//验证成功 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 $dingdan = $_POST['out_trade_no']; //获取支付宝传递过来的订单号 $total = $_POST['price']; //获取支付宝传递过来的总价格 if($_POST['trade_status'] == 'WAIT_BUYER_PAY') { //该判断表示买家已在支付宝交易管理中产生了交易记录,但没有付款 //判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
function notify_f() { $sn = $this->trans_lib->safe("sn"); $pass = $this->trans_lib->safe("pass"); $paycode = "alipay"; $rs = $this->payment_m->get_one_code($paycode); $order_rs = $this->checkout_m->get_one_sn($sn); $f_rs = $this->payment_m->get_fields($rs["id"]); $data = array(); $id = $order_rs["id"]; include_once LIBS . "payment/alipay_notify.php"; //加载alipay_notify操作类 $alipay = new alipay_notify($f_rs["partner"], $f_rs["code"], "MD5", $f_rs["charset"], $f_rs["transport"]); $tmp_array = array(); $tmp_array[] = $this->config->c; $tmp_array[] = $this->config->f; $tmp_array[] = "sn"; $tmp_array[] = "pass"; $verify_result = $alipay->notify_verify($tmp_array); if (!$verify_result) { exit("fail"); } $payment_status = $this->trans_lib->safe("trade_status"); if ($payment_status == "WAIT_BUYER_PAY") { exit("success"); } if ($payment_status == "TRADE_FINISHED" || $payment_status == "TRADE_SUCCESS") { $data["pay_status"] = 1; $data["pay_price"] = $this->trans_lib->safe("total_fee"); $data["pay_currency"] = $f_rs["currency"]; $data["pay_type"] = $rs["id"]; $data["pay_date"] = $this->system_time; $data["pay_code"] = $this->trans_lib->safe("trade_no"); $this->payment_m->update_order($id, $data); $this->load_lib("email"); $this->email_lib->order_update($id); //通知客户订单信息 $this->email_lib->order_update_admin($id); //通知管理员有订单信息 } exit("success"); }
public function callback() { $oder_success = FALSE; // 获取商家信息 $this->load->library('encryption'); $seller_email = $this->config->get('alipay_direct_seller_email'); // 商家邮箱 $security_code = $this->config->get('alipay_direct_security_code'); //安全检验码 $partner = $this->config->get('alipay_direct_partner'); //合作伙伴ID $_input_charset = "utf-8"; //字符编码格式 目前支持 GBK 或 utf-8 $sign_type = "MD5"; //加密方式 系统默认(不要修改) $transport = 'http'; //访问模式,你可以根据自己的服务器是否支持ssl访问而选择http以及https访问模式(系统默认,不要修改) log_result("callback start."); // 获取支付宝返回的数据 $alipay = new alipay_notify($partner, $security_code, $sign_type, $_input_charset, $transport); $verify_result = $alipay->notify_verify(); if ($verify_result) { //认证合格 //获取支付宝的反馈参数 $order_id = $_POST['out_trade_no']; //获取支付宝传递过来的订单号 $this->load->model('checkout/order'); // 获取订单ID $order_info = $this->model_checkout_order->getOrder($order_id); // 存储订单至系统数据库 if ($order_info) { $order_status_id = $order_info["order_status_id"]; $alipay_direct_order_status_id = $this->config->get('alipay_direct_order_status_id'); $alipay_direct_wait_buyer_pay = $this->config->get('alipay_direct_wait_buyer_pay'); $alipay_direct_wait_buyer_confirm = $this->config->get('alipay_direct_wait_buyer_confirm'); $alipay_direct_trade_finished = $this->config->get('alipay_direct_trade_finished'); $alipay_direct_wait_seller_send = $this->config->get('alipay_direct_wait_seller_send'); if (1 > $order_status_id) { log_result('order->confirm order_status_id=' . $order_status_id); $this->model_checkout_order->confirm($order_id, $alipay_direct_order_status_id); } // 避免处理已完成的订单 log_result('order_id=' . $order_id . ' order_status_id=' . $order_status_id); if ($order_status_id != $alipay_direct_trade_finished) { log_result("No finished."); // 获取原始订单的总额 $currency_code = $this->config->get('alipay_direct_currency_code'); //人民币代号(CNY) $total = $order_info['total']; log_result('total=' . $total); if ($currency_code == '') { $currency_code = 'CNY'; } $currency_value = $this->currency->getValue($currency_code); log_result('currency_value=' . $currency_value); $amount = $total * $currency_value; $amount = number_format($amount, 2, '.', ''); log_result('amount=' . $amount); // 支付宝付款金额 $total = $_POST['total_fee']; // 获取支付宝传递过来的总价格 log_result('total_fee=' . $total); /* $receive_name =$_POST['receive_name']; //获取收货人姓名 $receive_address =$_POST['receive_address']; //获取收货人地址 $receive_zip =$_POST['receive_zip']; //获取收货人邮编 $receive_phone =$_POST['receive_phone']; //获取收货人电话 $receive_mobile =$_POST['receive_mobile']; //获取收货人手机 */ /* 获取支付宝反馈过来的状态,根据不同的状态来更新数据库 //TRADE_FINISHED(表示交易已经成功结束,通用即时到帐反馈的交易状态成功标志); //TRADE_SUCCESS(表示交易已经成功结束,高级即时到帐反馈的交易状态成功标志); */ log_result("trade_status:" . $_POST['trade_status']); if ($_POST['trade_status'] == 'WAIT_BUYER_PAY') { log_result('==alipay_direct_wait_buyer_pay=='); //该判断表示买家已在支付宝交易管理中产生了交易记录,但没有付款 //判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 if ($order_status_id != $alipay_direct_trade_finished && $order_status_id != $alipay_direct_wait_buyer_confirm && $order_status_id != $alipay_direct_wait_seller_send) { $this->model_checkout_order->update($order_id, $alipay_direct_wait_buyer_pay); echo "success - alipay_direct_wait_buyer_pay"; //请不要修改或删除 //调试用,写文本函数记录程序运行情况是否正常 log_result('success - alipay_direct_wait_buyer_pay'); } } else { if ($_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS') { log_result('==alipay_direct_wait_seller_send=='); //该判断表示买家已在支付宝交易管理中产生了交易记录且付款成功,但卖家没有发货 //判断该笔订单是否在商户网站中已经做过处理(可参考“集成教程”中“3.4返回数据处理”) //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 if ($order_status_id != $alipay_direct_trade_finished && $order_status_id != $alipay_direct_wait_buyer_confirm) { $this->model_checkout_order->update($order_id, $alipay_direct_wait_seller_send); echo "success - alipay_direct_wait_seller_send"; //请不要修改或删除 //调试用,写文本函数记录程序运行情况是否正常 log_result('success - alipay_direct_wait_seller_send'); } } else { if ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') { //交易成功结束 //这里放入你自定义代码,比如根据不同的trade_status进行不同操作 $this->model_checkout_order->update($order_id, $alipay_direct_trade_finished); echo "success - alipay_direct_trade_finished"; //请不要修改或删除 //调试用,写文本函数记录程序运行情况是否正常 log_result('success - alipay_direct_trade_finished'); log_result("finished."); } else { echo "fail"; log_result("verify_failed"); } } } } } } }