sae php 短信,中国电信翼聊短信PHP发送类实现详细代码
中國電信翼聊短信可以向三網(wǎng)用戶發(fā)送短信,每天對每一個(gè)號碼可以最多發(fā)送5條短信,當(dāng)發(fā)送5條短信的時(shí)候會(huì)出現(xiàn)驗(yàn)證碼,但是只要輸入一次驗(yàn)證碼之后就可以繼續(xù)使用,不再需要輸入驗(yàn)證碼,所以還是有一定實(shí)用價(jià)值的。下面是PHP 翼聊短信發(fā)送類源代碼。暫不支持放置在多出口的主機(jī)上,因?yàn)橐砹亩绦攀菃吸c(diǎn)登錄的,限制只有一個(gè)用戶和一個(gè)IP在線,所以SAE環(huán)境無法非常正常的使用,會(huì)有間歇性故障,原因是出口IP問題。
下面就是代碼了
/*
*翼聊短信發(fā)送類,由于翼聊短信限制,非電信用戶每天對每個(gè)號碼不能發(fā)送5條以上的短信,發(fā)送多條時(shí)會(huì)出現(xiàn)驗(yàn)證碼,所以會(huì)發(fā)送失敗;
*其實(shí)只要輸入驗(yàn)證碼就好了,反正翼聊短信也就驗(yàn)證一次驗(yàn)證碼~
*Author:CplusHua
*/
Class smsPush{
public $PhoneNum;
public $vcode;
public $cookie;
function __construct($PhoneNum=null){
if(null==$PhoneNum) echo '您沒有設(shè)置發(fā)送者手機(jī)號碼,這樣是發(fā)不出短信滴~';
$this->PhoneNum=$PhoneNum;
}
function __get($var){
return $this->$var;
}
function getVcode($PhoneNum=null){
if($PhoneNum==null&& $this->PhoneNum!=null) $PhoneNum=$this->PhoneNum;
else if($PhoneNum==null) return false;
$url='http://115.239.133.251:6090/imweb/phoneCheckCode.s?
0.9838632841128856&sendPhone='.$PhoneNum.'&methodType=getPhoneCode';
$option=array(
CURLOPT_URL=>$url,
CURLOPT_POST=>false,
CURLOPT_RETURNTRANSFER=>true,
//CURLOPT_HEADER=>true,
);
$result=$this->exec($option);
$this->saveCookie($this->cookie);
if(100==$result) return true;
else return false;
}
function SubmitVcode($PhoneNum=null,$vcode=null){
if(null==$vcode) $vcode=$this->vcode;
if(null==$PhoneNum) $PhoneNum=$this->PhoneNum;
$this->cookie='JSESSIONID=
C72FD92F73AB532C0676565D2D8B7971;loginType=1; firsstYZ=yes';
$option=array(
CURLOPT_URL=>'http://115.239.133.251:6090/imweb/codeLogin.s?clientId=46&
account='.$PhoneNum.'&checkCode='.$vcode.'&rid=0.19796998496167362',
CURLOPT_COOKIE=>$this->cookie,
CURLOPT_HEADER=>true,
CURLOPT_RETURNTRANSFER=>true,
);
$result=$this->exec($option);
preg_match_all('/\nSet-Cookie:\s(.*)\s\n[\w|\W]*({"code":"100",
"loginSessionInfo":{.*})/i', $result, $matches);
//print_r($matches);//echo $matches[0][1];
$res=json_decode($matches[2][0]);
// print_r($res);
if(100!=$res->code) return false;
$this->cookie=$matches[1][0];
$this->saveCookie($this->cookie);
return true;
}
function exec($option=array()){
if(empty($option)) return false;
$c=curl_init();
curl_setopt_array($c, $option);
$res=curl_exec($c);
curl_close($c);
return $res;
}
function sendSMS($receivePhone=null,$msg=null,$checkCode=null){
if(null==$receivePhone||null==$msg) return false;
$data='&checkCode='.$checkCode.'&receivePhone='.$receivePhone.'&
smsContent='.$msg.'&random=0.7006821087561548';
$this->readCookie();
$this->cookie.=';loginType=1; firsstYZ=yes';
//echo $this->cookie;
$option = array(
CURLOPT_URL =>'http://115.239.133.251:6090/imweb/smsPush.s?clientId=46' ,
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_COOKIE=>$this->cookie,
CURLOPT_RETURNTRANSFER=>true,
);
$result=$this->exec($option);echo $result;
if(101==$result){
echo "這個(gè)IP還未登錄,如果您是用在了分布式服務(wù)器,那么肯定是因?yàn)槌隹诘腎P不一樣了~";
return $result;
}
if(104==$result){
echo "發(fā)送次數(shù)超限!";
return $result;
}
if(201==$result) {
echo '請輸入驗(yàn)證碼!就這樣悲劇了~';//其實(shí)就輸入一次,抓取回來輸入進(jìn)去不就完事了嘛~ 人家翼聊短信是記錄IP的,不要用多IP的服務(wù)器,否則悲劇了~
return $result;
}
if(100==$result) return true;
else return $result;
}
function sae_saveCookie($string){
$mmc=memcache_init();
if($mmc==false){
echo "mc init failed\n"; return 0;
}
else
{
return memcache_set($mmc,$this->PhoneNum,$string);
}
}
function sae_readCookie(){
$mmc=memcache_init();
if($mmc==false){
echo "mc init failed\n"; return 0;
}
else
{
return memcache_get($mmc,$this->PhoneNum);
}
}
//雖然兼容了SAE環(huán)境的寫cookie問題,但是SAE是多線出口,所以沒有辦法保證每次的出口IP都一樣。使用該cookie,出口IP不同的時(shí)候是無法使用的
function saveCookie($string){
if(!empty($_SERVER['HTTP_APPNAME'])&&!empty
($_SERVER['HTTP_APPVERSION'])) return $this->sae_saveCookie($string);
$f=fopen($this->PhoneNum.'.txt', 'w');
return fwrite($f, $string);
}
function readCookie(){
if(isset($_SERVER['HTTP_APPNAME'])&&isset
($_SERVER['HTTP_APPVERSION']))
{ $this->cookie= $this->sae_readCookie(); return 1;}
if(filesize($this->PhoneNum.'.txt')){
$f=fopen($this->PhoneNum.'.txt', 'r');
$cookie=fread($f, filesize($this->PhoneNum.'.txt'));
if(!empty($cookie)) return $this->cookie=$cookie;
}
}
function setImgcode(){
}
function getImg($imgurl="
http://115.239.133.251:6090/imweb/imageServlet.s",
$reffer="http://liao.189.cn/"){
$this->readCookie();
$this->cookie.=';loginType=1; firsstYZ=yes';
//echo $this->cookie;
$option = array(
CURLOPT_URL =>$imgurl ,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HEADER=>0,
CURLOPT_USERAGENT=>'Mozilla/4.0 (compatible; MSIE 7.0;
Windows NT 5.1; QQDownload 1.7; TencentTraveler 4.0',
CURLOPT_REFERER=>'http://liao.189.cn/',
CURLOPT_COOKIE=>$this->cookie,
CURLOPT_COOKIESESSION=>true,
);
$result=$this->exec($option);
header('Content-Type: image/jpeg');
echo $result;
return $result;
}
}
總結(jié)
以上是生活随笔為你收集整理的sae php 短信,中国电信翼聊短信PHP发送类实现详细代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 荀巨伯远看友人疾
- 下一篇: ZigBee TI ZStack CC2