php发送短信验证码
来源:互联网 发布:硬盘格式化恢复软件 编辑:程序博客网 时间:2024/05/09 11:54
<?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);
}
}
?>
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 0
- php发送短信验证码
- php发送短信验证码
- PHP发送短信验证码
- php阿里大于短信验证码发送
- PHP实现短信宝发送短信验证码功能
- PHP实现短信宝发送短信验证码功能
- 发送短信验证码
- 发送短信验证码
- 发送短信验证码
- 短信验证码发送
- 发送短信验证码
- 发送短信验证码
- php发送短信验证码完成注册功能
- php使用阿里大于短信平台发送验证码记录
- 秒嘀发送验证码短信类php
- php版阿里大于短信发送验证码
- Android发送短信验证码
- 发送短信验证码计时
- W88 Online Casino Malaysia sports Daily Reload(Online Casino Malaysia, sports Daily Reload, w88, W88
- MFC读写配置文件
- 引用对象的使用和易产生bug的示例
- js最新手机号码、电话号码正则表达式
- Ctrl与Caps Lock键(大写键)的交换swap
- php发送短信验证码
- 27. Remove Element
- Echarts导出为pdf格式
- c语言简单实现telnet客户端
- codis安装手册
- css元素水平居中
- C++ main函数的返回值
- 由es6 let想到的块级作用域问题-面试题
- oracle update 操作方法介绍与对比