123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace addons\qcloudsms;
- use addons\qcloudsms\library\SmsSingleSender;
- use addons\qcloudsms\library\SmsVoicePromptSender;
- use addons\qcloudsms\library\SmsVoiceverifyCodeSender;
- use addons\qcloudsms\library\TtsVoiceSender;
- use think\Addons;
- use think\Config;
- class Qcloudsms extends Addons
- {
- private $appid = null;
- private $appkey = null;
- private $config = null;
- private $sender = null;
- private $sendError = '';
- public function ConfigInit()
- {
- $this->config = $this->getConfig();
-
- if ($this->config['isVoice'] == 1) {
- $this->config['template'] = $this->config['voiceTemplate'];
-
- $this->appid = $this->config['voiceAppid'];
- $this->appkey = $this->config['voiceAppkey'];
- } else {
- $this->appid = $this->config['appid'];
- $this->appkey = $this->config['appkey'];
- }
- }
-
- public function smsSend(&$params)
- {
- $this->ConfigInit();
- try {
- if ($this->config['isTemplateSender'] == 1) {
- $templateID = $this->config['template'][$params->event];
- if ($this->config['isVoice'] != 1) {
-
- $this->sender = new SmsSingleSender($this->appid, $this->appkey);
- $result = $this->sender->sendWithParam("86", $params['mobile'], $templateID, ["{$params->code}"], $this->config['sign'], "", "");
- } else {
-
- $this->sender = new TtsVoiceSender($this->appid, $this->appkey);
-
- $result = $this->sender->send("86", $params['mobile'], $templateID, [$params->code]);
- }
- } else {
-
- if ($this->config['isVoice'] != 1) {
- $this->sender = new SmsSingleSender($this->appid, $this->appkey);
-
- $result = $this->sender->send($params['type'], '86', $params['mobile'], $params['msg'], "", "");
- } else {
- $this->sender = new SmsVoiceVerifyCodeSender($this->appid, $this->appkey);
-
- $result = $this->sender->send('86', $params['mobile'], $params['msg']);
- }
- }
- $rsp = json_decode($result, true);
- if ($rsp['result'] == 0 && $rsp['errmsg'] == 'OK') {
- return true;
- } else {
-
- $this->setError($rsp);
- return false;
- }
- } catch (\Exception $e) {
- $this->setError($e->getMessage());
- }
- return false;
- }
-
- public function smsNotice(&$params)
- {
- $this->ConfigInit();
- try {
- if ($this->config['isTemplateSender'] == 1) {
- $templateID = $this->config['template'][$params['template']];
- if ($this->config['isVoice'] != 1) {
-
- $this->sender = new SmsSingleSender($this->appid, $this->appkey);
- $result = $this->sender->sendWithParam("86", $params['mobile'], $templateID, ["{$params['msg']}"], $this->config['sign'], "", "");
- } else {
-
- $this->sender = new TtsVoiceSender($this->appid, $this->appkey);
-
- $result = $this->sender->send("86", $params['mobile'], $templateID, [$params['msg']]);
- }
- } else {
-
- if ($this->config['isVoice'] != 1) {
- $this->sender = new SmsSingleSender($this->appid, $this->appkey);
-
- $result = $this->sender->send($params['type'], '86', $params['mobile'], $params['msg'], "", "");
- } else {
- $this->sender = new SmsVoicePromptSender($this->appid, $this->appkey);
-
- $result = $this->sender->send('86', $params['mobile'], 2, $params['msg']);
- }
- }
- $rsp = (array)json_decode($result, true);
- if ($rsp['result'] == 0 && $rsp['errmsg'] == 'OK') {
- return true;
- } else {
-
- $this->setError($rsp);
- return false;
- }
- } catch (\Exception $e) {
- var_dump($e);
- exit();
- }
- }
-
- private function setError($err)
- {
- $this->sendError = $err;
- }
-
- public function getError()
- {
- return $this->sendError;
- }
-
- public function smsCheck(&$params)
- {
- return true;
- }
-
- public function install()
- {
- return true;
- }
-
- public function uninstall()
- {
- return true;
- }
-
- public function enable()
- {
- return true;
- }
-
- public function disable()
- {
- return true;
- }
- }
|