Browse Source

留言以及短信server

胖虎 2 years ago
parent
commit
e0c302e1aa

+ 3 - 23
app/Http/Controllers/AdminApi/ConfigController.php

@@ -13,10 +13,10 @@ class ConfigController extends AdminController
     }
 
     /**
-     * 获取&更新消费金奖励规则
+     * 获取&更新基础配置信息
      * @return \Illuminate\Http\JsonResponse
      */
-    function setConsume(){
+    function setConfig(){
         if(request()->isMethod('post')){
             $data = request()->all();
             //更新config数据
@@ -24,27 +24,7 @@ class ConfigController extends AdminController
 
             return $this->apiResponseSuccess('更新成功');
         }else{
-            $configs = Config::whereIn('key',['consume_money','consume_for','consume_give'])->pluck('value','key');
-            return $this->apiResponseSuccess('获取成功',$configs);
-        }
-    }
-
-    /**
-     *获取&更新振合豆使用规则
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function setBean(){
-        if(request()->isMethod('post')){
-            $data = request()->all();
-            //金额固定为1
-            $data['use_bean'] = 1;
-            $data['bean_money'] = 1;
-            //更新config数据
-            $this->update($data);
-
-            return $this->apiResponseSuccess('更新成功');
-        }else{
-            $configs = Config::whereIn('key',['is_bean','bean_money','bean_give','use_bean','offset_bean_money','is_bean_expense'])->pluck('value','key');
+            $configs = Config::whereIn('key',['logo','title','tel','email','address','wx_image','icp','put_on_record'])->pluck('value','key');
             return $this->apiResponseSuccess('获取成功',$configs);
         }
     }

+ 78 - 0
app/Http/Controllers/AdminApi/MessageController.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Controllers\AdminApi;
+
+use App\Models\MessageModels\Message;
+use App\Http\Controllers\AdminController;
+
+class MessageController extends AdminController
+{
+
+    /**
+     * 获取留言列表
+     * @return \Illuminate\Http\JsonResponse
+     */
+    function getList(){
+        $name = request()->input('name','');//获取搜索名称
+        $phone = request()->input('phone','');//获取搜索手机号
+        $start = request()->input('start','');//获取开始时间
+        $end = request()->input('end','');//获取结束时间
+
+        //查询数据条件
+        $where = [['is_del',0]];
+        if ($name) $where[] = ['name', 'like', "%$name%"];
+        if ($phone) $where[] = ['phone', 'like', "%$phone%"];
+        if ($start) $where[] = ['created_at', '>=', $start];
+        if ($end) $where[] = ['created_at', '<=', $end];
+
+        //获取数据
+        $list = Message::where($where)
+            ->orderBy('id','desc')
+            ->select(['id','name','phone','created_at'])
+            ->paginate(10);
+
+        return $this->apiResponseSuccess('获取信息成功', [
+            'list' => $list->items(),
+            'total' => $list->total(),
+            'limit' => 10
+        ]);
+    }
+
+    /**
+     * 获取记录详情
+     * @return \Illuminate\Http\JsonResponse
+     */
+    function getInfo()
+    {
+        $id = request()->input('id', '');//获取需要查询的记录id
+        if (empty($id)) return $this->apiResponseError('缺少必要参数');
+
+        //查询数据
+        $where = [['id', $id], ['is_del',0]];
+        $info = Message::where($where)->select(['id', 'name', 'phone', 'content', 'created_at'])->first();
+
+        if (empty($info)) return $this->apiResponseError('没有找到该记录');
+
+        return $this->apiResponseSuccess('获取成功', $info);
+    }
+
+
+    /**
+     * 删除(批量)记录
+     * @return \Illuminate\Http\JsonResponse
+     */
+    function destroys(){
+        $ids = request()->input('ids','');//获取需要删除的id
+        if(empty($ids)) return $this->apiResponseError('缺少必要参数');
+
+        //数据条件
+        if(!is_array($ids)) return $this->apiResponseError('数据格式错误');
+
+        $res = Message::whereIn('id',$ids)->update(['is_del' => 1]);
+        if ($res) {
+            return $this->apiResponseSuccess('删除成功');
+        } else {
+            return $this->apiResponseError('删除失败');
+        }
+    }
+}

+ 39 - 0
app/Models/MessageModels/Message.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Models\MessageModels;
+
+use App\Models\Traits\Timestamp;
+use Illuminate\Database\Eloquent\Model;
+
+class Message extends Model
+{
+    use Timestamp;
+    /**
+     * 表名。
+     *
+     * @var string
+     */
+    protected $table = 'messages';
+
+    /**
+     * 与表关联的主键。
+     *
+     * @var string
+     */
+    protected $primaryKey = 'id';
+
+    /**
+     * 是否主动维护时间戳
+     *
+     * @var bool
+     */
+    public $timestamps = true;
+
+    /**
+     * 不能被批量赋值的属性
+     *
+     * @var array
+     */
+    protected $guarded = ['id', 'updated_at', 'created_at'];
+
+}

+ 118 - 0
app/Servers/Common/SmsServer.php

@@ -0,0 +1,118 @@
+<?php
+
+
+namespace App\Servers\Common;
+
+use End01here\EasySms\EasySmsService;
+
+
+/**
+ * 短信发送类
+ */
+class SmsServer
+{
+
+
+    /**
+     * 错误信息
+     * @var string
+     */
+    private $errorMsg = '';
+
+
+    private function __construct()
+    {
+    }
+
+    /**
+     * 创建对象
+     * @return SmsServer
+     */
+    static function creatServer()
+    {
+        return new SmsServer();
+    }
+
+    /**
+     * @return string
+     */
+    public function getErrorMsg(): string
+    {
+        return $this->errorMsg;
+    }
+
+    /**
+     * 发送短信
+     * @param $phone_num
+     * @param $send_type
+     * @return bool
+     * @throws \End01here\EasySms\Exceptions\CodeErrorException
+     * @throws \End01here\EasySms\Exceptions\GatewayErrorException
+     * @throws \End01here\EasySms\Exceptions\MessageException
+     */
+    function sendCode($phone_num,$send_type='default')
+    {
+        try {
+            $phone = EasySmsService::getPhoneSever($phone_num);
+            $code_server = EasySmsService::getCodeSever($phone)->setCode($send_type);
+            $message_server = EasySmsService::getMessageServer();
+            $content = '您好,你的验证码:' . $code_server->getCode();
+//            $content = '您好,你的验证码:[var] ' ;
+            $message_server->setContent($content);
+            $send_info = EasySmsService::getSmsServer()->creatQybSms()->send($phone, $message_server);
+        }catch (\Exception $e){
+            $this->errorMsg=$e->getMessage();
+            return false;
+        }
+
+        if (!empty($send_info['code']) && $send_info['code'] != 1) {
+            $this->errorMsg = '短信发送失败';
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 有留言通知发送短信
+     * @param $phone_num
+     * @return bool
+     */
+    function sendPayNotice($phone_num)
+    {
+        try {
+            $phone = EasySmsService::getPhoneSever($phone_num);
+            $message_server = EasySmsService::getMessageServer();
+
+            $content = '您好,官网有新的留言,请您及时查看。';
+            $message_server->setContent($content);
+            $send_info = EasySmsService::getSmsServer()->creatQybSms()->send($phone, $message_server);
+        }catch (\Exception $e){
+            $this->errorMsg=$e->getMessage();
+            return false;
+        }
+
+        if (!empty($send_info['code']) && $send_info['code'] != 1) {
+            $this->errorMsg = '短信发送失败';
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 验证码验证
+     * @param $phone_num
+     * @param $code
+     * @param $send_type
+     * @return bool
+     */
+    public function verifyCode($phone_num, $code,$send_type='default')
+    {
+        $phone = EasySmsService::getPhoneSever($phone_num);
+        $code_sever= EasySmsService::getCodeSever($phone);
+        $ret_code = $code_sever->verifyCode($code,$send_type);
+        $this->errorMsg=$code_sever->getErrorMsg();
+        return $ret_code;
+    }
+
+
+}

+ 1 - 0
composer.json

@@ -7,6 +7,7 @@
     "require": {
         "php": "^7.3|^8.0",
         "alibabacloud/sdk": "^1.8",
+        "end01here/easy-sms": "^1.0",
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
         "laravel/framework": "^8.75",

+ 44 - 6
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "0aea38a9727665403b2dc934fc4fc0eb",
+    "content-hash": "a08e62d9e96f37626509f949bf6b9c45",
     "packages": [
         {
             "name": "adbario/php-dot-notation",
@@ -146,16 +146,16 @@
         },
         {
             "name": "alibabacloud/sdk",
-            "version": "1.8.1471",
+            "version": "1.8.1472",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aliyun/openapi-sdk-php.git",
-                "reference": "e70053be0d2bbf1a2dfaa1335faab55024b01df0"
+                "reference": "903ea5926d4d15e2b592eab4d458fdde6c4fb46f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aliyun/openapi-sdk-php/zipball/e70053be0d2bbf1a2dfaa1335faab55024b01df0",
-                "reference": "e70053be0d2bbf1a2dfaa1335faab55024b01df0",
+                "url": "https://api.github.com/repos/aliyun/openapi-sdk-php/zipball/903ea5926d4d15e2b592eab4d458fdde6c4fb46f",
+                "reference": "903ea5926d4d15e2b592eab4d458fdde6c4fb46f",
                 "shasum": ""
             },
             "require": {
@@ -380,7 +380,7 @@
                 "issues": "https://github.com/aliyun/openapi-sdk-php/issues",
                 "source": "https://github.com/aliyun/openapi-sdk-php"
             },
-            "time": "2022-09-08T13:27:25+00:00"
+            "time": "2022-09-13T02:47:05+00:00"
         },
         {
             "name": "asm89/stack-cors",
@@ -981,6 +981,44 @@
             ],
             "time": "2020-12-29T14:50:06+00:00"
         },
+        {
+            "name": "end01here/easy-sms",
+            "version": "v1.0.12",
+            "source": {
+                "type": "git",
+                "url": "https://gitee.com/lcpcp/easy-sms.git",
+                "reference": "0b5c300447c6f4a9cbd45142f719eb6fd2cfe748"
+            },
+            "require": {
+                "illuminate/redis": "*"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "End01here\\EasySms\\EasySmsServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "End01here\\EasySms\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "authors": [
+                {
+                    "name": "lihang",
+                    "email": "448212125@qq.com"
+                }
+            ],
+            "description": "easy-sms",
+            "keywords": [
+                "easy-sms",
+                "laravel"
+            ],
+            "time": "2022-05-27T14:01:05+00:00"
+        },
         {
             "name": "fruitcake/laravel-cors",
             "version": "v2.2.0",

+ 33 - 0
config/easy_sms.php

@@ -0,0 +1,33 @@
+<?php
+
+return [
+    //code码验证存储方式
+    'cache_type' => env('CACHE_SMS_TYPE','redis'),
+    //短信有效时长(分钟)
+    'cache_time' => env('CACHE_SMS_TIME','15'),
+    //短信最短重发时间(秒)
+    'mix_time' => env('CACHE_MIX_TIME','60'),
+    //签名信息
+    'sign_text'=>env('SIGN_TEXT',''),
+    //请求超时时间
+    'timeout'=>env('SMS_TIMEOUT',''),
+    //是否开启通用验证码
+    'is_current'=>env('IS_CURRENT',false),
+    //通用验证码
+    'current_code'=>env('CURRENT_CODE','1234'),
+    //kewail平台短信配置信息
+    'kewail' => [
+        'accesskey' => env('KEWAIL_ACCESSKEY',''),
+        'secretkey' => env('KEWAIL_SECRETKEY',''),
+    ],
+    //阿里云短信配置
+    'ali' => [
+        'access_key_id' => env('ALI_ACCESS_KEY_ID',''),
+        'secretkey' => env('ALI_ACCESS_KEY',''),
+    ],
+    //企业宝短信配置
+    'qyb' => [
+        'username' => env('QYB_USERNAME',''),
+        'password' => env('QYB_PASSWORD',''),
+    ]
+];