Sms.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php namespace Msg\Lib\Method;
  2. use Dever;
  3. class Sms
  4. {
  5. private $config;
  6. # 初始化
  7. public function init($template_id, $account)
  8. {
  9. if (empty($account['mobile'])) {
  10. Dever::error('账户不存在');
  11. }
  12. $this->config = Dever::db('template_sms', 'msg')->find(array('template_id' => $template_id));
  13. if (!$this->config) {
  14. Dever::error('短信配置不存在');
  15. }
  16. $this->config['account'] = $account['mobile'];
  17. return $this->config['account'];
  18. }
  19. # 发送短信
  20. public function send($content, $param)
  21. {
  22. if (!$this->config) {
  23. Dever::error('短信配置不存在');
  24. }
  25. $send['mobile'] = $this->config['account'];
  26. $send['TemplateCode'] = $this->config['code'];
  27. $send['TemplateParam'] = $param;
  28. $send['log'] = true;
  29. $result = Dever::load('account', 'api')->run($this->config['account_key'], 'send_sms', $send);
  30. return Dever::json_encode($result);
  31. }
  32. }