callback.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. include_once("../../untils/conn.php");
  3. mysqli_query($con, "set names utf8");
  4. $type = $_GET['type'];
  5. // 将POST的数据写入log.txt文件
  6. $logFile = __DIR__ . "/log.txt";
  7. $logContent = date('Y-m-d H:i:s') . " [$type] " . json_encode($_POST) . PHP_EOL;
  8. file_put_contents($logFile, $logContent, FILE_APPEND);
  9. if ($type === 'haokeyun') {
  10. // 检查是否为测试消息
  11. $msg = $_POST['msg'];
  12. if ($msg === 'check') {
  13. echo 'SUCCESS';
  14. exit;
  15. }
  16. $oderid = $_POST['order_sn']; //订单号
  17. $status = $_POST['status']; //订单状态
  18. $thirdphone = $_POST['number']; //生产号码
  19. $is_activated = $_POST['is_activated']; //激活状态
  20. $activated_at = $_POST['activated_at']; //激活时间
  21. $is_recharged = $_POST['is_recharged']; //首冲状态
  22. $recharged_at = $_POST['recharged_at']; //首冲时间
  23. $recharged_amount = $_POST['recharged_amount']; //首冲金额
  24. $express_name = $_POST['express_name']; //物流名称
  25. $express_sn = $_POST['express_sn']; //物流单号
  26. $reason = $_POST['reason']; //失败原因
  27. if ($status === '26' && $is_activated === '1') {
  28. // 更新数据oder表
  29. $query = "UPDATE oder SET status = '3', card_sta = '1' WHERE oderid = '$oderid'";
  30. $querys = "UPDATE revenue SET oder_sta = '3' WHERE oderid = '$oderid'";
  31. $result = mysqli_query($con, $query);
  32. $result2 = mysqli_query($con, $querys);
  33. if ($result && $result2) {
  34. echo 'success';
  35. } else {
  36. echo 'err';
  37. }
  38. } elseif ($status === '30' || $status === '21') {
  39. // 更新数据oder表
  40. $query = "UPDATE oder SET status = '4', beizhu = '$reason' WHERE oderid = '$oderid'";
  41. $querys = "UPDATE revenue SET oder_sta = '4' WHERE oderid = '$oderid'";
  42. $result = mysqli_query($con, $query);
  43. $result2 = mysqli_query($con, $querys);
  44. if ($result && $result2) {
  45. echo 'success';
  46. } else {
  47. echo 'err';
  48. }
  49. } elseif ($status === '26') {
  50. // 更新数据oder表
  51. $beizhu = $express_name . ' ' . $express_sn;
  52. $query = "UPDATE oder SET status = '2', beizhu = '$beizhu', thirdphone = '$thirdphone' WHERE oderid = '$oderid'";
  53. $querys = "UPDATE revenue SET oder_sta = '2' WHERE oderid = '$oderid'";
  54. $result = mysqli_query($con, $query);
  55. $result2 = mysqli_query($con, $querys);
  56. if ($result && $result2) {
  57. echo 'success';
  58. } else {
  59. echo 'err';
  60. }
  61. } else {
  62. echo 'SUCCESS'; // 其他情况默认返回成功
  63. }
  64. } elseif ($type === 'gantanhao') {
  65. // 检查是否为测试消息
  66. $msg = $_POST['msg'];
  67. if ($msg === 'success') {
  68. echo 'SUCCESS';
  69. exit;
  70. }
  71. $outer_id = $_POST['outer_id']; // 合作方id
  72. $plan_mobile_produced = $_POST['plan_mobile_produced']; // 生产号码
  73. $status = $_POST['status']; // 订单状态
  74. $is_activated = $_POST['is_activated']; // 激活状态
  75. $activated_at = $_POST['activated_at']; // 激活时间
  76. $is_recharged = $_POST['is_recharged']; // 首冲状态
  77. $recharged_at = $_POST['recharged_at']; // 首冲时间
  78. $tracking_number = $_POST['tracking_number']; // 物流单号
  79. $tracking_company = $_POST['tracking_company']; // 物流公司名称
  80. $reason = $_POST['reason']; // 失败原因
  81. $sign = $_POST['sign']; // 签名
  82. // 取出apitoke
  83. $sql = "SELECT * FROM config_api WHERE groups = 'gantanhao'";
  84. $result = mysqli_query($con, $sql);
  85. // 检查查询结果是否为空
  86. if (mysqli_num_rows($result) > 0) {
  87. // 获取第一行数据
  88. $row = mysqli_fetch_assoc($result);
  89. $userid = $row['userid'];
  90. $token = $row['token'];
  91. } else {
  92. // 处理查询结果为空的情况
  93. }
  94. // 验证签名
  95. $api_token = $token;
  96. $signature = md5("outer_id=$outer_id&plan_mobile_produced=$plan_mobile_produced&status=$status$api_token");
  97. if ($sign !== $signature) {
  98. echo 'Invalid signature';
  99. exit;
  100. }
  101. if ($is_activated === '1') {
  102. // 更新数据oder表
  103. $query = "UPDATE oder SET status = '3', card_sta = '1' WHERE oderid = '$outer_id'";
  104. $querys = "UPDATE revenue SET oder_sta = '3' WHERE oderid = '$outer_id'";
  105. $result = mysqli_query($con, $query);
  106. $result2 = mysqli_query($con, $querys);
  107. if ($result && $result2) {
  108. echo 'SUCCESS';
  109. } else {
  110. echo 'err';
  111. }
  112. } elseif ($status === '550') {
  113. // 更新数据oder表
  114. $beizhu = $tracking_company . ' ' . $tracking_number;
  115. $query = "UPDATE oder SET status = '2', beizhu = '$beizhu', thirdphone = '$plan_mobile_produced' WHERE oderid = '$outer_id'";
  116. $querys = "UPDATE revenue SET oder_sta = '2' WHERE oderid = '$outer_id'";
  117. $result = mysqli_query($con, $query);
  118. $result2 = mysqli_query($con, $querys);
  119. if ($result && $result2) {
  120. echo 'SUCCESS';
  121. } else {
  122. echo 'err';
  123. }
  124. } elseif ($status === '-460' || $status === '-120') {
  125. // 更新数据oder表
  126. $query = "UPDATE oder SET status = '4', beizhu = '$reason' WHERE oderid = '$outer_id'";
  127. $querys = "UPDATE revenue SET oder_sta = '4' WHERE oderid = '$outer_id'";
  128. $result = mysqli_query($con, $query);
  129. $result2 = mysqli_query($con, $querys);
  130. if ($result && $result2) {
  131. echo 'SUCCESS';
  132. } else {
  133. echo 'err';
  134. }
  135. } else {
  136. echo 'SUCCESS'; // 其他情况默认返回成功
  137. }
  138. } else {
  139. // 未知平台类型,可以进行相应的处理
  140. }
  141. // 返回小写的'SUCCESS'表示成功接收回调请求
  142. // echo 'SUCCESS';
  143. ?>