12345678910111213141516171819202122232425262728293031323334 |
- <?php namespace Msg\Lib\Method;
- use Dever;
- class Sms
- {
- private $config;
- # 初始化
- public function init($template_id, $account)
- {
- if (empty($account['mobile'])) {
- Dever::error('账户不存在');
- }
- $this->config = Dever::db('template_sms', 'msg')->find(array('template_id' => $template_id));
- if (!$this->config) {
- Dever::error('短信配置不存在');
- }
- $this->config['account'] = $account['mobile'];
- return $this->config['account'];
- }
- # 发送短信
- public function send($content, $param)
- {
- if (!$this->config) {
- Dever::error('短信配置不存在');
- }
- $send['mobile'] = $this->config['account'];
- $send['TemplateCode'] = $this->config['code'];
- $send['TemplateParam'] = $param;
- $send['log'] = true;
- $result = Dever::load('account', 'api')->run($this->config['account_key'], 'send_sms', $send);
- return Dever::json_encode($result);
- }
- }
|