日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > HTML >内容正文

HTML

【转】前端验证码倒计时、后台发送验证码、创蓝短信接口

發(fā)布時(shí)間:2024/1/1 HTML 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】前端验证码倒计时、后台发送验证码、创蓝短信接口 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前端代碼:倒計(jì)時(shí)

<!DOCTYPE html>
<html>
<head lang="en">
? ? <meta charset="UTF-8">
? ? <title></title>


? ? <style>
? ? ? ? .yanzm_b_btn {
? ? ? ? ? ? width: 98px;
? ? ? ? ? ? height: 40px;
? ? ? ? ? ? float: left;
? ? ? ? ? ? line-height: 40px;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? border-radius: 5px;
? ? ? ? ? ? background: #f0f0f0;
? ? ? ? ? ? color: #aeaeae;
? ? ? ? ? ? font-size: 14px;
? ? ? ? ? ? margin-left: 10px;
? ? ? ? ? ? border: none;
? ? ? ? ? ? margin-bottom: 30px;
? ? ? ? }
? ? </style>
? ? <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
? ? </script>
</head>
<body>
? ? <input class="register_b_shouji" type="text" placeholder="請(qǐng)輸入手機(jī)號(hào)" name="E_Mobile" id="E_Mobile">
? ? <input class="yanzm_b_btn" type="button" value="發(fā)送驗(yàn)證碼" οnclick="GetCodemo(this)"/>
</body>
</html>
<script>
? ? var wait = 60;
? ? function GetCodemo(o){
? ? ? ? //發(fā)送驗(yàn)證碼
? ? ? ? if(wait == 60){
? ? ? ? ? ? //發(fā)送驗(yàn)證碼
? ? ? ? ? ? var mobile = $("#E_Mobile").val();
? ? ? ? ? ? if(mobile!=""){
? ? ? ? ? ? ? ? //請(qǐng)求后臺(tái)獲取數(shù)據(jù)、
? ? ? ? ? ? ? ? $.post('getMobileCode',{mobile:mobile,type:'reg'},function(data){
? ? ? ? ? ? ? ? ? ? if(data.status==1){
? ? ? ? ? ? ? ? ? ? ? ? //發(fā)送成功
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? //發(fā)送失敗
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? },'json');
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? $("#E_Mobile").focus();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(wait ==0){
? ? ? ? ? ? o.removeAttribute('disabled');//禁用
? ? ? ? ? ? o.value= '重新發(fā)送';
? ? ? ? ? ? wait = 60;
? ? ? ? }else{
? ? ? ? ? ? o.setAttribute('disabled',true);
? ? ? ? ? ? o.value= "已發(fā)送("+wait+")";wait--;
? ? ? ? ? ? setTimeout(function(){GetCodemo(o)},1000);
? ? ? ? }
? ? }


</script>

后端發(fā)送驗(yàn)證碼代碼:

?

/**
? ? ?* 發(fā)送驗(yàn)證碼
? ? ?*/
? ? public function getMobileCode(){
? ? ? ? header("content-type:text/html; charset=utf-8");
? ? ? ? $Mobile = $_POST ["mobile"]; ? ? ?//用戶修改的手機(jī)號(hào)


? ? ? ? $type = trim($_POST["type"]); // 定義用來(lái)發(fā)送短信
? ? ? ? $type = empty($type)?"reg":$type; //短信模版代碼
? ? ? ? if (!empty($type) && strlen($Mobile)==11){
? ? ? ? ? ? $Template = M("pagetemplate")->where(array("E_Type"=>$type))->cache(true,6000)->find(); ? //判斷類型,發(fā)送驗(yàn)證碼有多個(gè)地方使用到,比如找回密碼,注冊(cè)等
? ? ? ? ? ? if(empty($Template)) $this->jsonReturn(0, "短信類型異常!", '');
? ? ? ? ? ? if(!empty($Template['ID'])){
? ? ? ? ? ? ? ? $Code ? ?= getCode(5);//驗(yàn)證碼
? ? ? ? ? ? ? ? $sendstr = str_replace("0000", "", $Template["E_Template"]); ?//發(fā)送驗(yàn)證碼文本、替換、例子:你正在注冊(cè)某某商城,驗(yàn)證碼為0000,[某某商城]
? ? ? ? ? ? ? ? $result ?= sendSMS($Mobile, $sendstr, 'true'); ?//調(diào)用創(chuàng)藍(lán)短信方法
? ? ? ? ? ? ? ? $result = $this->execResult($result); ?//處理返回值
? ? ? ? ? ? ? ? if($result[1] == "0") { ?//返回的是一個(gè)數(shù)組、狀態(tài)碼 0 是成功
? ? ? ? ? ? ? ? ? ? $seReCode = $Mobile . "," . $Code;
? ? ? ? ? ? ? ? ? ? $_SESSION['MobileCode'] = $seReCode;
? ? ? ? ? ? ? ? ? ? $this->jsonReturn(1, "發(fā)送成功!", '');
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? $this->jsonReturn(0, "發(fā)送失敗!", '');
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? $this->jsonReturn(0, "異常、非法操作!", '');
? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? $this->jsonReturn(0, "異常、非法手機(jī)號(hào)!", '');
? ? ? ? }
? ? }


/**
* 查詢額度
*
* 查詢地址
*/
protected function queryBalance() {
$chuanglan_config = $this->GetInterfacecon ( 'message' );
// 查詢參數(shù)
$postArr = array (
'account' => $chuanglan_config ["ConS"] ['USERID'] ['val'],
'pswd' => $chuanglan_config ["ConS"] ['PWD'] ['val']?
);
$result = $this->curlPost ( $chuanglan_config ["ConS"] ['URLQ'] ['val'], $postArr );
return $result;
}

/**
* 處理返回值
*/
protected function execResult($result) {
$result = preg_split ( "/[,\r\n]/", $result );
return $result;
}

/**
* 通過CURL發(fā)送HTTP請(qǐng)求
*
* @param string $url
* ? ? ? ??//請(qǐng)求URL
* @param array $postFields
* ? ? ? ??//請(qǐng)求參數(shù)
* @return mixed
*/
protected function curlPost($url, $postFields) {
$postFields = http_build_query ( $postFields );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
$result = curl_exec ( $ch );
curl_close ( $ch );
// dump ( $result );
return $result;
}


/**
* 發(fā)送短信
*
* @param string $mobile
* ? ? ? ??手機(jī)號(hào)碼
* @param string $msg
* ? ? ? ??短信內(nèi)容
* @param string $needstatus
* ? ? ? ??是否需要狀態(tài)報(bào)告
* @param string $product
* ? ? ? ??產(chǎn)品id,可選
* @param string $extno
* ? ? ? ??擴(kuò)展碼,可選
*/
protected function sendSMS($mobile, $msg, $needstatus = 'false', $product = '', $extno = '') {

// 創(chuàng)藍(lán)接口參數(shù)
$postArr = array (
'account' => '',//賬號(hào)
'pswd' => '',//密碼
'msg' => $msg, //發(fā)送內(nèi)容
'mobile' => $mobile, //手機(jī)號(hào)
'needstatus' => $needstatus,
'product' => $product,
'extno' => $extno?
);
$result = $this->curlPost ( $chuanglan_config ["ConS"] ['URL'] ['val'], $postArr );
return $result;
}

官方文檔:https://www.253.com/api-docs-5.html,狀態(tài)碼地址:https://www.253.com/api-docs-1.html

版權(quán)聲明:本文為博主原創(chuàng)文章,可以轉(zhuǎn)載 https://blog.csdn.net/hua950327/article/details/78064801

轉(zhuǎn)載于:https://www.cnblogs.com/apolloren/p/9260969.html

總結(jié)

以上是生活随笔為你收集整理的【转】前端验证码倒计时、后台发送验证码、创蓝短信接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。