親切にしてください、これは私の最初の質問で、私の英語はあまり上手ではありません。
Nexmo API からの標準メッセージを処理するのに問題はありません。標準メッセージと同じように (つまり、1 つのブロックで) 長い SMS を受信したいと考えています。
標準 SMS で Nexmo から受信したデータの例:
$_GET['msisdn'] ==> "33612345678" // "from"
$_GET['to'] ==> "33687654321"
$_GET['messageId'] ==> "02000000478EBE09"
$_GET['text'] ==> "Hello world!"
$_GET['type'] ==> "unicode"
$_GET['keyword'] ==> "HELLO"
$_GET['message-timestamp'] ==> "2014-11-25 14:06:58"
長いもの: (Nexmo はそれを少しずつ送りました)
$_GET['msisdn'] ==> "33612345678" // "from"
$_GET['to'] ==> "33687654321"
$_GET['messageId'] ==> "02000000478EBE09"
$_GET['text'] ==> "the first part of a too long text..."
$_GET['type'] ==> "unicode"
$_GET['keyword'] ==> "THE"
$_GET['message-timestamp'] ==> "2014-11-25 12:06:58"
$_GET['concat'] ==> "true"
$_GET['concat-ref'] ==> "108" // unique identifier for long SMS text
$_GET['concat-total'] ==> "4" // or more, or less...
$_GET['concat-part'] ==> "1" // index of the part, start at 1
Nexmo のドキュメントについて詳しくは、こちらをご覧ください。
だから、私は github にあるライブラリ ( Nexmo-PHP-lib ) から始めて、これを行いました: (かなり醜いですが、テスト目的です)
public function inboundText( $data=null ){
if(!$data) $data = $_GET;
if(!isset($data['text'], $data['msisdn'], $data['to']))
return false;
if(isset($data['concat']) && $data['concat'])
{
session_start();
if ($data['concat-part'] > 1) // first part ?
{
if ($data['concat-total'] == $data['concat-part']) // last part ?
{
// last part ! stock the data in the text and unset now useless $_SESSION entry!
$data['text'] = $_SESSION[(string)$data['concat-ref']] . $data['text'];
unset($_SESSION[(string)$data['concat-ref']]);
}
else // not the first or the last, so concat !
{
// concat the new part in the entry named after the concat-ref
$_SESSION[(string)$data['concat-ref']] .= $data['text'];
return false;
}
}
else // first part ! so creat a $_SESSION entry for that! (named after concat-ref)
{
$_SESSION[(string)$data['concat-ref']] = $data['text'];
return false;
}
}
// Get the relevant data
$this->to = $data['to'];
$this->from = $data['msisdn'];
$this->text = $data['text'];
$this->network = (isset($data['network-code'])) ? $data['network-code'] : '';
$this->message_id = $data['messageId'];
// Flag that we have an inbound message
$this->inbound_message = true;
return true;
}
ローカル テストでは完全に動作しますが、heroku サーバーでホストされている場合は機能しません。SMS の各部分で $_SESSION 配列がリセットされているようです...
それで、それを適切に処理する方法について何か考えがありますか?(そして醜い一時SQLテーブルなしで)。メッセージを完全に受信するまで、メッセージの前の部分を取得するにはどうすればよいですか?