Easemob.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Redis;
  5. use think\Db;
  6. /**
  7. * 环信接口
  8. */
  9. class Easemob extends Api
  10. {
  11. protected $noNeedLogin = ["callback"];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 回调
  15. */
  16. public function callback() {
  17. $this->notify_log_start();
  18. $input = file_get_contents("php://input"); // 主题信息
  19. $input = json_decode($input,true);
  20. }
  21. //异步日志
  22. private function notify_log_start($paytype = 'easemob'){
  23. //记录支付回调数据
  24. ignore_user_abort(); // run script in background
  25. set_time_limit(30);
  26. // 日志文件 start
  27. $log_base_dir = '../paylog/'.$paytype.'/';
  28. if (!is_dir($log_base_dir))
  29. {
  30. mkdir($log_base_dir, 0770, true);
  31. @chmod($log_base_dir, 0770);
  32. }
  33. $notify_file = $log_base_dir.'notify.txt';
  34. if(!file_exists($notify_file)) {
  35. @touch($notify_file);
  36. @chmod($notify_file, 0770);
  37. }
  38. if(filesize($notify_file)>5242880)//大于5M自动切换
  39. {
  40. rename($notify_file, $log_base_dir.'notify_'.date('Y_m_d_H_i_s').'.txt');
  41. }
  42. if(!file_exists($notify_file)) {
  43. @touch($notify_file);
  44. @chmod($notify_file, 0770);
  45. }
  46. // 日志文件 end
  47. //开始写入
  48. $xml = file_get_contents("php://input");
  49. file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流原始数据] \n".$xml, FILE_APPEND);
  50. ini_set('display_errors','On');
  51. return $notify_file;
  52. }
  53. }