php发送短信验证码

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI视觉网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值