您的位置:首页 > 编程语言 > PHP开发

php模拟post请求,实现手机短信验证

2016-11-02 20:06 351 查看
下面的函数是直接封装好的post请求,需要两个参数  相信我注释很清楚了

/**

     *响应信息(post)

     *@url 请求地址

     *@query 请求参数string类型

     */

    /* protected function sock_post($url,$query){

        $info=parse_url($url);

        $fp=fsockopen($info["host"],80,$errno,$errstr,3);

        $head="POST ".$info['path']." HTTP/1.0\r\n";

        $head.="Host: ".$info['host']."\r\n";

        $head.="Referer: http://".$info['host'].$info['path']."\r\n";
        $head.="Content-type: application/x-www-form-urlencoded\r\n";

        $head.="Content-Length: ".strlen(trim($query))."\r\n";

        $head.="\r\n";

        $head.=trim($query);

        $write=fputs($fp,$head);

        while(!feof($fp)){

            $line=fgets($fp);

            echo $line."<br>";

        }

    }*/

//调用实力 //$mobile是手机号  拿到了请求参数  传入手机号就能发送短信了

function read($mobile){

        $url           = "http://www.ztsms.cn/sendNSms.*****";

        $name         = '****';

        $tkey         = date('YmdHis');

        $pass         = md5(md5('***').$tkey);

        $mobile     = $mobile;

        $content     = "此次注册验证码$this->$captcha(验证码有效期30分钟)【*****】";

        $productid  = '****';

        $xh         = '';

        $parameter  = "username=$name&password=$pass&tkey=$tkey&mobile=$mobile&content=$content&productid=$productid&xh=";

        return $this->sock_post($url,$parameter);

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: