WebHook.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Tools;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\Http;
  5. class WebHook{
  6. /**
  7. * Create a new command instance.
  8. *
  9. * @return void
  10. */
  11. public function __construct()
  12. {
  13. }
  14. public function wechat($url, $title=null, $message=null)
  15. {
  16. $param["msgtype"]="markdown";
  17. if(empty($title) && empty($message) ){
  18. return 0;
  19. }
  20. if($title !== null){
  21. $param["markdown"]['title'] = $title;
  22. }
  23. if($message !== null){
  24. $param["markdown"]['content'] = $message;
  25. }
  26. return $this->send($url, $param);
  27. }
  28. public function dingtalk($url, $title=null, $message=null){
  29. $param = array();
  30. $param["msgtype"]="markdown";
  31. if(empty($title) && empty($message) ){
  32. return 0;
  33. }
  34. if($title !== null){
  35. $param["markdown"]['title'] = $title;
  36. }
  37. if($message !== null){
  38. $param["markdown"]['text'] = $message;
  39. }
  40. return $this->send($url, $param);
  41. }
  42. private function send($url, $param){
  43. Log::info($param);
  44. try{
  45. $response = Http::post($url, $param);
  46. if($response->successful()){
  47. return 0;
  48. }else{
  49. return 1;
  50. }
  51. }catch(\Exception $e){
  52. Log::error($e);
  53. return 1;
  54. }
  55. return 0;
  56. }
  57. }