善良,这是我的第一个问题,我的英语不是很好。
我可以毫无问题地处理来自 Nexmo API 的标准消息,并且我想像处理标准消息一样接收长 SMS(即在一个块中)。
从 Nexmo 接收的标准 SMS 数据示例:
$_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服务器上时,$_SESSION 数组似乎在短信的每个部分都被重置了......
那么,您知道如何正确处理它吗?(并且没有丑陋的临时 SQL 表)。在我完全收到之前,如何检索消息的前一部分?