error('error'); } $s = \Dever\Helper\Str::decode($input['s']); if ($s) { list($connect_id, $api_id, $order_id) = explode('|', $s); } elseif (isset($input['order_num'])) { $order_id = Dever::db('order', 'seller')->find(array('order_num' => $input['order_num'])); if (!$order_id) { $this->error('error'); } $channel = Dever::db('info', 'channel')->find($order_id['channel_id']); if (!$channel) { $this->error('order error'); } $connect_id = $channel['connect_id']; $api = Dever::db('api', 'api')->find(array('connect_id' => $connect_id, 'type' => 1)); if (!$api) { $this->error('order error'); } $api_id = $api['id']; } else { $this->error('error'); } $this->connect = Dever::db('info', 'api')->find($connect_id); $this->info = Dever::db('api', 'api')->find($api_id); unset($input['s']); unset($input['l']); if (!$input) { $input = file_get_contents("php://input"); if ($input) { $input = json_decode($input, true); if (is_array($input)) { if (isset($input['s'])) { unset($input['s']); } if (isset($input['l'])) { unset($input['l']); } } else { $this->error('error'); } } } if (!$input) { $this->error('error'); } $this->load($input, $connect_id, $api_id, $order_id); } private function load($input, $connect_id, $api_id, $order_id) { //Dever::log($input, 'notify'); if (is_array($order_id)) { $order = $order_id; } else { $order = Dever::db('order', 'seller')->find($order_id); } if (!$order || $order['status'] >= 10) { $this->error('order error'); } $channel = Dever::db('info', 'channel')->find($order['channel_id']); if (!$channel) { $this->error('channel error'); } $this->connect['appsecret'] = $channel['appsecret']; $code = Dever::db('api_notify_code', 'api')->select(array('api_id' => $api_id)); $status = 0; if ($code) { foreach ($code as $k => $v) { if (isset($input[$v['key']]) && $input[$v['key']] == $v['value']) { $status = $v['type']; } } } $data = $input; $data['status'] = $status; $data = $this->service($data); $msg = ''; if ($status == 1) { $msg = 'ok'; } elseif ($status == 2) { $msg = 'error'; } if ($this->info['notify_sign_col']) { $this->info['sign_col'] = $this->info['notify_sign_col']; } if ($sign = Dever::issets($input, $this->connect['sign_name'])) { unset($input[$this->connect['sign_name']]); unset($input['l']); /* $string = ''; if ($sign != $this->sign($input, $string)) { $this->error('sign error'); }*/ } if ($msg) { $update = array(); $update['official_msg'] = $data['official_msg'] ?? ''; $update['official_order_num'] = $data['official_order_num'] ?? ''; $update['channel_callback'] = json_encode($input, JSON_UNESCAPED_UNICODE); $update['channel_callback_date'] = time(); if ($msg != 'ok') { $channel_num = Dever::db('channel', 'seller')->count(array('seller_id' => $order['seller_id'], 'goods_id' => $order['goods_id'], 'status' => 1)); if ($channel_num > 1) { # 记录渠道错误信息 $selected = array(); $selected[$order['channel_id']] = true; $order_error_data = Dever::db('order_error', 'seller')->select(array('order_num' => $order['order_num'])); if ($order_error_data) { foreach ($order_error_data as $k => $v) { $selected[$v['channel_id']] = true; } } $num = count($selected); $channel_num = $channel_num - $num; if ($channel_num > 0) { $order_error = array(); $order_error['order_num'] = $order['order_num']; $order_error['buy_price'] = $order['buy_price']; $order_error['channel_id'] = $order['channel_id']; $order_error['channel_goods_id'] = $order['channel_goods_id']; $order_error['channel_goods_discount'] = $order['channel_goods_discount']; $order_error['channel_order_date'] = $order['channel_order_date']; $order_error['channel_order_num'] = $order['channel_order_num']; $order_error['channel_request'] = $order['channel_request']; $order_error['channel_response'] = $order['channel_response']; $order_error['channel_callback'] = $update['channel_callback']; $order_error['channel_callback_date'] = $update['channel_callback_date']; Dever::db('order_error', 'seller')->insert($order_error); Dever::load('order', 'seller')->handleAct($order, $selected); } else { Dever::load('order', 'seller')->notify($order, $msg, $update); } } else { Dever::load('order', 'seller')->notify($order, $msg, $update); } } else { Dever::load('order', 'seller')->notify($order, $msg, $update); } echo $this->info['notify_success'];die; } $this->error('error'); } private function error($msg) { if ($this->info && $this->info['notify_error']) { if ($this->info['notify_error'] == 500) { header("HTTP/1.1 500 Internal Server Error"); header("Status: 500 Internal Server Error"); } else { echo $this->info['notify_error'];die; } } echo $msg;die; } # 生成回调 public function callback() { //$param = '{"l":"notify.callback","t":"4-5-user_order","userid":"41438","order_id":"24020213181441438abbf5b39f","account":"15810090811","amount":"100","price":"104.1","state":"failed","user_order":"C2024020251094338265393","sign":"0447CC15F7D0218A1C5C09160A12A19A","voucher":""}'; //$input = Dever::json_decode($param); $input = Dever::input(); if (!isset($input['t'])) { $this->error('error'); } $file = file_get_contents("php://input"); if ($file) { $file = json_decode($file, true); if ($file) { $input = array_merge($file, $input); } } $temp = explode('-', $input['t']); $connect_id = $temp[0]; $api_id = $temp[1]; $order_key = $temp[2]; $this->connect = Dever::db('info', 'api')->find($connect_id); $this->info = Dever::db('api', 'api')->find($api_id); if (!isset($input[$order_key])) { $this->error('error'); } $order_id = $input[$order_key]; unset($input['t']); $order = Dever::db('order', 'seller')->find(array('order_num' => $order_id)); if (!$order || $order['status'] >= 10) { $this->error('order error'); } $this->load($input, $connect_id, $api_id, $order); } }