Home  >  Article  >  Backend Development  >  asp发送短信功能如何改成php的,有asp例子,求教

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

WBOY
WBOYOriginal
2016-06-13 12:12:031020browse

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 />?>

你看这样是否能用

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn