WIN-2308041133\Administrator 23 часов назад
Родитель
Сommit
e643ad0fd8
1 измененных файлов с 71 добавлено и 3 удалено
  1. 71 3
      app/services/message/notice/SmsService.php

+ 71 - 3
app/services/message/notice/SmsService.php

@@ -13,6 +13,7 @@ namespace app\services\message\notice;
 
 
 use app\jobs\notice\SmsJob;
 use app\jobs\notice\SmsJob;
 use app\jobs\TaskJob;
 use app\jobs\TaskJob;
+use app\model\system\SystemNotification;
 use app\services\message\NoticeService;
 use app\services\message\NoticeService;
 use app\services\kefu\service\StoreServiceServices;
 use app\services\kefu\service\StoreServiceServices;
 use app\services\message\SystemNotificationServices;
 use app\services\message\SystemNotificationServices;
@@ -35,6 +36,10 @@ class SmsService extends NoticeService
      * @var string[]
      * @var string[]
      */
      */
     private $smsType = ['yihaotong', 'aliyun', 'tencent'];
     private $smsType = ['yihaotong', 'aliyun', 'tencent'];
+    const url = 'https://api-shss.zthysms.com/v2/sendSms';
+    private static $username = '13777687829';
+    private static $password = 'T17L7T10';
+    private static $sign = '玉环斌飞日用品商行';
 
 
     /**
     /**
      * 发送短信消息
      * 发送短信消息
@@ -58,7 +63,68 @@ class SmsService extends NoticeService
             return true;
             return true;
         }
         }
     }
     }
-
+   public function send(bool $switch, $phone, array $data, string $mark)
+   {
+       if ($switch && $phone) {
+           //获取发送短信驱动类型
+           $type = $this->smsType[sys_config('sms_type', 0)];
+           if ($type == 'tencent') {
+               $data = $this->handleTencent($mark, $data);
+           }
+           $sms_txt = SystemNotification::where('mark',$mark)->value('sms_text');
+           foreach ($data as  $key=>$v)
+           {
+               $arr[] = '{$'.$key.'}';
+               $arr1[] = $v;
+           }
+           $sms_txt = str_replace($arr,$arr1,$sms_txt);
+           $data1['username'] = self::$username;
+           $data1['tKey'] = time();
+           $data1['password'] = md5(md5(self::$password).$data1['tKey']);
+           $data1['mobile'] = $phone;
+           $sign = self::$sign;
+           $data1['content'] = "【{$sign}】".$sms_txt;
+           $rs =$this->do_request(self::url,$data1,[
+               'Content-Type: application/json'
+           ],true,true,0);
+           $rs = json_decode($rs,true);
+           if ($rs['code'] !=200) {
+               throw new ApiException($rs['msg']);
+           }
+           return true;
+       } else {
+           return false;
+       }
+   }
+    private function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
+    {
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+        if ($post) {
+            curl_setopt($curl, CURLOPT_POST, 1);
+            if (!$json && !$form) {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
+            } else if ($json && !$form) {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
+            } else {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+            }
+        }
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        if ($header) {
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+            curl_setopt($curl, CURLOPT_HEADER, 0);
+        }
+        $result = curl_exec($curl);
+        @file_put_contents("do.txt",$result.'---'.$url);
+        if (curl_errno($curl)) {
+            return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
+        }
+        curl_close($curl);
+        return $result;
+    }
     /**
     /**
      * 发送短信
      * 发送短信
      * @param bool $switch
      * @param bool $switch
@@ -67,7 +133,7 @@ class SmsService extends NoticeService
      * @param string $mark
      * @param string $mark
      * @return bool
      * @return bool
      */
      */
-    public function send(bool $switch, $phone, array $data, string $mark)
+    public function sendold(bool $switch, $phone, array $data, string $mark)
     {
     {
         if ($switch && $phone) {
         if ($switch && $phone) {
             //获取发送短信驱动类型
             //获取发送短信驱动类型
@@ -191,7 +257,9 @@ class SmsService extends NoticeService
             case 'recharge_success':
             case 'recharge_success':
                 $result = [$data['price'], $data['now_money']];
                 $result = [$data['price'], $data['now_money']];
                 break;
                 break;
-
+            case 'sign_remind':
+                $result = [$data['site_name']];
+                break;
         }
         }
         return $result;
         return $result;
     }
     }