📄 mycantos-sms.php
字号:
<?php
/*************************************************************************************************************************************
* @Author : Poomalairaj.R <poomalairaj.r@gmail.com>
* @Filename : class.mycantos.php
* @Date : 5:34 PM 10/20/2008
* @version : 1.0
* @Desc : This class sends messages from www.mycantos.com using php curl
* No need to edit this class. U can use this as it is.
* Copying : You can do whatever you want with this class. U have all rights to copy, modify, and distribute. This class is distributed under BSD License. Please Dont remove this copyright info from this file. Please dont use this class to send spam or otherwise SMS recursively. If u do so, My cantos will block ur account or they may use captcha to send messages. Then it would be difficult to send sms via PHP program... Use this class for your personal use and in a decent way...
* This class is made in india
*************************************************************************************************************************************/
class MyCantos {
private $user="";
private $pass="";
private $toMobile="";
private $msg="";
private $postUrlLogin="http://www.mycantos.com/index.php";
private $postUrlSendmsg="http://www.mycantos.com/sendSMStoanyone.php";
private $refererLogin="http://www.mycantos.com/index.php";
private $refererSendMsg="http://www.mycantos.com/sendSMS.php?a=a";
private $cookiefile="";
private $userAgent="";
/**
* Constructor: Creates cookie file and user agent string.
*
* @param string $cookiePath (Optional) path of the cookie file where login info is stored from mycantos
* @param string $userAgent (Optional) User agent string. defaults to mozilla.
*
*/
public function __construct($cookiePath="", $userAgent="") {
if(!empty($cookiePath))
$this->cookiefile = $cookiePath;
else
$this->cookiefile ="cookies.txt";
if (!file_exists($this->cookiefile)) {
$fp = fopen($this->cookiefile,"w+");
fwrite($fp,"");
fclose($fp);
}
switch ($userAgent) {
case 'mozilla':
$this->userAgent='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3';break;
case 'ie':
$this->userAgent='Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)';break;
case '':
$this->userAgent='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3';break;
default:
$this->userAgent=$userAgent;
}
}
/**
* login : Logs in to mycantos using provided username and password
*
* @param string $user (must) mycantos username
* @param string $pass (must) mycantos password
*
*/
public function login($user, $pass) {
$this->user=$user;
$this->pass=$pass;
$postFields = 'username='.$this->user.'&password='.$this->pass.'&checklogin=1';
$output = $this->postFields($postFields, $this->postUrlLogin, $this->refererLogin);
return $output;
}
/**
* sendSMS : This method sends SMS
*
* @param string $toMobile (must) The mobile number u want to send sms to.
* @param string $msg (must) Message to be sent through SMS
*
*/
public function sendSMS($toMobile, $msg) {
$this->toMobile=$toMobile;
$this->msg=urlencode(substr($msg,0,118)); # Message should not exceed more than 118 characters
$postFields="checkSMS=1&SMSnumber=".$this->toMobile."&SMSmessage=".$this->msg;
$output = $this->postFields($postFields, $this->postUrlSendmsg, $this->refererSendMsg);
return $output;
}
/**
* postFields : This method posts the $postFields to $url and uses $referer
* This method uses curl function to post the required fields to the url
*
* @param string $postFields (must) Fields to be posted to mycantos
* @param string $url (must) URL to send the foelds to,
* @param string $referer (must) set the referer url
*
*/
public function postFields($postFields, $url, $referer) {
$ch = curl_init(); # Initialize a CURL session.
curl_setopt($ch, CURLOPT_URL, $url); # The URL to fetch.
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); # Set the userAgent here
curl_setopt($ch, CURLOPT_POST, 1); # Do a regular HTTP POST. The data should be url encoded
curl_setopt($ch, CURLOPT_POSTFIELDS,$postFields); # Fields to be poted to the above set url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); # set this to return the transfer as a string
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); # set this to follow any Location: header
curl_setopt($ch, CURLOPT_REFERER, $referer); # Set the referer url here
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); # The name of the file containing the cookie data.
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile); # The name of a file to save all internal cookies to when the connection closes.
$output = curl_exec($ch); # store the contents of the fetched url
curl_close($ch); # close curl resource,
return $output; # Return the output
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -