zoukankan      html  css  js  c++  java
  • PHP SDK短信接口

        /**
         * sdk 短信接口
         * @param $tel 手机号
         * @param $content  短信内容
         * @return bool
         */
        public function telSDK($tel,$content)
        {
            $flag = 0;
            $params = '';
            //要post的数据
            $argv = array(
                'sn'=>'XXX', ////替换成您自己的序列号
                'pwd'=>strtoupper(md5('XXX'.'XXX')), //此处密码需要加密 加密方式为 md5(sn+password) 32位大写
                'mobile'=>$tel,//手机号 多个用英文的逗号隔开 post理论没有长度限制.推荐群发一次小于等于10000个手机号
                'content'=>iconv( "UTF-8", "gb2312//IGNORE" ,$content),//短信内容
                'ext'=>'',
                'stime'=>'',//定时时间 格式为2011-6-29 11:09:21
                'rrid'=>''
            );
            //构造要post的字符串
            foreach ($argv as $key=>$value)
            {
                if ($flag!=0)
                {
                    $params .= "&";
                    $flag = 1;
                }
                $params.= $key."="; $params.= urlencode($value);
                $flag = 1;
            }
            $length = strlen($params);
            //创建socket连接
            $fp = fsockopen("sdk.entinfo.cn",8060,$errno,$errstr,10) or exit($errstr."--->".$errno);
            //构造post请求的头
            $header = "POST /webservice.asmx/mt HTTP/1.1
    ";
            $header .= "Host:sdk.entinfo.cn
    ";
            $header .= "Content-Type: application/x-www-form-urlencoded
    ";
            $header .= "Content-Length: ".$length."
    ";
            $header .= "Connection: Close
    
    ";
            //添加post的字符串
            $header .= $params."
    ";
            //发送post的数据
            fputs($fp,$header);
            $inheader = 1;
            while (!feof($fp))
            {
                $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据
                if ($inheader && ($line == "
    " || $line == "
    "))
                {
                    $inheader = 0;
                }
                if ($inheader == 0)
                {
                    // echo $line;
                }
            }
            //<string xmlns="http://tempuri.org/">-5</string>
            $line=str_replace("<string xmlns="http://tempuri.org/">","",$line);
            $line=str_replace("</string>","",$line);
            $result=explode("-",$line);
            // echo $line."-------------";
            if(count($result)>1)
                return false;
            else
                return true;
        }

    调用 :

            
             if($_GET['tel']){
                    $code = mt_rand(10000,99999);
                    if(session("code")){
                        session("code",null);
                    }
                    session("code",$code,3600);
                    $con = "您的短信验证码为:".$code.",打死都不要告诉别人哦!";
                    $this->telSDK($_GET['tel'],$con);
                }

  • 相关阅读:
    docker 方式安装gitlab时,项目的clone地址及项目文件列表地址为机器名的问题解决办法
    CPU流水线
    Element中el-form嵌套el-table双击编辑提交检验
    java基础知识
    C#多线程下载
    mysql优化
    C++ 算法(一)
    前端vue 的面试总结 以及答案以及前端技术点面试
    C# 组合任务
    C# List去重DistinctBy扩展
  • 原文地址:https://www.cnblogs.com/ningjiabing/p/10066096.html
Copyright © 2011-2022 走看看