php发送短信验证码

举报
风吹稻花香 发表于 2021/06/04 23:22:13 2021/06/04
【摘要】 D:\phpStudy\WWW\phpcms\libs\functions\sms.func.php   <?php class lbg{     public $returncode;     public $msg;     pub...

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

 

<?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*(<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);
    }
}
 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;
    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);
    }
}
?>

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/55654698

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200