loraWan.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // 智慧灯杆wifi设备收发指令脚本
  3. require_once __DIR__ . '/Autoloader.php';
  4. use Workerman\Worker;
  5. use Workerman\Connection\TcpConnection;
  6. use \Workerman\Lib\Timer;
  7. require_once './Lib/mysql/src/Connection.php';
  8. $tcp_worker = new Worker("tcp://0.0.0.0:8090");
  9. $tcp_worker->onWorkerStart = function($ws_worker)
  10. {
  11. global $cmdClientList;
  12. $cmdClientList = [];
  13. $url = 'https://device.api.ct10649.com:8743/iocm/app/sec/v1.1.0/login';
  14. $data = array(
  15. 'appId' => 'L_JzQ9KoR0py5X6fEGjO9p2PsWYa',
  16. 'secret' => 'pO9P7mecnU2KeucxkxuxiWbGBDsa',
  17. );
  18. $jsonData = json_encode($data);
  19. var_dump(curl($url,$data));
  20. // 指令返回结果处理
  21. // Timer::add(1, function()use($ws_worker){
  22. // global $globalData;
  23. // global $cmdClientList;
  24. // do
  25. // {
  26. // $old_value = $globalData->resList;
  27. // $new_value = [];
  28. // }
  29. // while(!$globalData->cas('resList', $old_value, $new_value));
  30. // $resList = $old_value;
  31. // if (!empty($resList)) {
  32. // foreach ($resList as $resData) {
  33. // $resData = json_decode($resData,true);
  34. // if (isset($cmdClientList[$resData['devId']])) {
  35. // $cmdClientList[$resData['devId']]->send(json_encode($resData));
  36. // unset($cmdClientList[$resData['devId']]);
  37. // }
  38. // }
  39. // }
  40. // });
  41. };
  42. // 下发指令
  43. $tcp_worker->onMessage = function($connection, $data)
  44. {
  45. // global $globalData;
  46. // global $cmdClientList;
  47. // $res = json_decode($data,true);
  48. // if (isset($res['devId'])) {
  49. // $cmdClientList[$res['devId']] = $connection;
  50. // add_cmd($res);
  51. // }else{
  52. // }
  53. };
  54. function curl($url, $params = false, $ispost = 0, $https = 0)
  55. {
  56. $httpInfo = array();
  57. $ch = curl_init();
  58. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  59. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  60. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  61. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
  62. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
  63. // curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\wzh\Desktop\cert\client.crt');
  64. curl_setopt($ch, CURLOPT_SSLCERT, './cert/outgoing.CertwithKey.pem');
  65. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'IoM@1234');
  66. curl_setopt($ch, CURLOPT_POST, true);
  67. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  68. curl_setopt($ch, CURLOPT_URL, $url);
  69. $response = curl_exec($ch);
  70. if ($response === FALSE) {
  71. echo "cURL Error: " . curl_error($ch);
  72. return false;
  73. }
  74. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  75. $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
  76. curl_close($ch);
  77. return $response;
  78. }
  79. Worker::runAll();