<address id="bhhjf"><form id="bhhjf"><th id="bhhjf"></th></form></address>

      <address id="bhhjf"><nobr id="bhhjf"><meter id="bhhjf"></meter></nobr></address>
      <address id="bhhjf"><address id="bhhjf"><listing id="bhhjf"></listing></address></address>
      <form id="bhhjf"></form>

        <address id="bhhjf"><form id="bhhjf"><nobr id="bhhjf"></nobr></form></address>

        <address id="bhhjf"></address><noframes id="bhhjf">

        <form id="bhhjf"><th id="bhhjf"><th id="bhhjf"></th></th></form>
        <noframes id="bhhjf"><address id="bhhjf"><th id="bhhjf"></th></address>

        0712-2888027 189-8648-0214
        微信公眾號

        孝感風信網絡科技有限公司微信公眾號

        當前位置:主頁 > 技術支持 > DedeCMS > 織夢dedecms短信驗證碼功能(阿里短信)

        織夢dedecms短信驗證碼功能(阿里短信)

        時間:2023-09-04來源:風信官網 點擊: 503次
        現在大部分網站都需要用短信驗證碼,因為織夢官方沒有短信驗證碼插件,所以寫了幾個短信驗證碼插件,一個使用的是阿里云的短信驗證碼接口,一個使用的是阿里大于的短信驗證碼接口,一個使用的是阿里通信短信驗證碼接口,另外一個使用的是云之訊的短信接口。下面的教程包含2個織夢短信驗證碼接口。



        織夢會員短信注冊需要修改的地方:
         
        1、需要創建一個表來對驗證碼進行記錄,防止多次發送,這里創建了一個phonecode表。
        2、member/templets/reg-new.htm (注冊模版添加元素)
        3、member/templets/js/reg_new.js (驗證手機號)
        4、member/index_do.php (根據后臺設置,判斷是否發送注冊驗證碼)
        5、member/reg_new.php (驗證、記錄)



        a.使用阿里云短信接口接入:
         
        需要在member/index_do.php對應的位置插入阿里云短信接口代碼。特別需要注意的是,阿里云短信官方demo文檔是大神寫的,所以普通人用起來會報命名空間錯誤,這個需要自己注意。另外需要更新下短息模板,現在阿里短信模板審核非常嚴格,不允許有其他變量,之前并沒有這個問題。所以,審核不過的時候,需要減少變量。(目前已經無法開通阿里云短信接口,新開通的是阿里通信接口,不能使用這段代碼,只適合很久之前就開通過阿里云短信的人)
         
        function getrandchar($length){
            $str = null;
            $strPol = "0123456789abcdefghijklmnopqrstuvwxyz";
            $max = strlen($strPol)-1;
                for($i=0;$i<$length;$i++){
                $str.=$strPol[rand(0,$max)];
                }
                return $str;
            }
            $code = getrandchar(5);
         
            require_once(DEDEINC.'/aliyun-php-sdk-core/Config.php');
            use Sms\Request\V20160927 as Sms;
            $iClientProfile = DefaultProfile::getProfile("cn-shenzhen", "your accessKey", "your accessSecret"); //登錄阿里云查看: "your accessKey", "your accessSecret"
            $client = new DefaultAcsClient($iClientProfile);  
            $request = new Sms\SingleSendSmsRequest();
            $request->setSignName("簽名");/*簽名名稱*/
            $request->setTemplateCode("SMS_1111");/*模板code*/
            $request->setRecNum($phone);/*目標手機號*/
            $request->setParamString("{\"code\":\"$code\",\"tel\":\"電話號碼\"}");/*模板變量,請確保跟審核過的短信模版變量一致,數字一定要轉換為字符串*/
            try {
                $response = $client->getAcsResponse($request);
                print_r($response);
            }
            catch (ClientException  $e) {
                print_r($e->getErrorCode()); 
                print_r($e->getErrorMessage()); 
            }
            catch (ServerException  $e) { 
                print_r($e->getErrorCode()); 
                print_r($e->getErrorMessage());
            }

            $inquery = " INSERT INTO `dede_phonecode` (`ip`,`phone`,`phonecode`,`used`,`sendtime`) VALUES ( '$ip','$to','$code','1','$nowtime'); ";
            $rs = $dsql->ExecuteNoneQuery2($inquery);
            if( $rs = 1 ){
                ShowMsg('發送成功,請注意查收!','-1');
                exit();
            }
            exit();

        附上阿里云短信模版:驗證碼:${code}。您正在注冊,如非您本人操作,請忽略此條短信。如有疑問請與我們聯系! 電話:${tel}

        b.使用阿里大魚的短信接口接入:
         
        同樣的需要在member/index_do.php對應的位置插入以下代碼。
         
        function getrandchar($length){
            $str = null;
            //$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
            $strPol = "0123456789abcdefghijklmnopqrstuvwxyz";
            $max = strlen($strPol)-1;
                for($i=0;$i<$length;$i++){
                $str.=$strPol[rand(0,$max)];
                }
                return $str;
            }
            $code = getrandchar(5);

            require_once(DEDEINC.'/alidayu-php-sdk/TopSdk.php');
            $client = new TopClient;
            $client ->appkey = '111111' ; //登錄阿里大于查看appkey。
            $client ->secretKey = 'aaaaaaaaaaaaaa' ; //登錄阿里大于查看secret。
            $req = new AlibabaAliqinFcSmsNumSendRequest;
            $req ->setExtend( "" );
            $req ->setSmsType( "normal" );
            $req ->setSmsFreeSignName( "城子居" ); /*簽名名稱*/
            $req ->setSmsParam( "{\"code\":\"$code\",\"name\":\"注冊\"}" ); /*模板變量,請確保跟審核過的短信模版變量一致,數字一定要轉換為字符串*/
            $req ->setRecNum($phone);/*目標手機號*/
            $req ->setSmsTemplateCode( "SMS_1111111" );//登錄阿里大于查看/*模板ID編號*/
            $resp = $client ->execute( $req );

            $inquery = " INSERT INTO `imm_phonecode` (`ip`,`phone`,`phonecode`,`used`,`sendtime`)  VALUES ( '$ip','$to','$code','1','$nowtime'); ";
            $rs = $dsql->ExecuteNoneQuery2($inquery);
            if( $rs = 1 ){
                ShowMsg('發送成功,請注意查收!','-1');
                exit();
            }
            exit();

        c.使用最新的阿里通信短信接口接入:

        function getrandchar($length){
        $str = null;
        //$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        $strPol = "0123456789";
        $max = strlen($strPol)-1;
            for($i=0;$i<$length;$i++){
            $str.=$strPol[rand(0,$max)];
            }
            return $str;
        }
        $number = getrandchar(4);
         
        require_once(DEDEINC.'/aliyun-php-sdk-core/Config.php');
        require_once(DEDEINC.'/Dysmsapi/Request/V20170525/SendSmsRequest.php');
        require_once(DEDEINC.'/Dysmsapi/Request/V20170525/QuerySendDetailsRequest.php');

        function sendSms() {
            global $phone, $number;
            
            //此處需要替換成自己的AK信息
            $accessKeyId = "yourAccessKeyId";
            $accessKeySecret = "yourAccessKeySecret";
            //短信API產品名
            $product = "Dysmsapi";
            //短信API產品域名
            $domain = "dysmsapi.aliyuncs.com";
            //暫時不支持多Region
            $region = "cn-beijing";
            
            //初始化訪問的acsCleint
            $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
            DefaultProfile::addEndpoint("cn-beijing", "cn-beijing", $product, $domain);
            $acsClient= new DefaultAcsClient($profile);
            
            $request = new Dysmsapi\Request\V20170525\SendSmsRequest;
            //必填-短信接收號碼
            $request->setPhoneNumbers($phone);
            //必填-短信簽名
            $request->setSignName("99商鋪網");
            //必填-短信模板Code
            $request->setTemplateCode("SMS_74725029");
            //選填-假如模板中存在變量需要替換則為必填(JSON格式)
            $request->setTemplateParam("{\"number\":\"$number\"}");
            //選填-發送短信流水號
            $request->setOutId("1234");
            
            //發起訪問請求
            $acsResponse = $acsClient->getAcsResponse($request);
        }

        sendSms();
         
        $inquery = " INSERT INTO `imm_phonecode` (`ip`,`phone`,`phonecode`,`used`,`sendtime`)  VALUES ( '$ip','$phone','$number','1','$nowtime'); ";
        $rs = $dsql->ExecuteNoneQuery2($inquery);
        if( $rs = 1 ){
            echo "發送成功,請注意查收!";
            exit();
        }
        exit();

        到這里阿里系的3個短信接口就全都在這里了,對應的SDK需要在阿里云官方查找下載。

        d.使用云之訊短信接口接入:
         
        同樣的需要在member/index_do.php對應的位置插入云之訊短信接口代碼。

        function getrandchar($length){
        $str = null;
        $strPol = "0123456789abcdefghijklmnopqrstuvwxyz";
        $max = strlen($strPol)-1;
        for($i=0;$i<$length;$i++){
        $str.=$strPol[rand(0,$max)];
        }
        return $str;
        }
        require_once(DEDEINC.'/ucpaas.class.php');
        $options['accountsid']='';  //對應ucpaas.com用戶ID
        $options['token']='';  //對應ucpaas.com里面的用戶token
        $ucpass = new Ucpaas($options);
        $appId = ""; //對應ucpaas.com里面的項目ID
        $to = $phone;
        $templateId = ""; //對應ucpaas.com里面的短信模版ID
        $code = getrandchar(5);
        $param= $code.',短信模版參數2'.',短信模版參數3'; // $code為生成的驗證碼,短信模版參數2,短信模版參數3,參數之間用英文逗號間隔。
        $ucpass->templateSMS($appId,$to,$templateId,$param);
        $inquery = " INSERT INTO `dede_phonecode` (`ip`,`phone`,`phonecode`,`used`,`sendtime`) VALUES ( '$ip','$to','$code','1','$nowtime'); ";
        $rs = $dsql->ExecuteNoneQuery2($inquery);
        if( $rs = 1 ){
        ShowMsg('發送成功,請注意查收!','-1');
        exit();
        }
        exit();

        同樣的附上短信模版:驗證碼:{1}。您正在{2},如非您本人操作,請忽略此條短信。如有疑問請與我們聯系!  電話:{3}
        欄目列表
        推薦內容
        熱點內容
        展開