1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
<? /*-------------------------------- 功能: 中國簡訊網PHP HTTP介面 傳送簡訊 修改日期: 2009-04-08 說明: http://http.c123.com/tx/?uid=使用者帳號&pwd=MD5位32密碼&mobile=號碼&content=內容 狀態: 100 發送成功 101 驗證失敗 102 簡訊不足 103 操作失敗 104 非法字元 105 內容過多 106 號碼過多 107 頻率過快 108 號碼內容空 109 帳號凍結 110 禁止頻繁單條發送 111 系統暫訂發送 112 號碼不正確 120 系統升級 --------------------------------*/ $uid = '9999'; //使用者帳號 $pwd = '9999'; //密碼 $mobile = '13912341234,13312341234,13512341234,02122334444'; //號碼 $content = '中國簡訊網PHP HTTP介面'; //內容 //即時發送 $res = sendSMS($uid,$pwd,$mobile,$content); echo $res; //定時發送 /* $time = '2010-05-27 12:11'; $res = sendSMS($uid,$pwd,$mobile,$content,$time); echo $res; */ function sendSMS($uid,$pwd,$mobile,$content,$time='',$mid='') { $http = 'http://http.c123.com/tx/'; $data = array ( 'uid'=>$uid, //使用者帳號 'pwd'=>strtolower(md5($pwd)), //MD5位32密碼 'mobile'=>$mobile, //號碼 'content'=>$content, //內容 'time'=>$time, //定時發送 'mid'=>$mid //子擴充號 ); $re= postSMS($http,$data); //POST方式提交 if( trim($re) == '100' ) { return "發送成功!"; } else { return "發送失敗! 狀態:".$re; } } function postSMS($url,$data='') { $row = parse_url($url); $host = $row['host']; $port = $row['port'] ? $row['port']:80; $file = $row['path']; while (list($k,$v) = each($data)) { $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //轉URL標準碼 } $post = substr( $post , 0 , -1 ); $len = strlen($post); $fp = @fsockopen( $host ,$port, $errno, $errstr, 10); if (!$fp) { return "$errstr ($errno)n"; } else { $receive = ''; $out = "POST $file HTTP/1.1rn"; $out .= "Host: $hostrn"; $out .= "Content-type: application/x-www-form-urlencodedrn"; $out .= "Connection: Closern"; $out .= "Content-Length: $lenrnrn"; $out .= $post; fwrite($fp, $out); while (!feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("rnrn",$receive); unset($receive[0]); return implode("",$receive); } } ?> |