<?php


namespace App\Services;


use App\Http\Controllers\Api\BuKaSendController;
use App\Http\Controllers\Api\KmiSendController;
use App\Http\Controllers\Api\PlantsSendController;
use App\Http\Controllers\Api\ZhangRongSendController;
use Illuminate\Support\Facades\Redis;

class SendCode
{
    public function sendCode($type)
    {
        switch ($type) {
            case 1:
                return new BuKaSendController();
                break;
            case 2:
                return new ZhangRongSendController();
                break;
            case 3:
                return new PlantsSendController();
                break;

            case 4:
                return new KmiSendController();
                break;
        }
    }


    /**
     * 给请求的IP，手机号做存储，并限制
     * @param $ip
     * @param $phone
     */
    public function redisPhoneCode($ip, $phone)
    {
        // 过期时间，当天有效
        $expireTime = mktime(23, 59, 59, date("m"), date("d"), date("Y"));

        $redis = Redis::connection();
        $redis->incr($ip);
        $redis->incr($phone);

        //设置键的过期时间
        $redis->expireAt($ip, $expireTime);
        $redis->expireAt($phone, $expireTime);
    }
}
