seNmult.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. include_once("../../untils/conn.php"); // 引入数据库连接配置文件
  3. // 查询SQL语句
  4. $sql = "SELECT * FROM config_api WHERE groups = 'Unicom'";
  5. // 执行查询
  6. $result = mysqli_query($con, $sql);
  7. // 获取结果
  8. $row = mysqli_fetch_assoc($result);
  9. $channel = $row['channel'];
  10. $uid = $row['uid'];
  11. $productType = $_POST['haokaid'];
  12. $searchValue = $_POST['searchValue'];
  13. // $productType = '1137';
  14. $provinceCode ='50';
  15. $cityCode = '501';
  16. $searchType ='02';
  17. // 构建请求参数数组
  18. $data = array(
  19. 'productType' => $productType,
  20. 'provinceCode' => $provinceCode,
  21. 'cityCode' => $cityCode,
  22. );
  23. // 判断$searchValue是否为空
  24. if (!empty($searchValue)) {
  25. $data['searchValue'] = $searchValue;
  26. $data['searchType'] = $searchType;
  27. }
  28. // 创建cURL资源
  29. $curl = curl_init();
  30. // 设置cURL选项
  31. curl_setopt_array($curl, array(
  32. CURLOPT_URL => 'https://kapi.10010.com/kcardorder/intentionalOrder/selectNum?channel=' . urlencode($channel) . '&id=' . urlencode($uid),
  33. CURLOPT_RETURNTRANSFER => true,
  34. CURLOPT_POST => true,
  35. CURLOPT_POSTFIELDS => $data,
  36. CURLOPT_HTTPHEADER => array(
  37. 'Content-Type: multipart/form-data'
  38. )
  39. ));
  40. // 发送请求并获取响应
  41. $response = curl_exec($curl);
  42. // 检查是否有错误发生
  43. if(curl_errno($curl)){
  44. $error_msg = curl_error($curl);
  45. // 处理错误
  46. } else {
  47. // 处理响应
  48. $responseData = json_decode($response, true);
  49. // 输出返回的数据
  50. if (!empty($responseData['data'])) {
  51. $data = array();
  52. foreach ($responseData['data'] as $item) {
  53. if (isset($item['number'])) {
  54. $data[] = $item['number'];
  55. }
  56. }
  57. $output = array(
  58. 'code' => 200,
  59. 'message' => '获取成功',
  60. 'data' => $data
  61. );
  62. } else {
  63. // 请求成功但没有数据的情况
  64. $output = array(
  65. 'code' => 0,
  66. 'message' => '没有数据'
  67. );
  68. }
  69. header('Content-Type: application/json');
  70. echo json_encode($output);
  71. }
  72. // 关闭cURL资源
  73. curl_close($curl);
  74. ?>