Template.php 1.7 KB

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