Template.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php namespace Msg\Lib;
  2. use Dever;
  3. use Msg\Lib\Type\Notify;
  4. use Msg\Lib\Type\Code;
  5. class Template
  6. {
  7. # 获取通知方式
  8. public function method()
  9. {
  10. $value = [
  11. 'Letter' => '站内信',
  12. 'Sms' => '短信',
  13. 'WechatService' => '微信公众号模板消息',
  14. 'WechatApplet' => '微信小程序订阅消息',
  15. //'App' => 'APP推送',
  16. //'Email' => '邮箱',
  17. ];
  18. return $value;
  19. }
  20. # 发送消息
  21. public function send($template, $account = [], $param = [], $project = 'api')
  22. {
  23. $template = Dever::db('msg/template')->find(['key' => $template, 'status' => 1]);
  24. if (!$template) {
  25. Dever::error('消息模板不存在');
  26. }
  27. if ($template['type'] == 1) {
  28. $method = Notify::class;
  29. } elseif ($template['type'] == 2) {
  30. $method = Code::class;
  31. }
  32. $template['method'] = explode(',', $template['method']);
  33. return Dever::load($method)->send($template, $account, $param, $project);
  34. }
  35. # 验证码检查
  36. public function check($template, $account, $code, $update = 1)
  37. {
  38. $template = Dever::db('msg/template')->find(['key' => $template, 'status' => 1]);
  39. if (!$template) {
  40. Dever::error('消息模板不存在');
  41. }
  42. if ($template['type'] == 2) {
  43. $state = Dever::load(Code::class)->check($template['id'], $account, $code, $update);
  44. if (!$state) {
  45. Dever::error('验证码错误');
  46. }
  47. }
  48. }
  49. }