簡體   English   中英

如何使用 twilio 從我的站點中的用戶獲取消息內容

[英]How to get content of message from users in my site using twilio

大家好嗎? 我的網站基於 PHP。 我是 twilio 的新手,並以此構建簡單的項目。 所以我應該實現的是使用 twilio 向用戶發送消息,然后在我的站點中再次接收來自用戶的消息。

<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once './vendor/autoload.php';

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = 'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$twilio = new Client($sid, $token);

$message = $twilio->messages
                  ->create("+12099216581", // to
                           [
                               "body" => "This is test",
                               "from" => "+15324394442",
                               "statusCallback" => ""
                           ]
                  );

print($message->sid);

這是用於向我現在正在使用的一個用戶發送消息.. 然后...

<?php
require_once './vendor/autoload.php';
use Twilio\TwiML\MessagingResponse;

$response = new MessagingResponse();
$response->message('This is message 1 of 2.');
$response->message('This is message 2 of 2.');

echo $response;

我認為這段代碼會用文字向用戶返回短信...如果我錯了,請教我...

所以我現在正在嘗試這樣做,但我不知道如何在我的網站中接收消息內容。 如果你有這方面的經驗,請教我。 提前致謝。

您需要為該消息響應設置 webhook

smsUrl = '網址';

$response = $client->request("POST", "IncomingPhoneNumbers/$phone_id.json", ['auth' => [$sid, $token], 'form_params' => array("SmsUrl" => $webhook_url , "BundleSid" => $bundle_id)]);

此 url 將發布傳入消息並回復消息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM