retryPay.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // 确保这些常量已经定义
  3. defined('DB_SERVER') ? null : define('DB_SERVER', 'localhost');
  4. defined('DB_USER') ? null : define('DB_USER', 'root');
  5. defined('DB_PASS') ? null : define('DB_PASS', 'wch123.com');
  6. defined('DB_NAME') ? null : define('DB_NAME', 'sdk');
  7. // 连接数据库
  8. $connection = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
  9. // 检查连接
  10. if ($connection->connect_error) {
  11. die("连接失败: " . $connection->connect_error);
  12. }
  13. $now = time();
  14. // 半小时之前的时间戳
  15. $halfHourAgo = strtotime("-120 minutes", $now);
  16. // 格式化时间戳为日期时间字符串
  17. $halfHourAgoFormatted = date("Y-m-d H:i:s", $halfHourAgo);
  18. // 查询数据库
  19. $query = "SELECT * FROM game_order where status= 1 and token != '' and create_time >= '{$halfHourAgoFormatted}' ";
  20. $result = $connection->query($query);
  21. $data = [];
  22. if ($result) {
  23. while ($row = $result->fetch_assoc()) {
  24. $data[] = $row;
  25. }
  26. } else {
  27. die("查询失败: " . $connection->error);
  28. }
  29. // 关闭数据库连接
  30. $connection->close();
  31. if(empty($data)){
  32. die("查询为空");
  33. }
  34. foreach ($data as $val) {
  35. $apiParams = [
  36. 'orderId' => $val['order_id'],
  37. 'platform' => $val['platform'],
  38. 'purchaseToken' => $val['token']
  39. ];
  40. var_dump($apiParams['orderId']);
  41. // 发送POST请求
  42. $url = 'http://sso.skystoryorigin.com:3000/callback';
  43. $jsonStr = json_encode($apiParams);
  44. list($returnCode, $returnContent) = http_post_json($url, $jsonStr);
  45. var_dump($returnCode, $returnContent);
  46. }
  47. function http_post_json($url, $jsonStr)
  48. {
  49. $ch = curl_init();
  50. curl_setopt($ch, CURLOPT_POST, 1);
  51. curl_setopt($ch, CURLOPT_URL, $url);
  52. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
  53. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  54. curl_setopt(
  55. $ch,
  56. CURLOPT_HTTPHEADER,
  57. array(
  58. 'Content-Type: application/json;charset=utf-8',
  59. 'Content-Length: ' . strlen($jsonStr)
  60. )
  61. );
  62. curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 超时时间设置为10秒
  63. $response = curl_exec($ch);
  64. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  65. curl_close($ch);
  66. return array($httpCode, $response);
  67. }