-1, 'msg' => '信息不完整,请重新输入'); echo json_encode($response); return; } // 判断订单是否已经提交过 session_start(); if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) { $response = array('status' => 1, 'msg' => '订单已经提交过了'); echo json_encode($response); return; } $data_query = mysqli_query($con, "select * from oder where uid='$uid'"); $count = mysqli_num_rows($data_query); if ($count > 10) { // 用户已经申请过了,返回状态码1和提示信息 $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服'); echo json_encode($response); } else { // 判断$channel变量是否为空,如果为空则将其赋值为null if(empty($channel)){ $channel = 0; } $data_insert = mysqli_query($con, "insert into oder(goods,name,uid,phone,sf,city,xian,dizhi,oderid,time,price,channel) values('$goods','$name','$uid','$phone','$sf','$city','$xian','$dizhi','$oderid','$time','$price','$channel')"); if ($data_insert) { $sql = "SELECT haokaid FROM list WHERE name='$goods'"; $res = mysqli_query($con, $sql); if(mysqli_num_rows($res) > 0){ $row = mysqli_fetch_assoc($res); $haokaid = $row['haokaid']; } if ($haokaid == 0) { // haokaid等于0,直接输出申请成功 $response = array('status' => 0, 'msg' => '申请成功'); echo json_encode($response); // 将订单号写入session $_SESSION['order_id'] = $oderid; //发送短信通知 sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign); } else { $sql = "SELECT * FROM kefu"; $res = mysqli_query($con, $sql); if(mysqli_num_rows($res) > 0){ $row = mysqli_fetch_assoc($res); $user_id = $row['appid']; $secret = $row['key']; } // 计算签名 $user_sign = md5 ("Address=".$dizhi."&Area=".$xian."&City=".$city."&DownOrderID=".$oderid."&IDCard=".$uid."&Name=".$name."&Phone=".$phone."&ProductID=".$haokaid."&Province=".$sf."&ThirdPhone=&Timestamp=".$time."&user_id=".$user_id.$secret); // echo $user_sign; // exit ; // 构造请求参数 $params = array( 'user_id' => $user_id, 'Timestamp' => $time, 'Name' => $name, 'Phone' => $phone, 'IDCard' => $uid, 'Province' => $sf, 'City' => $city, 'Area' => $xian, 'Address' => $dizhi, 'ProductID' => $haokaid, 'DownOrderID' => $oderid, 'ThirdPhone' => '', 'user_sign' => $user_sign, ); // 构造请求头 $headers = array( 'Content-Type: application/x-www-form-urlencoded' ); // 发送请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://haokaopenapi.lot-ml.com/api/order/ApiToOrder'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // 解析响应数据 $result = json_decode($response, true); if ($result['code'] == 0) { // 更新订单状态 $update_sql = "UPDATE oder SET status=1, beizhu='$beizhu' WHERE oderid='$oderid'"; $update_query = mysqli_query($con, $update_sql); if ($update_query) { // 更新成功,返回状态码0和提示信息 $response = array('status' => 0, 'msg' => '申请成功'); echo json_encode($response); //发送短信通知 sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign); } else { // 更新失败,返回状态码-2和提示信息 $response = array('status' => -2, 'msg' => '更新订单状态失败'); echo json_encode($response); } } else { // 下单失败,返回接口返回的错误信息 $response = array('status' => $result['code'], 'msg' => $result['message']); echo json_encode($response); } } } else { // 信息不全,返回状态码-1和提示信息 $response = array('status' => -1, 'msg' => '哦豁,又出错了,找客服吧~'); echo json_encode($response); } } }