PHP通过ICQ网关发送手机短信的实现代码
以下是利用ICQ网关实现手机短信发送功能的PHP源代码。 复制代码 代码如下: //########################################################### // // 如有疑问或评论 // Roland (别名 -=: Vlieg :=-) // ICQ号码 #78354631 // 邮箱: vlieg@atoomnet.net // // 注意:此脚本无法在启用安全模式的免费主机上运行! // 注意:您必须在 http://web.icq.com/sms/login/ 注册您的ICQ号码,否则脚本无法工作 //###########################################################
//****************************************************************\//配置部分: $uin=""; //您的ICQ号码 $passw=""; //您的ICQ密码 $PRefix=""; //短信前缀 $phonenumber=""; //接收短信的电话号码 $message = "Hello!"; //短信内容
//****************************************************************\// EN: 计算内容长度 $contentlength= ( 37+ strlen($uin)+ strlen($passw) ); //****************************************************************\// 打开登录页面 // EN: open loginpage $htmlreply=""; $post ="POST http://web.icq.com/karma/dologin/1,,,00.html HTTP/1.0 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-Powerpoint, application/vnd.ms-Excel, application/msword, */* Referer: http://web.icq.com/sms/login/1,,,00.html Accept-Language: nl Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) Host: web.icq.com Content-Length: ".$contentlength." Proxy-Connection: Keep-Alive Pragma: no-cache Cookie: uin=".$uin."; sms_country=".$prefix."; KarmaService1=Yes; uin=".$uin."; sms_country=".$prefix."; KarmaService1=Yes uService=1&uLogin=".$uin."&uPassword=".$passw."&x=0&y=0"; $remote = fsockopen("web.icq.com", 80, &$errno, &$errstr, 30); global $remote; global $post; fputs($remote, $post); while (!feof($remote)) { $htmlreply.=fgets($remote,120); } //取消注释以输出: echo "".htmlspecialchars($htmlreply).""; fclose($remote); //****************************************************************\//从登录页获取个人Cookie // EN: fetch personal cookie from login page $splited = split("\n",$htmlreply); $cookies = $splited[3]; $cookies = str_replace("Set-Cookie: KarmaLogin=","",$cookies); $cookies = str_replace("; path=/","",$cookies); $cookies = str_replace("\n","",$cookies); //取消注释以输出: echo $cookies; if (strlen($prefix) == 2) { $contentprefix = ' '.$prefix; } else { $contentprefix = $prefix; } $charcount = (160-strlen($message)); $contentlength= ( 1561+ strlen($message)+ strlen($charcount)+ strlen($phonenumber)+ strlen($prefix) ); //****************************************************************\//使用获取到的Cookie打开发送页面 // EN: open send page with fetched cookie $htmlreply=""; $post ='POST http://web.icq.com/sms/send_history/1,,,00.html HTTP/1.0 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */* Referer: http://web.icq.com/sms/send_session/1,,,00.html?prefix=+'.$prefix.'&carrier=&tophone='.$phonenumber.' Accept-Language: nl Content-Type: multipart/form-data; boundary=---------------------------7d12442eab4 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) Host: web.icq.com Content-Length: '.$contentlength.' Proxy-Connection: Keep-Alive Pragma: no-cache Cookie: uin='.$uin.'; sms_country='.$prefix.'; KarmaService1=Yes; KarmaLogin='.$cookies.'; uin='.$uin.'; sms_country='.$prefix.'; KarmaService1=Yes; KarmaLogin='.$cookies.' -----------------------------7d12442eab4 Content-Disposition: form-data; name="carrier"
-----------------------------7d12442eab4 Content-Disposition: form-data; name="prefix" '.$contentprefix.' -----------------------------7d12442eab4 Content-Disposition: form-data; name="tophone" '.$phonenumber.' -----------------------------7d12442eab4 Content-Disposition: form-data; name="uSession" 1 -----------------------------7d12442eab4 Content-Disposition: form-data; name="uReply"
-----------------------------7d12442eab4 Content-Disposition: form-data; name="uLastId"
-----------------------------7d12442eab4 Content-Disposition: form-data; name="uSend" 1 -----------------------------7d12442eab4 Content-Disposition: form-data; name="uNextId"
-----------------------------7d12442eab4 Content-Disposition: form-data; name="uHistoryCounter" 1 -----------------------------7d12442eab4 Content-Disposition: form-data; name="count" 0 -----------------------------7d12442eab4 Content-Disposition: form-data; name="uSubmitCount" 0 -----------------------------7d12442eab4 Content-Disposition: form-data; name="checkNewMsg" 180000 -----------------------------7d12442eab4 Content-Disposition: form-data; name="charcount" '.$charcount.' -----------------------------7d12442eab4 Content-Disposition: form-data; name="msg" '.$message.' -----------------------------7d12442eab4 Content-Disposition: form-data; name="x" 30 -----------------------------7d12442eab4 Content-Disposition: form-data; name="y" 16 -----------------------------7d12442eab4-- '; $remote = fsockopen("web.icq.com", 80, &$errno, &$errstr, 30); global $remote; global $post; fputs($remote, $post); while (!feof($remote)) { $htmlreply.=fgets($remote,120); } //取消注释以输出: echo "".htmlspecialchars($htmlreply).""; fclose($remote); //****************************************************************\//检查消息是否发送成功,如果返回'moved permanently'则表示成功 if (eregi('Moved Permanently',$htmlreply)) { echo "Sms message successfully sent!"; } else { echo "Sms not sent!"; } ?>