public static function msg($id_cart, $code = "null", $msg = "null") { $log = new Paylog(); $log->id_cart = (int) $id_cart; $log->code = pSQL($code); $log->msg = pSQL($msg); $log->add_date = date("Y-m-d H:i:s"); $log->add(); }
function verify_notify($order_info, $strict = false) { if (!defined('WXAPPID')) { define("WXAPPID", $this->_config['appid']); define("WXMCHID", $this->_config['mchid']); define("WXKEY", $this->_config['key']); define("WXAPPSECRET", $this->_config['appsecret']); define("WXCURL_TIMEOUT", 30); define('WXNOTIFY_URL', $this->_create_notify_url($order_info['order_id'])); define('WXJS_API_CALL_URL', $this->_create_notify_url($order_info['order_id'])); define('WXSSLCERT_PATH', ROOT_PATH . '/data/cacert/1/apiclient_cert.pem'); define('WXSSLKEY_PATH', ROOT_PATH . '/data/cacert/1/apiclient_key.pem'); } require_once dirname(__FILE__) . "/WxPayPubHelper/WxPayPubHelper.php"; $notify = new Notify_pub(); $xml = $order_info['xml']; $notify->saveData($xml); if ($notify->checkSign() == true) { if ($notify->data["return_code"] == "FAIL") { return false; } else { $total_fee = $notify->data["total_fee"]; $out_trade_no = $notify->data["out_trade_no"]; if ($order_info['out_trade_sn'] != $out_trade_no) { /* 通知中的订单与欲改变的订单不一致 */ Paylog::error("price_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('order_inconsistent'); return false; } if ($order_info['order_amount'] * 100 != $total_fee) { /* 支付的金额与实际金额不一致 */ Paylog::error("price_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('price_inconsistent'); return false; } Paylog::info("success,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); return array('target' => ORDER_ACCEPTED); } } else { Paylog::info("sign_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('sign_inconsistent'); return false; } }
/** * 返回通知结果 * * @author Garbin * @param array $order_info * @param bool $strict * @return array */ function verify_notify($order_info, $strict = false) { if (empty($order_info)) { $this->_error('order_info_empty'); return false; } /* 初始化所需数据 */ $notify = $this->_get_notify(); /* 验证来路是否可信 */ if ($strict) { /* 严格验证 */ $verify_result = $this->_query_notify($notify['notify_id']); if (!$verify_result) { /* 来路不可信 */ Paylog::info("notify_unauthentic,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('notify_unauthentic'); return false; } } /* 验证通知是否可信 */ $sign_result = $this->_verify_sign($notify); if (!$sign_result) { /* 若本地签名与网关签名不一致,说明签名不可信 */ Paylog::info("sign_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('sign_inconsistent'); return false; } /*----------通知验证结束----------*/ /*----------本地验证开始----------*/ /* 验证与本地信息是否匹配 */ /* 这里不只是付款通知,有可能是发货通知,确认收货通知 */ if ($order_info['out_trade_sn'] != $notify['out_trade_no']) { /* 通知中的订单与欲改变的订单不一致 */ Paylog::info("order_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); $this->_error('order_inconsistent'); return false; } if ($order_info['order_amount'] != $notify['total_fee']) { Paylog::error("price_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); /* 支付的金额与实际金额不一致 */ $this->_error('price_inconsistent'); return false; } //至此,说明通知是可信的,订单也是对应的,可信的 Paylog::info("success,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}"); /* 按通知结果返回相应的结果 */ switch ($notify['trade_status']) { case 'WAIT_SELLER_SEND_GOODS': //买家已付款,等待卖家发货 $order_status = ORDER_ACCEPTED; break; case 'WAIT_BUYER_CONFIRM_GOODS': //卖家已发货,等待买家确认 $order_status = ORDER_SHIPPED; break; case 'TRADE_FINISHED': //交易结束 //交易结束 case 'TRADE_SUCCESS': // 交易成功 if ($order_info['status'] == ORDER_PENDING) { /* 如果是等待付款中,则说明是即时到账交易,这时将状态改为已付款 */ $order_status = ORDER_ACCEPTED; } else { /* 说明是第三方担保交易,交易结束 */ $order_status = ORDER_FINISHED; } break; case 'TRADE_CLOSED': //交易关闭 $order_status = ORDER_CANCLED; break; default: $this->_error('undefined_status'); return false; break; } switch ($notify['refund_status']) { case 'REFUND_SUCCESS': //退款成功,取消订单 $order_status = ORDER_CANCLED; break; } return array('target' => $order_status); }
$flag = $httpClient->post($path, $data); $status = $httpClient->getStatus(); if ($flag === true) { $result = $httpClient->getContent(); } else { $error = $httpClient->getError(); } } else { Paylog::msg($cart->id, "300", "尝试curl和fsockopen提交定单到速汇通,均失败!"); die(json_encode(array("isError" => "YES", "msg" => "300"))); } } if ($status == 200 && $result) { parse_str($result, $rData); $systemResponse = new System_Response(); Paylog::msg($cart->id, $rData['Succeed'], $systemResponse->getMsg($rData['Succeed'])); if ($rData['Succeed'] == "9") { die(json_encode(array("isError" => "YES", "msg" => "401,Payment Failed!"))); } //判断是否支付成功 $isSystemCode = $systemResponse->isSucceed($rData['Succeed']); if ($isSystemCode === true) { $sht = Module::Hook($data['paymentid']); $sht->validateOrder($cart, $sht->id, 2); $redirct = $link->getPage('PaymentResultView') . "?id_order=" . $sht->currentOrder . "&id_module=" . $sht->id . "&toke_open=" . $data['order_token']; die(json_encode(array("isError" => "NO", "redirct" => $redirct, "msg" => 'Transaction has been successfully,the page will redirect after 3 seconds,If there is no redirect, please click <a href="' . $redirct . '">here</a>'))); } //检测是为不配置错误 $isSystemCode = $systemResponse->isSystem($rData['Succeed']); if ($isSystemCode === true) { die(json_encode(array("isError" => "YES", "msg" => "Payment failed!, Response Code: {$rData['Succeed']},Please check your information or contact the technician")));
$hashValue = $payResultJson['data']['hashValue']; $signkey = trim(Configuration::get('NEWORDER_MERCHANT_KEY')); $signSrc = $signkey . $acctNo . $orderNo . $pkid . $succeed . $result . $currCode; $signInfo = szComputeMD5Hash($signSrc); if ($hashValue == $signInfo) { if ($succeed == "00") { Paylog::msg($cart->id, "00", "支付成功"); $pay = Module::Hook($paymentid); $pay->validateOrder($cart, $pay->id, 2); $order = new Order($pay->currentOrder); $redirct = $link->getPage('PaymentResultView') . "?id_order=" . $pay->currentOrder . "&id_module=" . $paymentid . "&toke_open=" . md5($order->id_user); die(json_encode(array("isError" => "NO", "redirct" => $redirct, "msg" => 'Transaction has been successfully,the page will redirect after 3 seconds,If there is no redirect, please click <a href="' . $redirct . '">here</a>'))); } else { //信息不是从支付服务器返回 Paylog::msg($cart->id, "202", "返回状态码是成功,但succeed不为00" . (empty($errorMessage) ? $messages["errorNote"] : str_replace("@@@", $errorMessage, $messages["payFailure"]))); die(json_encode(array("isError" => "YES", "isPendingPayment" => $isPendingPayment, "msg" => "Payment failed!, Response Code: 202," . (empty($errorMessage) ? $messages["errorNote"] : str_replace("@@@", $errorMessage, $messages["payFailure"]))))); } } else { //信息不是从支付服务器返回 Paylog::msg($cart->id, "203", "返回状态码是成功的,但hash验证失败,信息可能不是从服务器传回"); die(json_encode(array("isError" => "YES", "msg" => "Payment failed!, Response Code:203"))); } } else { Paylog::msg($cart->id, "204", empty($errorMessage) ? $messages["errorNote"] : str_replace("@@@", $errorMessage, $messages["payFailure"])); die(json_encode(array("isError" => "YES", "isPendingPayment" => $isPendingPayment, "msg" => "Payment failed!, Response Code: 204," . (empty($errorMessage) ? $messages["errorNote"] : str_replace("@@@", $errorMessage, $messages["payFailure"]))))); } function _getFormatedAddress(Address $the_address, $line_sep, $fields_style = array()) { return AddressFormat::generateAddress($the_address, array('avoid' => array()), $line_sep, ' ', $fields_style); } }
<?php if (intval(Tools::getRequest('delete')) > 0) { $object = new Paylog(intval(Tools::getRequest('delete'))); if (Validate::isLoadedObject($object)) { $object->delete(); } if (is_array($object->_errors) and count($object->_errors) > 0) { $errors = $object->_errors; } else { echo '<div class="conf">删除对象成功</div>'; } } elseif (Tools::isSubmit('subDelete')) { $select_cat = Tools::getRequest('categoryBox'); $paylog = new Paylog(); if ($paylog->deleteSelection($select_cat)) { echo '<div class="conf">删除对象成功</div>'; } } $table = new UIAdminTable('paylog', 'Paylog', 'id_pay'); $table->header = array(array('sort' => false, 'isCheckAll' => 'itemsBox[]'), array('name' => 'id_pay', 'title' => 'ID', 'width' => '80px', 'filter' => 'string', 'edit' => false), array('name' => 'code', 'title' => '状态码', 'filter' => 'string', 'edit' => false), array('name' => 'msg', 'title' => '状态信息', 'filter' => 'string', 'edit' => false)); $filter = $table->initFilter(); $orderBy = isset($_GET['orderby']) ? Tools::G('orderby') : 'id_pay'; $orderWay = isset($_GET['orderway']) ? Tools::G('orderway') : 'desc'; $limit = $cookie->getPost('pagination') ? $cookie->getPost('pagination') : '50'; $p = Tools::G('p') ? Tools::G('p') == 0 ? 1 : Tools::G('p') : 1; $result = Paylog::loadData($p, $limit, $orderBy, $orderWay, $filter); if (isset($errors)) { UIAdminAlerts::MError($errors); } $breadcrumb = new UIAdminBreadcrumb();