我尝试使用curl发送一个http网址,但它根本不起作用,这是我用过的代码:
<?php
$username = 'username';
$password = 'password';
$sender='sender';
$msisdn = '+96899999999';
$content="Test MSG";
$data = "username=".$username."&password=".$password."&message=".urlencode($content)."&sender=".$sender."&msisdn=".urlencode($msisdn);
$ch = curl_init('http://bulksms.vsms.net/eapi/submission/send_sms/2/2.0');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($response = curl_exec($ch))
{
echo "1";
}
else
{
echo "0";
}
curl_close ($ch);
?>
它总是返回0.可能是什么问题?
答案 0 :(得分:0)
查看 BulkSMS API documentation for PHP 。这提供了使用Curl发送SMS的综合代码。
经过快速检查后,我发现他们的端口(443)有一个curl_setopt,他们的POST数据略有不同。主要区别在于你的sender
字段为 $ch = curl_init( );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_PORT, $port ); //443
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
// Allowing cUrl funtions 20 second to execute
curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
// Waiting 20 seconds while trying to connect
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 20 );
$response_string = curl_exec( $ch );
$curl_info = curl_getinfo( $ch );
,而它们没有。{/ p>
function foo (foo1, foo2) {
...
}
我建议您先从他们的代码开始,然后修剪掉不需要的东西。