<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2023/7/8
 * Time: 14:56
 */

namespace app\lib\sms;
use app\common\library\Sms as Smslib;
use think\Exception;
use think\Log;

class DxSms
{
    /**
     * 通用短信验证(登录注册)
     * @param $mobile
     * @param string $smstemplate
     * @return bool
     * @date
     */
    public static function sendCodeSms($mobile, $event )
    {
        $code = rand(10000, 99999);
        $info = "您的验证码：" . $code . "，您正进行身份验证，打死不告诉别人！";
        try {
            $result = ZthySms::sendSms($mobile, $info);
            $res = json_decode($result, true);
            if (isset($res['code']) && $res['code'] == 200) {
                $ret = Smslib::send($mobile, $code, $event);
                if (!$ret) {
                    return false;
                }
            }
        } catch (Exception $e) {
            Log::write("错误", json_encode($e));
            return false;
        }
        return true;

    }
}