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