SmsConfigLogic.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\notice;
  15. use app\common\enum\notice\SmsEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\service\ConfigService;
  18. /**
  19. * 短信配置逻辑层
  20. * Class SmsConfigLogic
  21. * @package app\adminapi\logic\notice
  22. */
  23. class SmsConfigLogic extends BaseLogic
  24. {
  25. /**
  26. * @notes 获取短信配置
  27. * @return array
  28. * @author 段誉
  29. * @date 2022/3/29 11:37
  30. */
  31. public static function getConfig()
  32. {
  33. $config = [
  34. ConfigService::get('sms', 'ali', ['type' => 'ali', 'name' => '阿里云短信', 'status' => 1]),
  35. ConfigService::get('sms', 'tencent', ['type' => 'tencent', 'name' => '腾讯云短信', 'status' => 0]),
  36. ];
  37. return $config;
  38. }
  39. /**
  40. * @notes 短信配置
  41. * @param $params
  42. * @return bool|void
  43. * @author 段誉
  44. * @date 2022/3/29 11:37
  45. */
  46. public static function setConfig($params)
  47. {
  48. $type = $params['type'];
  49. $params['name'] = self::getNameDesc(strtoupper($type));
  50. ConfigService::set('sms', $type, $params);
  51. $default = ConfigService::get('sms', 'engine', false);
  52. if ($params['status'] == 1 && $default === false) {
  53. // 启用当前短信配置 并 设置当前短信配置为默认
  54. ConfigService::set('sms', 'engine', strtoupper($type));
  55. return true;
  56. }
  57. if ($params['status'] == 1 && $default != strtoupper($type)) {
  58. // 找到默认短信配置
  59. $defaultConfig = ConfigService::get('sms', strtolower($default));
  60. // 状态置为禁用 并 更新
  61. $defaultConfig['status'] = 0;
  62. ConfigService::set('sms', strtolower($default), $defaultConfig);
  63. // 设置当前短信配置为默认
  64. ConfigService::set('sms', 'engine', strtoupper($type));
  65. return true;
  66. }
  67. }
  68. /**
  69. * @notes 查看短信配置详情
  70. * @param $params
  71. * @return array|int|mixed|string|null
  72. * @author 段誉
  73. * @date 2022/3/29 11:37
  74. */
  75. public static function detail($params)
  76. {
  77. $default = [];
  78. switch ($params['type']) {
  79. case 'ali':
  80. $default = [
  81. 'sign' => '',
  82. 'app_key' => '',
  83. 'secret_key' => '',
  84. 'status' => 1,
  85. 'name' => '阿里云短信',
  86. ];
  87. break;
  88. case 'tencent':
  89. $default = [
  90. 'sign' => '',
  91. 'app_id' => '',
  92. 'secret_key' => '',
  93. 'status' => 0,
  94. 'secret_id' => '',
  95. 'name' => '腾讯云短信',
  96. ];
  97. break;
  98. }
  99. $result = ConfigService::get('sms', $params['type'], $default);
  100. $result['status'] = intval($result['status'] ?? 0);
  101. return $result;
  102. }
  103. /**
  104. * @notes 获取短信平台名称
  105. * @param $value
  106. * @return string
  107. * @author 段誉
  108. * @date 2022/3/29 11:37
  109. */
  110. public static function getNameDesc($value)
  111. {
  112. $desc = [
  113. 'ALI' => '阿里云短信',
  114. 'TENCENT' => '腾讯云短信',
  115. ];
  116. return $desc[$value] ?? '';
  117. }
  118. }