Alisms.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\alisms;
  3. use think\Addons;
  4. /**
  5. * Alisms
  6. */
  7. class Alisms extends Addons
  8. {
  9. /**
  10. * 插件安装方法
  11. * @return bool
  12. */
  13. public function install()
  14. {
  15. return true;
  16. }
  17. /**
  18. * 插件卸载方法
  19. * @return bool
  20. */
  21. public function uninstall()
  22. {
  23. return true;
  24. }
  25. /**
  26. * 短信发送行为
  27. * @param array $params 必须包含mobile,event,code
  28. * @return boolean
  29. */
  30. public function smsSend(&$params)
  31. {
  32. $config = get_addon_config('alisms');
  33. $alisms = new \addons\alisms\library\Alisms();
  34. $result = $alisms->mobile($params['mobile'])
  35. ->template($config['template'][$params['event']])
  36. ->param(['code' => $params['code']])
  37. ->send();
  38. return $result;
  39. }
  40. /**
  41. * 短信发送通知
  42. * @param array $params 必须包含 mobile,event,msg
  43. * @return boolean
  44. */
  45. public function smsNotice(&$params)
  46. {
  47. $config = get_addon_config('alisms');
  48. $alisms = \addons\alisms\library\Alisms::instance();
  49. if (isset($params['msg'])) {
  50. if (is_array($params['msg'])) {
  51. $param = $params['msg'];
  52. } else {
  53. parse_str($params['msg'], $param);
  54. }
  55. } else {
  56. $param = [];
  57. }
  58. $param = $param ? $param : [];
  59. $params['template'] = isset($params['template']) ? $params['template'] : (isset($params['event']) && isset($config['template'][$params['event']]) ? $config['template'][$params['event']] : '');
  60. $result = $alisms->mobile($params['mobile'])
  61. ->template($params['template'])
  62. ->param($param)
  63. ->send();
  64. return $result;
  65. }
  66. /**
  67. * 检测验证是否正确
  68. * @param $params
  69. * @return boolean
  70. */
  71. public function smsCheck(&$params)
  72. {
  73. return true;
  74. }
  75. }