Browse Source

奇讯云短信

lizhen_gitee 11 months ago
parent
commit
2ff39ef0e4
3 changed files with 101 additions and 7 deletions
  1. 67 0
      application/common/library/Qxysms.php
  2. 20 2
      application/common/library/Sms.php
  3. 14 5
      application/config.php

+ 67 - 0
application/common/library/Qxysms.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\common\library;
+
+class Qxysms
+{
+    private $host      = '';
+    private $appKey    = '';
+    private $appSecret = '';
+    private $appCode   = '';
+    private $signName  = '';
+
+    public function __construct($config){
+        $this->host      = $config['host'];
+        $this->appKey    = $config['appKey'];
+        $this->appSecret = $config['appSecret'];
+        $this->appCode   = $config['appCode'];
+        $this->signName  = $config['signName'];
+    }
+
+    /**
+     * 发送验证码
+     * @param string $mobile
+     * @param $code
+     * @return bool
+     */
+    public function send(string $mobile, $code)
+    {
+
+        $timestamp = $this->ms_time();
+        $data = [
+            'sign'      => md5("{$this->appKey}{$this->appSecret}{$timestamp}"),
+            'timestamp' => $timestamp,
+            'phone'     => $mobile,
+            'appcode'   => $this->appCode,
+            'appkey'    => $this->appKey,
+            'msg'       => "【{$this->signName}】您的验证码是{$code},请妥善保管"
+        ];
+
+        $response  = curl_post($this->host . '/sms/batch/v1', json_encode($data),['Content-type:application/json']);
+
+        //dump($response);exit;
+        $response = json_decode($response,true);
+        if(is_array($response) && isset($response['code']) && $response['code'] == '00000'){
+            return true;
+        }
+
+        return false;
+    }
+
+    protected function ms_time()
+    {
+        list($ms, $sec) = explode(' ', microtime());
+        return intval((floatval($ms) + floatval($sec)) * 1000);
+    }
+
+    /**
+     * @param $url
+     * @param array $params
+     * @param array $header
+     * @return PromiseInterface|Response
+     */
+    protected function postJson($url, array $params = [], array $header = [])
+    {
+        return Http::withHeaders($header)->acceptJson()->post($this->host . $url, $params);
+    }
+}

+ 20 - 2
application/common/library/Sms.php

@@ -57,11 +57,14 @@ class Sms
         $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
 //        $result = Hook::listen('sms_send', $sms, null, true);
 
-        //阿里短信
+
         $params['mobile'] = $mobile;
         $params['code'] = $code;
 
-        $result = self::smsSend($params);
+        //阿里短信
+        //$result = self::smsSend($params);
+        //奇讯云短信
+        $result = self::qxySend($params);
 
         if (!$result) {
             $sms->delete();
@@ -91,6 +94,21 @@ class Sms
     }
 
     /**
+     * 短信发送行为
+     * @param array $params 必须包含mobile,event,code
+     * @return  boolean
+     */
+    public static function qxySend($params)
+    {
+        $config = config('qxysms');
+
+        $alisms = new Qxysms($config);
+        $result = $alisms->send($params['mobile'],$params['code']);
+
+        return $result;
+    }
+
+    /**
      * 发送通知
      *
      * @param   mixed  $mobile   手机号,多个以,分隔

+ 14 - 5
application/config.php

@@ -377,12 +377,21 @@ return [
         'app_code'   => 'a4c5dc1c580a4d9dab323286c2780328',
     ],
 
-    //阿里云短信配置,  借用tken
+    //阿里云短信配置
     'alisms' =>[
-        'template_cn' => 'SMS_267360101', //国内
-        'sign' => 'TKEN',
-        'key' => 'LTAI5tE7djEZAXJcLtxshRu5',
-        'secret' => 'MK7sRjd2rpZ4PEbngf76PvKhvpTJWc',
+        'template_cn' => '', //国内
+        'sign'        => '',
+        'key'         => '',
+        'secret'      => '',
+    ],
+
+    //奇讯云短信配置  安心聊正式
+    'qxysms' =>[
+        'host'      => 'http://sms.qxcioud.com:9090',
+        'appKey'    => 'Rt3KnN',
+        'appSecret' => 'Hr7SRi',
+        'appCode'   => '1000',
+        'signName'  => '珍友',//重庆创星悦网络科技有限公司
     ],
 
     //环信推送 没用到