Notify.php 1.1 KB

123456789101112131415161718192021222324252627
  1. <?php namespace Msg\Lib\Type;
  2. use Dever;
  3. use Api\Lib\Account;
  4. class Notify
  5. {
  6. # 发送通知
  7. public function send($template, $account = [], $param = [], $project = 'api')
  8. {
  9. if ($template['content']) {
  10. $template['content'] = \Dever\Helper\Str::val($template['content'], $param);
  11. }
  12. foreach ($template['method'] as $k => $v) {
  13. $config = Dever::db('msg/account')->find(['method' => $v]);
  14. if ($config) {
  15. $handle = Dever::load('\\Msg\\Lib\\Method\\' . $config['method']);
  16. $data['account'] = $handle->init($template['id'], $config['id'], $account, $project);
  17. if ($config['test'] == 2) {
  18. $api = Dever::load(Account::class)->get($config['api_account_id'], $project);
  19. $data['record'] = $handle->send($api, $template['content'], $param);
  20. }
  21. $data['content'] = $template['content'];
  22. Dever::db('msg/notify')->insert($data);
  23. }
  24. }
  25. return '通知发送成功';
  26. }
  27. }