php发送短信验证码

网友投稿 724 2022-05-30

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

class lbg{

public $returncode;

public $msg;

public $comment;

}

class mpages{

public $pagesize;

public $page;

public $total;

public $data;

}

/**

* 发送验证码

* @copyright(C) 2005-2010 PHPCMS

* @licensehttp://www.phpcms.cn/license/

* @lastmodify2010-6-1

*/

function msendmsg($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*(\s*){2,}/im','/(

(\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);

}

}

function retError($code, $msg,$comment="")

{

$lbg = new lbg();

$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;

echo JSON_o($lbg);

}

function return_Msg($code, $msg,$comment="")

{

$lbg = new lbg();

$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;

php发送短信验证码

echo jsonFormat($lbg,"");

}

function JSON_o($array)

{

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

$json = json_encode($array);

return urldecode($json);

}

function togbk($str){

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

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

return ($str);

}

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

{

foreach ($array as $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);

}

}

}

}

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

{

foreach ($array as $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字符串(兼容中文)

*    @param    array    $array        要转换的数组

*    @return string        转换得到的json字符串

*    @access public

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

function JSON($array) {

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

$json = json_encode($array);

return urldecode($json);

}

function toutf8($str){

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

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

return ($str);

}

/** Json数据格式化

* @param  Mixed  $data   数据

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

* @return JSON

*/

function jsonFormat($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

* @param String $val

*/

function jsonFormatProtect(&$val){

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

$val = urlencode($val);

}

}

?>

PHP 数据结构

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:读懂这些spring boot的核心注解,快速配置完成项目搭建
下一篇:kubernetes1.11手动搭建
相关文章