ReceivedSms.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Heanup\App\Api\Controller;
  3. use Heanup\App\Api\RestfulController;
  4. use Heanup\Frame\Logger;
  5. class ReceivedSms extends RestfulController
  6. {
  7. protected function main()
  8. {
  9. $this->showSuccess();
  10. // file_put_contents(APP_DIR . "/test_msg.txt", file_get_contents("php://input").PHP_EOL,FILE_APPEND);
  11. }
  12. protected function getData()
  13. {
  14. $data = file(APP_DIR . "/test_msg.txt");
  15. $result = [];
  16. foreach ($data as $datum) {
  17. $pat = "#\[(.*)\]-\[IP.*\[操作:(.*)\]#iUs";
  18. preg_match($pat, $datum, $arr);
  19. if ($arr) {
  20. $temp = explode("$$$", $arr[2]);
  21. $result[] = [
  22. 'from' => $temp[1],
  23. 'to' => $temp[2],
  24. 'msg' => $temp[0],
  25. 'time' => $arr[1]
  26. ];
  27. }
  28. }
  29. $result=array_reverse($result);
  30. $this->showSuccess($result);
  31. }
  32. protected function postData()
  33. {
  34. $msg = file_get_contents("php://input");
  35. $temp = explode("$$$", $msg);
  36. $data = [
  37. "token" => '1234',
  38. 'api' => 'SendTextMsg',
  39. 'msg' => $temp[1] . ":" . $temp[0],
  40. 'to_wxid' => 'heanup',
  41. 'robot_wxid' => 'wxid_dt0ww4moe0qj22'
  42. ];
  43. $curl = curl_init();
  44. $data = json_encode($data);
  45. curl_setopt_array($curl, array(
  46. CURLOPT_URL => 'http://myhome.97admin.com:8808',
  47. CURLOPT_RETURNTRANSFER => true,
  48. CURLOPT_ENCODING => '',
  49. CURLOPT_MAXREDIRS => 10,
  50. CURLOPT_TIMEOUT => 0,
  51. CURLOPT_FOLLOWLOCATION => true,
  52. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  53. CURLOPT_CUSTOMREQUEST => 'POST',
  54. CURLOPT_POSTFIELDS => $data,
  55. CURLOPT_HTTPHEADER => array(
  56. 'Content-Type: application/json'
  57. ),
  58. ));
  59. curl_exec($curl);
  60. curl_close($curl);
  61. Logger::setLog($msg, APP_DIR . "/test_msg.txt");
  62. }
  63. protected function putData()
  64. {
  65. // TODO: Implement putData() method.
  66. }
  67. protected function deleteData()
  68. {
  69. // TODO: Implement deleteData() method.
  70. }
  71. }