ASP send SMS function How to change to PHP, have ASP example, ask for advice

Source: Internet
Author: User
ASP send SMS function How to change to PHP, have ASP example, ask for advice
If vercode > "Then
email = "User account for Interface SMS"
Sms_password = "User password for Interface SMS"
Descurl = "http://www.xxxx.com.cn/api/send.asp" //interface address
Set objhttp = Server.CreateObject ("MSXML2. XMLHTTP ")
Call Objhttp.open ("POST", Descurl, FALSE)
PostData = "email=" +email+ "&password=" +sms_password+ "&msgcontent=" + ((msgcontent)) + "&mobileNumber=" + M + "&sendtime=" +sendtime+ "&subnumber=" + subnumber //Some of the above variables splicing, with user name, password, send mobile phone number, etc.
Response.Write PostData
Call Objhttp.setrequestheader ("Content-type", "text/html; charset=uft-8")
Call Objhttp.open ("GET", Descurl & "?" & PostData, False)
Call Objhttp.send ()
End If



This is the ASP's wording, a bit awkward. How do you write it in PHP? Thank you, first!
------to solve the idea----------------------
In the Curl class.
------to solve the idea----------------------
File_get_contents ($url);
------to solve the idea----------------------
 Class Mycurl {
protected $_useragent = ' mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 ';
protected $_url;
protected $_followlocation;
protected $_timeout;
protected $_maxredirects;
protected $_cookiefilelocation = './cookie.txt ';
protected $_post;
protected $_postfields;
protected $_referer = "http://www.xxxx.com.cn/api/send.asp";

protected $_session;
protected $_webpage;
protected $_includeheader;
protected $_nobody;
protected $_status;
protected $_binarytransfer;
Public $authentication = 0;
Public $auth _name = ";
Public $auth _pass = ";

Public Function Useauth ($use) {
$this->authentication = 0;
if ($use = = true) $this->authentication = 1;
}

Public Function SetName ($name) {
$this->auth_name = $name;
}
Public Function SetPass ($pass) {
$this->auth_pass = $pass;
}

Public function __construct ($url, $followlocation = True, $timeOut = $, $maxRedirecs = 4, $binaryTransfer = false,$ Includeheader = False, $noBody = False)
{
$this->_url = $url;
$this->_followlocation = $followlocation;
$this->_timeout = $timeOut;
$this->_maxredirects = $maxRedirecs;
$this->_nobody = $noBody;
$this->_includeheader = $includeHeader;
$this->_binarytransfer = $binaryTransfer;

$this->_cookiefilelocation = dirname (__file__). ' /cookie.txt ';

}

Public Function Setreferer ($referer) {
$this->_referer = $referer;
}

Public Function setcookifilelocation ($path)
{
$this->_cookiefilelocation = $path;
}

Public Function Setpost ($postFields)
{
$this->_post = true;
$this->_postfields = $postFields;
}

Public Function setuseragent ($userAgent)
{
$this->_useragent = $userAgent;
}

Public Function Createcurl ($url = ' nul ')
{
if ($url! = ' nul ') {
$this->_url = $url;
}

$s = Curl_init ();

curl_setopt ($s, curlopt_url, $this->_url);
curl_setopt ($s, Curlopt_httpheader,array (' Expect: '));
curl_setopt ($s, curlopt_timeout, $this->_timeout);
curl_setopt ($s, curlopt_maxredirs, $this->_maxredirects);
curl_setopt ($s, curlopt_returntransfer,true);
curl_setopt ($s, curlopt_followlocation, $this->_followlocation);
curl_setopt ($s, Curlopt_cookiejar, $this->_cookiefilelocation);
curl_setopt ($s, curlopt_cookiefile, $this->_cookiefilelocation);

if ($this->authentication = = 1) {
curl_setopt ($s, curlopt_userpwd, $this->auth_name. ': ' $this->auth_pass);
}
if ($this->_post)
{
curl_setopt ($s, curlopt_post,true);
curl_setopt ($s, curlopt_postfields, $this->_postfields);

}

if ($this->_includeheader)
{
curl_setopt ($s, curlopt_header,true);
}

if ($this->_nobody)
{
curl_setopt ($s, curlopt_nobody,true);
}
/*
if ($this->_binary)
{
curl_setopt ($s, curlopt_binarytransfer,true);
}
*/
curl_setopt ($s, curlopt_useragent, $this->_useragent);
curl_setopt ($s, curlopt_referer, $this->_referer);

$this->_webpage = curl_exec ($s);
$this->_status = Curl_getinfo ($s, curlinfo_http_code);
Curl_close ($s);

}

Public Function Gethttpstatus ()
{
return $this->_status;
}

Public Function __tostring () {
return $this->_webpage;
}
}

$m =new mycurl ("http://www.xxxx.com.cn/api/send.asp");

Some of the above variables splicing, there is a user name, password, send mobile phone number
$m->setpost (Array ("email" = $email,
"Password" = $SMS _password,
"Msgcontent" = $MsgContent,
"Mobilenumber" = $mobileNumber,
"Sendtime" = $SendTime,
"Subnumber" = $SubNumber
));
$m->createcurl ();

?>

Do you think this is going to work?
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.