Template.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php namespace Msg\Lib;
  2. use Dever;
  3. class Template
  4. {
  5. # 发送消息
  6. public function send($template, $account, $param = array())
  7. {
  8. $template = Dever::db('template', 'msg')->find(array('key' => $template));
  9. if (!$template) {
  10. Dever::error('消息模板不存在');
  11. }
  12. if ($template['type'] == 1) {
  13. $method = 'notify';
  14. } elseif ($template['type'] == 2) {
  15. $method = 'code';
  16. }
  17. $template['method'] = explode(',', $template['method']);
  18. return Dever::load('type/' . $method, 'msg')->send($template, $account, $param);
  19. }
  20. # 验证码检查
  21. public function check($template, $account, $code, $update = 1)
  22. {
  23. $template = Dever::db('template', 'msg')->find(array('key' => $template));
  24. if (!$template) {
  25. Dever::error('消息模板不存在');
  26. }
  27. if ($template['type'] == 2) {
  28. $state = Dever::load('type/code', 'msg')->check($template['id'], $account, $code, $update);
  29. if (!$state) {
  30. Dever::error('验证码错误');
  31. }
  32. }
  33. }
  34. }