MessageGateway.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @author mybsdc <[email protected]>
  4. * @date 2021/10/20
  5. * @time 13:34
  6. */
  7. namespace Luolongfei\Libs\Connector;
  8. abstract class MessageGateway implements MessageServiceInterface
  9. {
  10. /**
  11. * 根据模板生成送信内容
  12. *
  13. * @param array $data 数据
  14. * @param string $template 模板内容
  15. *
  16. * @return string
  17. */
  18. public function genMessageContent(array $data, string $template)
  19. {
  20. array_unshift($data, $template);
  21. return call_user_func_array('sprintf', $data);
  22. }
  23. /**
  24. * 参数数据检查
  25. *
  26. * @param string $content
  27. * @param array $data
  28. *
  29. * @throws \Exception
  30. */
  31. public function check(string $content, array $data)
  32. {
  33. if ($content === '' && empty($data)) {
  34. throw new \Exception(lang('100002'));
  35. }
  36. }
  37. /**
  38. * 换行转 <br>
  39. *
  40. * @param string $content
  41. *
  42. * @return string
  43. */
  44. public function newLine2Br(string $content)
  45. {
  46. return preg_replace("/\n/u", '<br>', $content);
  47. }
  48. /**
  49. * 设置公共页脚
  50. *
  51. * @param $footer
  52. * @param $newline
  53. * @param $enablePushFreqTips
  54. *
  55. * @return void
  56. */
  57. public function setCommonFooter(&$footer, $newline = "\n", $enablePushFreqTips = true)
  58. {
  59. if ($enablePushFreqTips) {
  60. $footer .= $newline . $newline . lang('100133');
  61. }
  62. // 服务器信息相关文言
  63. if (env('SHOW_SERVER_INFO')) {
  64. $footer .= $newline . $newline . lang('100134');
  65. $footer .= $newline . get_ip_info();
  66. }
  67. }
  68. }