0

有人建议我在我的脚本中使用它

        curl -X POST https://api.twilio.com/2010-04-01/Accounts/HIDDEN/SMS/Messages.json \
        -u HIDDEN\
        -d "From=+442033228389" \
        -d "To=hidden" \
        -d 'Body=test'

但是简单的剪切和粘贴就不行吗?我将如何将其合并到我的脚本中?

结果:

var_dump($输出); 返回:布尔(假)

var_dump($info); 返回:

数组(26){[“url”]=>字符串(95)“ https://api.twilio.com/2010-04-01/Accounts/AC7ae43150d51cce16de4be6ed0be5ca90/SMS/Messages.json" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int (-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.093) ["namelookup_time"]=> float(0) [" connect_time"]=> float(0.093) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float (0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) [ "redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(15) "174.129.254.101" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) [ "local_ip"]=> 字符串(11) "192.168.0.2" ["local_port"]=> int(28469) }

4

2 回答 2

1

如果您想从 PHP 脚本中执行 shell 命令,您必须使用其中一个函数exec,或简单的反引号运算符 `shell_execsystemproc_open

$output = `curl -X POST https://api.twilio.com/2010-04-01/Accounts/HIDDEN/SMS/Messages.json -u HIDDEN -d "From=+442033228389" -d "To=hidden" -d 'Body=test'`;

但是如果你想在 PHP 中使用 curl 功能,更好的方法是使用 curl 扩展。这里有一个例子:

<?php

// check if the curl extension is available
if(!function_exists('curl_init')) {
    die('the curl extension is not installed');
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/HIDDEN/SMS/Messages.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "From=+442033228389\nTo=hidden\nBody=test");

$result = curl_exec($ch);

// json_decode is used to translate the result into an object
var_dump(json_decode($result));
于 2013-02-25T02:22:33.980 回答
1
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.twilio.com/2010-04-01/Accounts/HIDDEN/SMS/Messages.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'From' => '+442033228389',
    'To' => 'hidden',
    'Body' => 'test'
);
/* // WHERE $username = your account username
   // Where $password = Your account password
*/
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
于 2013-02-25T02:25:16.943 回答