getInput(); } foreach ($postData as $k => $v) { $log_postdata .= $k . ':' . $v . ' '; } } catch (\Exception $e) { $log_postdata = json_encode($postData); } log_message('支付订单回调:' . request()->url() . ' ' . $log_postdata, 'log', LOG_PATH . 'CpsNotify/'); } /** * 支付宝Aop支付服务器异步通知页面方法 */ public function alipayAop() { //Alipay Aop Sdk支付回调 vendor('alipayAop.AopSdk'); $aop = new \AopClient(); $public_key = Config::get('ali_pay_config')['configs'][Config::get('ali_pay_config')['default']['zfb']]['public_key']; $aop->alipayrsaPublicKey = $public_key; if ($result = $aop->rsaCheckV1($_POST, NULL, Config::get('ali_pay_config')['sign_type'])) { // 处理支付成功后的逻辑业务 if (input('post.trade_status') == 'TRADE_SUCCESS') { //写入日志 log_message($result, 'log', LOG_PATH . 'paylog/'); $out_trade_no = input('out_trade_no'); //订单号 if (!empty($out_trade_no)) { //更新订单状态处理 $this->updateOrder($out_trade_no, input('total_fee')); } echo 'success'; exit; //请不要修改或删除 } echo 'fail'; exit; //验证失败 } echo 'fail'; exit; } /** * 酷点h5支付 */ public function kdh5zhifu() { $request_data = file_get_contents('php://input'); log_message('酷点h5支付回调参数:' . $request_data, 'log', LOG_PATH . '../paylog/'); vendor('kdpaySdk.des'); $sumpay = new \kdpay(); $data = json_decode($request_data, true); $res_result = json_decode($data['result'], true); if ($res_result['status'] == '100') { $retjson = $sumpay->notifyVerify($data); if ($retjson == $data['sign']) { $orderid = trim($res_result['out_trade_no']); $amount = floatval($res_result['fee'] / 100); //订单编号不为空时 if (!empty($orderid)) { //更新订单状态处理 $this->updateOrder($orderid, $amount, $res_result['transaction_id']); } echo "success"; die(); } else { echo 'fail'; exit(); } } else { echo '支付失败'; exit(); } } private function updateOrder($orderid, $real_amount = 0, $callback_order = '') { $channelRechargeCoin = model('ChannelRechargeCoin')->field('id,orderid,channel_id,channel_name,send_channel_id,send_channel_name,amount,real_amount,status') ->where(['recharge_type'=>2,'orderid'=>$orderid])->find(); if ($real_amount != '' && $channelRechargeCoin['real_amount'] != $real_amount) { $result = false; //写入日志 log_message('订单编号:' . $orderid . '支付金额不一致,订单状态更新失败', 'error', LOG_PATH . 'cpsnotify/'); } //待支付状态时 elseif ($channelRechargeCoin['status'] == 0) { // 启动事务 Db::startTrans(); try { model('ChannelRechargeCoin')->where(['id'=>$channelRechargeCoin['id']])->update(['status'=>1,'callback_order'=>$callback_order]); $detData = array(); $detData['channel_id'] = $channelRechargeCoin['channel_id']; $detData['channel_name'] = $channelRechargeCoin['channel_name']; $detData['change_amount'] = +$channelRechargeCoin['amount']; $detData['account_type'] = 3; //通用账户 $detData['type'] = 4; //充值收入 $detData['out_orderid'] = $channelRechargeCoin['orderid']; $detData['create_time'] = NOW_TIMESTAMP; $insertDetId = model('ChannelAccountDet')->insertGetId($detData); if ( !$insertDetId) { throw new Exception("添加账户变动明细失败"); } $updData = array(); $updData['amount_coin'] = Db::raw("amount_coin+".$channelRechargeCoin['amount']); $updData['update_time'] = time(); $updFromResult = model('Channel')->where(['id'=>$channelRechargeCoin['channel_id']])->update($updData); if (!$updFromResult) { throw new Exception("账户金额变动失败"); } $data['finish_status'] = 1; $data['finish_time']= time(); $result = model('ChannelRechargeCoin')->where(['id'=>$channelRechargeCoin['id'],'status'=>1])->update($data); if (!$result) { throw new Exception("充值失败"); } // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); var_dump( $e->getMessage()); //写入日志 log_message('订单编号:' . $orderid . '订单状态更新失败' . $e->getMessage(), 'error', LOG_PATH . 'cpsnotify/'); } } } }