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. $this->showSuccess($result);
  30. }
  31. protected function postData()
  32. {
  33. $msg = file_get_contents("php://input");
  34. $temp = explode("$$$", $msg);
  35. $data = [
  36. "token" => '1234',
  37. 'api' => 'SendTextMsg',
  38. 'msg' => $temp[1] . ":" . $temp[0],
  39. 'to_wxid' => 'heanup',
  40. 'robot_wxid' => 'wxid_dt0ww4moe0qj22'
  41. ];
  42. $curl = curl_init();
  43. $data = json_encode($data);
  44. curl_setopt_array($curl, array(
  45. CURLOPT_URL => '10.211.55.4:8808',
  46. CURLOPT_RETURNTRANSFER => true,
  47. CURLOPT_ENCODING => '',
  48. CURLOPT_MAXREDIRS => 10,
  49. CURLOPT_TIMEOUT => 0,
  50. CURLOPT_FOLLOWLOCATION => true,
  51. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  52. CURLOPT_CUSTOMREQUEST => 'POST',
  53. CURLOPT_POSTFIELDS => $data,
  54. CURLOPT_HTTPHEADER => array(
  55. 'Content-Type: application/json'
  56. ),
  57. ));
  58. curl_exec($curl);
  59. curl_close($curl);
  60. Logger::setLog($msg, APP_DIR . "/test_msg.txt");
  61. }
  62. protected function putData()
  63. {
  64. // TODO: Implement putData() method.
  65. }
  66. protected function deleteData()
  67. {
  68. // TODO: Implement deleteData() method.
  69. }
  70. }