public function pac_message_receiver() { $content = Req::post("content"); if (!isset($content)) { $this->returnXML("false", "S09", "返回报文为空"); } $signature = Req::post("data_digest"); if (!isset($signature)) { $this->returnXML("false", "S09", "返回报文为空"); } Tiny::log("异步审批结果回执信息【content:" . $content . "】data_digest【" . $signature . "】"); // 测试密钥 $aeskey = base64_decode($this->jkf['aes_key']); //AES解密,采用ECB模式 $aes = new Crypt_AES(CRYPT_MODE_ECB); //设置AES密钥 $aes->setKey($aeskey); //解密AES密文 $plaintext = $aes->decrypt(base64_decode($content)); //测试rsa公钥 $publickey = $this->jkf['public_key']; $rsa = new Crypt_RSA(); //设置RSA签名模式 CRYPT_RSA_SIGNATURE_PSS or CRYPT_RSA_SIGNATURE_PKCS1 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1); //使用RSA公钥验证签名 $rsa->loadKey(base64_decode($publickey)); //签名通过 if ($rsa->verify($plaintext, base64_decode($signature))) { $contentXML = simplexml_load_string($plaintext); $businessType = (string) $contentXML->head->businessType; $model = new GatewayModel(); if ($businessType == "RESULT") { $model->insertResult($contentXML, "1"); } else { if ($businessType == "PRODUCT_RECORD") { $model->insertExamineResult($contentXML); } } $this->returnXML(); } else { $this->returnXML("false", "S02", "非法的数字签名"); } }
public function callback() { //从URL中获取支付方式 $payment_id = Filter::int(Req::get('payment_id')); $payment = new Payment($payment_id); $paymentPlugin = $payment->getPaymentPlugin(); if (!is_object($paymentPlugin)) { $msg = array('type' => 'fail', 'msg' => '支付方式不存在!'); $this->redirect('/index/msg', false, $msg); exit; } //初始化参数 $money = ''; $message = '支付失败'; $orderNo = ''; //执行接口回调函数 $callbackData = Req::args(); //array_merge($_POST,$_GET); unset($callbackData['con']); unset($callbackData['act']); unset($callbackData['payment_id']); unset($callbackData['tiny_token_redirect']); $return = $paymentPlugin->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; $recharge_id = Order::recharge($recharge_no, $payment_id, $callbackData); if ($recharge_id) { //$this->redirect("/ucenter/account/$recharge_id"); $model = new Model('recharge'); $obj = $model->where("id=" . $recharge_id . ' and status=1')->find(); if ($obj) { $msg = array('type' => 'success', 'msg' => '充值成功!', 'content' => '充值编号:' . $recharge_no . ',充值方式:' . $obj['payment_name'], 'redirect' => '/ucenter/account'); $this->redirect('/index/msg', true, $msg); } exit; } $msg = array('type' => 'fail', 'msg' => '支充值失败!'); $this->redirect('/index/msg', false, $msg); exit; } else { $payment_plugin = $payment->getPayment(); //货到付款的处理 if ($payment_plugin['class_name'] == 'received') { $model = new Model("order"); $order = $model->where("order_no='" . $orderNo . "'")->find(); if (!empty($order)) { $model->where("order_no='" . $orderNo . "'")->data(array('payment' => $payment_id))->update(); $this->redirect("/simple/order_completed/order_id/" . $order['id']); exit; } } else { // 海关发送报文位置 待定 // todo SKM 海关发送报文位置 待定 // todo 更新订单表中数据 尤其是状态 // $strXML $order_id = Order::updateStatus($orderNo, $payment_id, $callbackData); if ($order_id) { $erpmsg = ApiToErp::callerporder($orderNo); //SKM-SMS 支付成功 发送支付完成信息 在Order.php 里面的方法处理 updateStatus //SKM-CUSTOMS 支付完成 把订单信息发送给 海关一步达系统 下面代码仅用于国际支付宝业务 $orderNo = $callbackData['out_trade_no']; //$money = $callbackData['total_fee']; $trade_no = $callbackData['trade_no']; $conf = array('payNumber' => $trade_no); // 交易号 //$orderNo = "88"; //订单编号 callbackData 中的out_trade_no // 导出订单数据,以XML文件格式 $order_export_inst = new OrderExport(); $ret = $order_export_inst->toXML($orderNo, $conf); if (isset($ret['status']) && $ret['status'] == 1) { $strXML = $ret['data']; // TEST-LOG //$strDate = date("Y-m-d-h-i-s"); //file_put_contents("/var/www/html/quanpin/logs/gateway_$strDate.xml", $strXML); // 发送XML数据到海关 $gateway_inst = new GatewayModel(); $gateway_inst->callWebService($strXML, "IMPORTORDER"); //Tiny::log(__FILE__.__LINE__."---ALIPAY----".$strXML); $data = array('tax_api_status' => 1); Order::updateStatusByNo($orderNo, $data); } else { $message = '支付成功, 发送海关数据失败,请从新发送'; // 这部分信息保存到数据库中 $data = array('tax_api_status' => 0); Order::updateStatusByNo($orderNo, $data); } //E SKM-CUSTOMS $this->redirect("/simple/order_completed/order_id/" . $order_id); exit; } $msg = array('type' => 'fail', 'msg' => '订单修改失败!'); $this->redirect('/index/msg', false, $msg); exit; } } } else { $message = $message ? $message : '支付失败'; $msg = array('type' => 'fail', 'msg' => $message); $this->redirect('/index/msg', false, $msg); exit; } }