1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php发送短信验证码

php发送短信验证码

时间:2024-01-14 01:43:52

相关推荐

php发送短信验证码

D:\phpStudy\WWW\phpcms\libs\functions\sms.func.php

<?php

classlbg{

public $returncode;

public $msg;

public $comment;

}

classmpages{

public $pagesize;

public $page;

public $total;

public $data;

}

/**

* 发送验证码

*@copyright(C) - PHPCMS

*@license/license/

*@lastmodify-6-1

*/

functionmsendmsg($mobile, $type,$password="",$isecho=true){

if($type =="yanzheng") {

$password ="您的新验证码为". random(6,"123456789abcdefghkmnrstwxy");

}else if($type =="pwd") {

// $password = "您的新密码为" . random(8, "123456789abcdefghkmnrstwxy");

}

$murl ="http://10.92.105.201:8000/mtPort/mt2?";

$murl .="phonelist=". $mobile ."&content=". $password .",请注意查收。【ppppp】";

$murl .="&pwd=afsdfsdfsdfsdgwerrewtert&uid=282";

$ch =curl_init();

//设置选项,包括URL

curl_setopt($ch,CURLOPT_URL, $murl);

curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch,CURLOPT_HEADER, 0);

//执行并获取HTML文档内容

$result =curl_exec($ch);

//释放curl句柄

curl_close($ch);

//打印获得的数据

$result =preg_replace(array('/\s*(<br\s*\/?\s*>\s*){2,}/im','/(<p>(\s|\s*<br\s*\/?\s*>\s*)*<\/p>)+/im'),array('\\1\\1',''),$result);

$xml =simplexml_load_string($result);

$code = $xml->CODE;//这里返回的依然是个SimpleXMLElement对象,不能改为小写,

if($code =='0') {

if($isecho){

retError(0,"验证码发送成功",$password);

}

}else{

//验证码发送失败

retError($code, $result->description);

}

}

functionretError($code, $msg,$comment="")

{

$lbg =newlbg();

$lbg->returncode= $code;

$encode =mb_detect_encoding($comment,array("ASCII","GB2312","UTF-8","GBK","BIG5"));

$comment =iconv($encode,"gbk", $comment);

$lbg->comment= $comment;

$encode =mb_detect_encoding($msg,array("ASCII","GB2312","UTF-8","GBK","BIG5"));

$msg =iconv($encode,"gbk", $msg);

$lbg->msg= $msg;

echoJSON_o($lbg);

}

functionreturn_Msg($code, $msg,$comment="")

{

$lbg =newlbg();

$lbg->returncode= $code;

$lbg->comment= $comment;

$encode =mb_detect_encoding($msg,array("ASCII","GB2312","UTF-8","GBK","BIG5"));

if($encode =="UTF-8") {

$msg =iconv("utf-8","GBK", $msg);

}

$lbg->msg= $msg;

echojsonFormat($lbg,"");

}

functionJSON_o($array)

{

arrayRecursive_o($array,'urlencode',true);

$json = json_encode($array);

returnurldecode($json);

}

functiontogbk($str){

$encode =mb_detect_encoding($str,array("ASCII","GB2312","UTF-8","GBK","BIG5"));

$str =iconv($encode,"gbk",$str);

return($str);

}

functionarrayRecursive_o(&$array, $function, $apply_to_keys_also =false)

{

foreach($arrayas$key => $value) {

if(is_array($value)) {

arrayRecursive_o($array->$key, $function, $apply_to_keys_also);

}else{

$array->$key= $function($value);

}

if($apply_to_keys_also &&is_string($key)) {

$new_key = $function($key);

if($new_key != $key) {

$array->$new_key= $array->$key;

unset($array->$key);

}

}

}

}

functionarrayRecursive(&$array, $function, $apply_to_keys_also =false)

{

foreach($arrayas$key => $value) {

if(is_array($value)) {

arrayRecursive($array[$key], $function, $apply_to_keys_also);

}else{

// echo $key. $function($value)."\n";

$str=str_replace(array("\r\n","\r","\n"),"", $value);

$str= toutf8($str);

$str= $function($str);

$array[$key] =$str;

}

if($apply_to_keys_also &&is_string($key)) {

$new_key = $function($key);

if($new_key != $key) {

$array[$new_key] = $array[$key];

unset($array[$key]);

}

}

}

}

/**************************************************************

* 将数组转换为JSON字符串(兼容中文)

*@paramarray $array 要转换的数组

*@returnstring 转换得到的json字符串

*@accesspublic

*************************************************************/

functionJSON($array) {

arrayRecursive($array,'urlencode',true);

$json = json_encode($array);

returnurldecode($json);

}

functiontoutf8($str){

$encode =mb_detect_encoding($str,array("ASCII","GB2312","UTF-8","GBK","BIG5"));

$str =iconv($encode,"GBK//IGNORE",$str);

return($str);

}

/** Json数据格式化

*@paramMixed $data 数据

*@paramString $indent 缩进字符,默认4个空格

*@returnJSON

*/

functionjsonFormat($data, $indent=""){

// 对数组中每个元素递归进行urlencode操作,保护中文字符

array_walk_recursive($data,'jsonFormatProtect');

// json encode

$data = json_encode($data);

// 将urlencode的内容进行urldecode

$data =urldecode($data);

// 缩进处理

$ret ='';

$pos = 0;

$length =strlen($data);

$indent =isset($indent)? $indent :'';

$newline ="";//"\n";

$prevchar ='';

$outofquotes =true;

for($i=0; $i<=$length; $i++){

$char =substr($data, $i, 1);

if($char=='"'&& $prevchar!='\\'){

$outofquotes = !$outofquotes;

}elseif(($char=='}'|| $char==']') && $outofquotes){

$ret .= $newline;

$pos --;

for($j=0; $j<$pos; $j++){

$ret .= $indent;

}

}

$ret .= $char;

if(($char==','|| $char=='{'|| $char=='[') && $outofquotes){

$ret .= $newline;

if($char=='{'|| $char=='['){

$pos ++;

}

for($j=0; $j<$pos; $j++){

$ret .= $indent;

}

}

$prevchar = $char;

}

return$ret;

}

/** 将数组元素进行urlencode

*@paramString $val

*/

functionjsonFormatProtect(&$val){

if($val!==true&& $val!==false&& $val!==null){

$val =urlencode($val);

}

}

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。