使用 Twilio 获取短信发件人的电话号码 [英] Get phone number of SMS sender, using Twilio

查看:31
本文介绍了使用 Twilio 获取短信发件人的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索向我的 Twilio 号码发送短信的用户的电话号码,但我无法在我的程序中获取它.

I am trying to retrieve the phone number of a user who sends SMS to my Twilio number, but I can't fetch it in my program.

我已经尝试过这些:

$message = $client->account->sms_messages->get("$Smssid");
$number = $message->From;

但是无论我怎么尝试 $number 仍然是空白.我试图获得 $sidsid$SMSSid.没什么.

But no matter what I try $number is still blank. I have tried to get $sid, sid, $SMSSid. Nothing.

我做错了什么?

推荐答案

当用户向您发送 SMS 时,我们会向您的服务器发出 HTTP 请求.此 HTTP 请求包含有关 SMS 的信息,例如 From、To、Body 等.

When a user sends you an SMS, we make an HTTP request to your server. This HTTP request contains info about the SMS, such as the From, To, Body, etc.

要从 PHP 中的 HTTP 请求中检索From"值,只需执行以下操作:

To retrieve the 'From' value from the HTTP request in PHP, simply do the following:

$from_number = $_REQUEST['From'];

或者,您可以从 REST API 中检索它:

Alternately you can retrieve it from the REST API:

$message = $client->account->sms_messages->get($_REQUEST['SmsSid'])

虽然这应该是不必要的,因为您需要的所有数据都应该在 HTTP 请求中.

Although this should be unneccessary as all the data you need should be in the HTTP request.

这篇关于使用 Twilio 获取短信发件人的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆