Forráskód Böngészése

更新 'crmeb/repositories/ShortLetterRepositories.php'

Kirin 2 éve
szülő
commit
52e83c4c8a
1 módosított fájl, 81 hozzáadás és 48 törlés
  1. 81 48
      crmeb/repositories/ShortLetterRepositories.php

+ 81 - 48
crmeb/repositories/ShortLetterRepositories.php

@@ -1,49 +1,82 @@
-<?php
-
-namespace crmeb\repositories;
-
-
-use app\admin\model\sms\SmsRecord;
-use crmeb\services\sms\Sms;
-use think\facade\Log;
-
-/**
- * 短信发送
- * Class ShortLetterRepositories
- * @package crmeb\repositories
- */
-class ShortLetterRepositories
-{
-    /**
-     * 发送短信
-     * @param $switch 发送开关
-     * @param $phone 手机号码
-     * @param array $data 模板替换内容
-     * @param string $template 模板编号
-     * @param string $logMsg 错误日志记录
-     * @return bool|string
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public static function send($switch, $phone, array $data, string $template, $logMsg = '')
-    {
-        if ($switch && $phone) {
-            $sms = new Sms([
-                'sms_account' => sys_config('sms_account'),
-                'sms_token' => sys_config('sms_token'),
-                'site_url' => sys_config('site_url')
-            ]);
-            $res = $sms->send($phone, $template, $data);
-            if ($res === false) {
-                $errorSmg = $sms->getError();
-                Log::info($logMsg ?? $errorSmg);
-                return $errorSmg;
-            } else {
-                SmsRecord::sendRecord($phone, $res['data']['content'], $res['data']['template'], $res['data']['id']);
-            }
-            return true;
-        } else {
-            return false;
-        }
-    }
+<?php
+
+namespace crmeb\repositories;
+
+
+use app\admin\model\sms\SmsRecord;
+use crmeb\services\sms\Sms;
+use think\facade\Log;
+
+/**
+ * 短信发送
+ * Class ShortLetterRepositories
+ * @package crmeb\repositories
+ */
+class ShortLetterRepositories
+{
+    /**
+     * 发送短信
+     * @param $switch 发送开关
+     * @param $phone 手机号码
+     * @param array $data 模板替换内容
+     * @param string $template 模板编号
+     * @param string $logMsg 错误日志记录
+     * @return bool|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function send($switch, $phone, array $data, string $template, $logMsg = '')
+    {
+        if ($switch && $phone) {
+            $sms = new Sms([
+                'sms_account' => sys_config('sms_account'),
+                'sms_token' => sys_config('sms_token'),
+                'site_url' => sys_config('site_url')
+            ]);
+            $res = $sms->send($phone, $template, $data);
+            if ($res === false) {
+                $errorSmg = $sms->getError();
+                Log::info($logMsg ?? $errorSmg);
+                return $errorSmg;
+            } else {
+                SmsRecord::sendRecord($phone, $res['data']['content'], $res['data']['template'], $res['data']['id']);
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+  
+   /**
+     * 发送短信
+     * @param string $phone 手机号码
+     * @param array $data 模板替换内容
+     * @param string $template 模板编号
+     * @return bool|string
+     */
+    public static function AliSend(bool $switch, string $phone, array $data, string $template, $logMsg = '')
+    {
+        if ($switch && $phone) {
+            try {
+                $sms = new AlismsService(sys_config('sms_account', 'LTAI5tShQy87veP818V9qd6W', true), sys_config('sms_token', 'hB0RrjIcC7jBV5apoXfX2YyVA4eoyl', true));
+                $res = $sms->setAction('SendSms')->setOptions([
+                    'PhoneNumbers' => $phone,
+                    'SignName' => '艺绘',
+                    'TemplateCode' => \think\facade\Config::get('sms.stores.aliyun.template_id.' . $template, 'sms.stores.aliyun.template_id.DEFAULT'),
+                    'TemplateParam' => json_encode($data),
+                ])->execute();
+                if ($res['Code'] != 'OK') {
+                    Log::info($logMsg ?? $res['Message']);
+                    return $res['Message'];
+                } else {
+                    SmsRecord::sendRecord($phone, $data['code'], $template, '');
+                }
+                return true;
+            } catch (Exception $exception) {
+                return $exception->getMessage();
+            }
+        } else {
+            return false;
+        }
+    }
 }