/** * @brief 【重要】支付回调[异步] */ function server_callback() { //从URL中获取支付方式 $payment_id = IFilter::act(IReq::get('_id'), 'int'); $paymentInstance = Payment::createPaymentInstance($payment_id); if (!is_object($paymentInstance)) { die('fail'); } //初始化参数 $money = ''; $message = '支付失败'; $orderNo = ''; //执行接口回调函数 $callbackData = array_merge($_POST, $_GET); unset($callbackData['controller']); unset($callbackData['action']); unset($callbackData['_id']); $return = $paymentInstance->callback($callbackData, $payment_id, $money, $message, $orderNo); //支付成功 if ($return == 1) { //充值方式 if (stripos($orderNo, 'recharge_') !== false) { $tradenoArray = explode('_', $orderNo); $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0; if (payment::updateRecharge($recharge_no)) { $paymentInstance->notifyStop(); exit; } } else { $order_id = Order_Class::updateOrderStatus($orderNo); if ($order_id) { $paymentInstance->notifyStop(); exit; } } } else { $paymentInstance->notifyStop(); exit; } }
/** * @brief 【重要】支付回调[异步] */ function server_callback() { //从URL中获取支付方式 $payment_id = IFilter::act(IReq::get('_id'), 'int'); $paymentInstance = Payment::createPaymentInstance($payment_id); if (!is_object($paymentInstance)) { die('fail'); } //初始化参数 $money = ''; $message = '支付失败'; $orderNo = ''; //执行接口回调函数 $callbackData = array_merge($_POST, $_GET); unset($callbackData['controller']); unset($callbackData['action']); unset($callbackData['_id']); $return = $paymentInstance->serverCallback($callbackData, $payment_id, $money, $message, $orderNo); //支付成功 if ($return == 1) { //充值方式 if (stripos($orderNo, 'recharge') !== false) { $tradenoArray = explode('recharge', $orderNo); $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0; if (payment::updateRecharge($recharge_no)) { $paymentInstance->notifyStop(); exit; } } else { //读取批量订单付款 $cacheObj = new ICache('file'); $moreOrder = $cacheObj->get($orderNo); $moreOrder = $moreOrder ? explode(",", $moreOrder) : array($orderNo); foreach ($moreOrder as $key => $item) { $order_id = Order_Class::updateOrderStatus($item); if (!$order_id) { throw new IException("异步支付回调修改状态错误,订单ID:" . $order_id); } } $paymentInstance->notifyStop(); exit; } } else { $paymentInstance->notifyStop(); exit; } }
?> </a> <?php } ?> </span> </div> <div id="admin_left"> <ul class="submenu"></ul> <div id="copyright"></div> </div> <div id="admin_right"> <?php $paymentInstance = Payment::createPaymentInstance($this->paymentRow['id']); $paramData = JSON::decode($this->paymentRow['config_param']); ?> <script type="text/javascript" charset="UTF-8" src="<?php echo BASE_URL; ?> /runtime/_systemjs/editor/kindeditor-min.js"></script><script type="text/javascript" charset="UTF-8" src="<?php echo BASE_URL; ?> /runtime/_systemjs/editor/lang/zh_CN.js"></script><script type="text/javascript">window.KindEditor.options.uploadJson = "/index.php?controller=pic&action=upload_json";window.KindEditor.options.fileManagerJson = "/index.php?controller=pic&action=file_manager_json";</script> <div class="headbar"> <div class="position"><span>系统</span><span>></span><span>支付管理</span><span>></span><span>支付插件配置</span></div> </div> <div class="content_box"> <div class="content form_content">
/** * @brief 获取订单中的支付信息 M:必要信息; R表示店铺; P表示用户; * @param $payment_id int 支付方式ID * @param $type string 信息获取方式 order:订单支付;recharge:在线充值; * @param $argument mix 参数 * @return array 支付提交信息 */ public static function getPaymentInfo($payment_id, $type, $argument) { //最终返回值 $payment = array(); //初始化配置参数 $paymentInstance = Payment::createPaymentInstance($payment_id); $configParam = $paymentInstance->configParam(); foreach ($configParam as $key => $val) { $payment[$key] = ''; } //获取公共信息 $paymentRow = self::getPaymentById($payment_id, 'config_param'); if ($paymentRow) { $paymentRow = JSON::decode($paymentRow); foreach ($paymentRow as $key => $item) { $payment[$key] = $item; } } if ($type == 'order') { $orderIdArray = $argument; $M_Amount = 0; $M_OrderNO = array(); foreach ($orderIdArray as $key => $order_id) { //获取订单信息 $orderObj = new IModel('order'); $orderRow = $orderObj->getObj('id = ' . $order_id . ' and status = 1'); if (empty($orderRow)) { IError::show(403, '订单信息不正确,不能进行支付'); } //判断商品库存 $orderGoodsDB = new IModel('order_goods'); $orderGoodsList = $orderGoodsDB->query('order_id = ' . $order_id); foreach ($orderGoodsList as $key => $val) { if (!goods_class::checkStore($val['goods_nums'], $val['goods_id'], $val['product_id'])) { IError::show(403, '商品库存不足无法支付,请重新下单'); } } $M_Amount += $orderRow['order_amount']; $M_OrderNO[] = $orderRow['order_no']; } $payment['M_Remark'] = $orderRow['postscript']; $payment['M_OrderId'] = $orderRow['id']; $payment['M_OrderNO'] = $orderRow['order_no']; $payment['M_Amount'] = $M_Amount; //用户信息 $payment['P_Mobile'] = $orderRow['mobile']; $payment['P_Name'] = $orderRow['accept_name']; $payment['P_PostCode'] = $orderRow['postcode']; $payment['P_Telephone'] = $orderRow['telphone']; $payment['P_Address'] = $orderRow['address']; //订单批量结算缓存机制 $cacheObj = new ICache('file'); $cacheObj->set($payment['M_OrderNO'], join(",", $M_OrderNO)); } else { if ($type == 'recharge') { if (ISafe::get('user_id') == null) { IError::show(403, '请登录系统'); } if (!isset($argument['account']) || $argument['account'] <= 0) { IError::show(403, '请填入正确的充值金额'); } $rechargeObj = new IModel('online_recharge'); $reData = array('user_id' => ISafe::get('user_id'), 'recharge_no' => Order_Class::createOrderNum(), 'account' => $argument['account'], 'time' => ITime::getDateTime(), 'payment_name' => $argument['paymentName']); $rechargeObj->setData($reData); $r_id = $rechargeObj->add(); //充值时用户id跟随交易号一起发送,以"_"分割 $payment['M_OrderNO'] = 'recharge' . $reData['recharge_no']; $payment['M_OrderId'] = $r_id; $payment['M_Amount'] = $reData['account']; } } $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); //交易信息 $payment['M_Time'] = time(); $payment['M_Paymentid'] = $payment_id; //店铺信息 $payment['R_Address'] = isset($site_config['address']) ? $site_config['address'] : ''; $payment['R_Name'] = isset($site_config['name']) ? $site_config['name'] : ''; $payment['R_Mobile'] = isset($site_config['mobile']) ? $site_config['mobile'] : ''; $payment['R_Telephone'] = isset($site_config['phone']) ? $site_config['phone'] : ''; return $payment; }
/** * @brief 获取订单中的支付信息 M:必要信息; R表示店铺; P表示用户; * @param $payment_id int 支付方式ID * @param $type string 信息获取方式 order:订单支付;recharge:在线充值; * @param $argument mix 参数 * @return array 支付提交信息 */ public static function getPaymentInfo($payment_id, $type, $argument) { //最终返回值 $payment = array(); //初始化配置参数 $paymentInstance = Payment::createPaymentInstance($payment_id); $configParam = $paymentInstance->configParam(); foreach ($configParam as $key => $val) { $payment[$key] = ''; } //获取公共信息 $paymentRow = self::getPaymentById($payment_id, 'config_param'); if ($paymentRow) { $paymentRow = JSON::decode($paymentRow); foreach ($paymentRow as $key => $item) { $payment[$key] = $item; } } //print_r($payment);die; if ($type == 'order') { $order_id = $argument; //获取订单信息 $orderObj = new IModel('order'); $orderRow = $orderObj->getObj('id = ' . $order_id . ' and status = 1'); if (empty($orderRow)) { IError::show(403, '订单信息不正确,不能进行支付'); } //是商家的订单的话,收款信息为商家个人 if ($orderRow['seller_id'] > 0) { $configParam = $paymentInstance->sellerConfigParam($orderRow['seller_id']); if ($configParam == 0) { IError::show(403, '商家收款信息未填写,不能进行支付'); } else { //重写收款信息 foreach ($configParam as $key => $val) { $payment[$key] = $val; } } } $payment['M_Remark'] = $orderRow['postscript']; $payment['M_OrderId'] = $orderRow['id']; $payment['M_OrderNO'] = $orderRow['order_no']; $payment['M_Amount'] = $orderRow['order_amount']; //用户信息 $payment['P_Mobile'] = $orderRow['mobile']; $payment['P_Name'] = $orderRow['accept_name']; $payment['P_PostCode'] = $orderRow['postcode']; $payment['P_Telephone'] = $orderRow['telphone']; $payment['P_Address'] = $orderRow['address']; } else { if ($type == 'recharge') { if (ISafe::get('user_id') == null) { IError::show(403, '请登录系统'); } if (!isset($argument['account']) || $argument['account'] <= 0) { IError::show(403, '请填入正确的充值金额'); } $rechargeObj = new IModel('online_recharge'); $reData = array('user_id' => ISafe::get('user_id'), 'recharge_no' => Order_Class::createOrderNum(), 'account' => $argument['account'], 'time' => ITime::getDateTime(), 'payment_name' => $argument['paymentName']); $rechargeObj->setData($reData); $r_id = $rechargeObj->add(); //充值时用户id跟随交易号一起发送,以"_"分割 $payment['M_OrderNO'] = 'recharge_' . $reData['recharge_no']; $payment['M_OrderId'] = $r_id; $payment['M_Amount'] = $reData['account']; } } $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); //交易信息 $payment['M_Time'] = time(); $payment['M_Paymentid'] = $payment_id; //店铺信息 $payment['R_Address'] = isset($site_config['address']) ? $site_config['address'] : ''; $payment['R_Name'] = isset($site_config['name']) ? $site_config['name'] : ''; $payment['R_Mobile'] = isset($site_config['mobile']) ? $site_config['mobile'] : ''; $payment['R_Telephone'] = isset($site_config['phone']) ? $site_config['phone'] : ''; return $payment; }
/** * @brief 更新支付方式插件 */ function payment_update() { //获取Post数据 $payment_id = IFilter::act(IReq::get("id"), 'int'); $name = IFilter::act(IReq::get("name")); $poundage_type = IFilter::act(IReq::get("poundage_type"), 'int'); $poundage = IFilter::act(IReq::get("poundage"), 'float'); $order = IFilter::act(IReq::get("order"), 'int'); $note = IFilter::act(IReq::get('note'), 'text'); $status = IFilter::act(IReq::get('status'), 'int'); $client_type = IFilter::act(IReq::get('client_type'), 'int'); $config_param = array(); $paymentInstance = Payment::createPaymentInstance($payment_id); $configParam = $paymentInstance->configParam(); foreach ($configParam as $key => $val) { $config_param[$key] = IFilter::act(IReq::get($key)); } $config_param = JSON::encode($config_param); $updateData = array('name' => $name, 'poundage_type' => $poundage_type, 'poundage' => $poundage, 'order' => $order, 'note' => $note, 'status' => $status, 'config_param' => $config_param, 'client_type' => $client_type); $paymentDB = new IModel('payment'); $paymentDB->setData($updateData); $paymentDB->update('id = ' . $payment_id); //日志记录 $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "修改了支付方式", '修改的支付方式为:' . $name)); $this->redirect('payment_list'); }