--
參考資源
--
實作/注意事項
- include 的檔案記得從 .inc 改為 .php
- port 是 8000,企業網路有管制時需要注意
- 簡訊內容不允許 10 個連續數字,如果是手機號碼需要另外處理
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 |
<?php include "sms2.php"; /* Socket to Air Server IP ,Port */ $server_ip = '202.39.54.130'; $server_port = 8000; $TimeOut=10; $user_acc = "帳號"; $user_pwd = "密碼"; $mobile_number = "門號"; $message = "簡訊內容,中英混合最長可達670個字"; $message_encodeFrom = "utf-8"; //請確認簡訊內容編碼 "utf-8" or "big5" or "ucs-2" or other encodings /*建立連線*/ $mysms = new sms2(); $ret_code = $mysms->create_conn($server_ip, $server_port, $TimeOut, $user_acc, $user_pwd); $ret_msg = $mysms->get_ret_msg(); if($ret_code==0){ echo "連線成功"."<br>\n"; /*如欲傳送多筆簡訊,連線成功後使用迴圈執行$mysms->send_long()即可*/ //send_long(門號, 型態:[1=立即, 2=立即+重送逾時, 3=預約, 4=預約+重送逾時], 預約時間, 重送逾時, 簡訊內容) $ret_code = $mysms->send_long($mobile_number, 1 , "" , 0 ,$message, $message_encodeFrom); $ret_msg = $mysms->get_ret_msg(); if($ret_code==0){ echo "簡訊傳送成功"."<br>"; echo "ret_code=".$ret_code."<br>\n"; echo "ret_msg=".$ret_msg."<br>\n"; }else{ echo "簡訊傳送失敗"."<br>\n"; echo "ret_code=".$ret_code."<br>\n"; echo "ret_msg=".$ret_msg."<br>\n"; } } else { echo "連線失敗"."<br>\n"; echo "ret_code=".$ret_code."<br>\n"; echo "ret_msg=".$ret_msg."<br>\n"; } /*關閉連線*/ $mysms->close_conn(); |
--
將連續數字中間加一個減號
1 |
$content = preg_replace('/(\d{4})(\d{6})/', '$1-$2', $content); |
--
4,457 total views, 1 views today