Send MSN message from command-line interface

    系統環境

    作業系統:CentOS 5.2
    PHP 版本:PHP 5.1.6 (cli)
    Apache 版本:Apache/2.2.3

    系統需求

    PHP 模組:curl, pcre, mhash, mcrypt, bcmath
    至少兩組 MSN 帳號作傳訊測試

    // 檢查 PHP 現有模組
    #> php -m | grep -E "curl|pcre|mhash|mcrypt|bcmath"

    // 安裝 PHP 模組
    #> yum install php-curl php-pcre php-mhash php-mcrypt php-bcmath

    下載及設定主程式

    // 因為官方提供的是 7z 壓縮檔,這在 Linux 的預設環境是不能解壓的,所以先從另一部有裝 7z 解壓縮軟體的 Windows電腦下載後解壓,再使用 WinSCP工具將解壓後的所有檔案,上傳到 Linux 主機內。你也可以直接在 Linux  安裝 7z 解壓工具,請自行用 Google 搜尋教學。
    *官方下載

    // 新增一個發送訊息的 php 檔
    #> vi mymsnsend.php

    #!/usr/bin/php -Cq
    <?php
    // General settings
    $from_msnid = "msnid@from";
    $from_msnpass = "password";
    
    if (!isset($argc)) $argc = $_SERVER['argc'];
    if (!isset($argv)) $argv = $_SERVER['argv'];
    
    if ($argc != 3) {
        echo "Syntax: $argv[0] <MSN ID> <message>\n";
        exit;
    }
    
    array_shift($argv);
    $to_msnid = $argv[0];
    $messages = $argv[1];
    
    error_reporting(E_ALL);
    include_once('msn.class.php');
    
    // force to use MSNP9, without debug information
    // $msn = new MSN('MSNP9');
    
    // force to use MSNP9, with debug information
    // $msn = new MSN('MSNP9', true);
    
    // force to use MSNP15, without debug information
    // $msn = new MSN('MSNP15');
    
    // force to use MSNP15, with debug information
    // $msn = new MSN('MSNP15', true);
    
    // auto detect MSN protocol, without debug information
    // $msn = new MSN;
    
    // auto detect MSN protocol, with debug information
    //$msn = new MSN('MSNP15', true);
    $msn = new MSN('MSNP15');
    
    if (!$msn->connect($from_msnid, $from_msnpass)) {
        echo "Error for connect to MSN network\n";
        echo "$msn->error\n";
        exit;
    }
    
    //echo "MSNID = $msnid";
    $msn->sendMessage($messages,
                      array(
                        $to_msnid
                           )
                     );
    echo "Done!\n";
    exit;
    
    ?>
     

    ; MSN('MSNP15', true) 如果正式使用時,可不加上 true,就不會再顯示除錯訊息。
    ; from_msnid 填入用來發送訊息的 MSN 帳號
    ; from_msnpass 填入發送訊息的 MSN 密碼

    // 發送訊息測試
    #>php mymsnsend.php "to_msn_id" "This is test message"

    * 支援離線訊息發送,但 ID 需先經過對方認證。
    * 以上只是簡單的應用範例,原始檔案有包含更完整的應用方式。

    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core