twilio sms with python

时间:2017-07-10 10:13:09

标签: sms twilio

我希望将其转换为php,任何人都可以。我正在进行营销应用程序编码以发送批量短信

from flask import Flask, request

from twilio.rest import TwilioRestClient

app = Flask(__name__)

# put your own credentials here 
ACCOUNT_SID = 'YOUR_ACCOUNT_SID' 
AUTH_TOKEN = 'YOUR_AUTH_TOKEN' 

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

@app.route('/sms', methods=['POST'])
def send_sms():
    message = client.messages.create(
        to=request.form['To'], 
        from_='YOUR_TWILIO_PHONE_NUMBER', 
        body=request.form['Body'],
    )

    return message.sid

if __name__ == '__main__':
        app.run()

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

how to send an SMS using Twilio and PHP right here上有一整页文档。

简而言之,要复制Python,您应该download or install the PHP helper library到您的项目。那么这段代码应该可以工作:

<?php
    require_once "vendor/autoload.php";
    use Twilio\Rest\Client;

    $AccountSid = "YOUR_ACCOUNTS_SID";
    $AuthToken = "YOUR_AUTH_TOKEN";

    $client = new Client($AccountSid, $AuthToken);

    $sms = $client->messages->create(
        $_REQUEST['To'],
        array(
            'from' => "YOUR_TWILIO_NUMBER", 
            'body' => $_REQUEST['Body']
        )
    );
    echo "Sent message";

我建议您完整了解follow the documentation