asp发送短信功能如何改成php的,有asp例子,求教

php中文网
发布: 2016-06-13 12:12:03
原创
1194人浏览过

asp发送短信功能怎么改成php的,有asp例子,求教

If vercode > "" Then<br />email = "接口短信的用户账号"<br />SMS_PASSWORD = "接口短信的用户密码"<br />DescURL = "http://www.xxxx.com.cn/api/send.asp"  //接口地址<br />Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")<br />Call objHTTP.Open("POST", DescURL, FALSE)<br />PostData = "email="+email+"&Password="+SMS_PASSWORD+"&MsgContent="+((MsgContent))+"&mobileNumber="+ m +"&SendTime="+SendTime+"&SubNumber="+ SubNumber  //一些上边的变量拼接,有用户名,密码,发送手机号等<br />Response.Write postdata<br />Call objHTTP.SetRequestHeader("Content-Type","text/html; charset=uft-8")<br />Call objHTTP.open("GET",DescURL & "?" & PostData, false)<br />Call objHTTP.send()<br />end if
登录后复制



这是asp的写法,有点别扭。 要换成php怎么写啊?先谢谢了!
------解决思路----------------------
用curl类似的
------解决思路----------------------
file_get_contents($url);
------解决思路----------------------
<?php<br />class mycurl {<br />     protected $_useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1';<br />     protected $_url;<br />     protected $_followlocation;<br />     protected $_timeout;<br />     protected $_maxRedirects;<br />     protected $_cookieFileLocation = './cookie.txt';<br />     protected $_post;<br />     protected $_postFields;<br />     protected $_referer ="http://www.xxxx.com.cn/api/send.asp";<br /> <br />     protected $_session;<br />     protected $_webpage;<br />     protected $_includeHeader;<br />     protected $_noBody;<br />     protected $_status;<br />     protected $_binaryTransfer;<br />     public    $authentication = 0;<br />     public    $auth_name      = '';<br />     public    $auth_pass      = '';<br /> <br />     public function useAuth($use){<br />       $this->authentication = 0;<br />       if($use == true) $this->authentication = 1;<br />     }<br /> <br />     public function setName($name){<br />       $this->auth_name = $name;<br />     }<br />     public function setPass($pass){<br />       $this->auth_pass = $pass;<br />     }<br /> <br />     public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false)<br />     {<br />         $this->_url = $url;<br />         $this->_followlocation = $followlocation;<br />         $this->_timeout = $timeOut;<br />         $this->_maxRedirects = $maxRedirecs;<br />         $this->_noBody = $noBody;<br />         $this->_includeHeader = $includeHeader;<br />         $this->_binaryTransfer = $binaryTransfer;<br /> <br />         $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt';<br /> <br />     }<br /> <br />     public function setReferer($referer){<br />       $this->_referer = $referer;<br />     }<br /> <br />     public function setCookiFileLocation($path)<br />     {<br />         $this->_cookieFileLocation = $path;<br />     }<br /> <br />     public function setPost ($postFields)<br />     {<br />        $this->_post = true;<br />        $this->_postFields = $postFields;<br />     }<br /> <br />     public function setUserAgent($userAgent)<br />     {<br />         $this->_useragent = $userAgent;<br />     }<br /> <br />     public function createCurl($url = 'nul')<br />     {<br />        if($url != 'nul'){<br />          $this->_url = $url;<br />        }<br /> <br />         $s = curl_init();<br /> <br />         curl_setopt($s,CURLOPT_URL,$this->_url);<br />         curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:'));<br />         curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);<br />         curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects);<br />         curl_setopt($s,CURLOPT_RETURNTRANSFER,true);<br />         curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);<br />         curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation);<br />         curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);<br /> <br />         if($this->authentication == 1){<br />           curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);<br />         }<br />         if($this->_post)<br />         {<br />             curl_setopt($s,CURLOPT_POST,true);<br />             curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);<br /> <br />         }<br /> <br />         if($this->_includeHeader)<br />         {<br />               curl_setopt($s,CURLOPT_HEADER,true);<br />         }<br /> <br />         if($this->_noBody)<br />         {<br />             curl_setopt($s,CURLOPT_NOBODY,true);<br />         }<br />         /*<br />         if($this->_binary)<br />         {<br />             curl_setopt($s,CURLOPT_BINARYTRANSFER,true);<br />         }<br />         */<br />         curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent);<br />         curl_setopt($s,CURLOPT_REFERER,$this->_referer);<br /> <br />         $this->_webpage = curl_exec($s);<br />                   $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE);<br />         curl_close($s);<br /> <br />     }<br /> <br />   public function getHttpStatus()<br />   {<br />       return $this->_status;<br />   }<br /> <br />   public function __tostring(){<br />      return $this->_webpage;<br />   }<br />}<br /> <br />$m=new mycurl("http://www.xxxx.com.cn/api/send.asp");<br /> <br />//一些上边的变量拼接,有用户名,密码,发送手机号<br />$m->setPost(Array("email"=> $email, <br />"Password"=> $SMS_PASSWORD,<br />"MsgContent"=> $MsgContent,<br />"mobileNumber"=> $mobileNumber,<br />"SendTime"=> $SendTime,<br />"SubNumber"=> $SubNumber<br />    ));<br />$m->createCurl();<br /><br />?>
登录后复制

你看这样是否能用

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号