我正在研究一个使用clicksend SMS的HTTP API发送短信的项目。我正在尝试使用curl函数发布数据,但是遇到了困难。
这些是发布字段:
方法,用户名,密钥,收件人,消息,发件人
我希望使用带有HTML表单的curl函数来完成此操作。
<?php
if(isset($_POST['number'])) {
$pass = $_POST['password'];
$num = $_POST['number'];
$msg = $_POST['msg'];
$sender = $_POST['sender'];
// Passwords Start Here.....!!
if ($pass == "jony") {
echo "Correct Password....!!";
}
else {
echo "Wrong Password....!! ";
exit;
}
// Passwords End Here....!!
echo "Success " . $num . " ";
$LOGINURL = "https://api.clicksend.com/http/v2/send.php?method=http&username=username&key=KEY";
$POSTFIELDS = '&to=' . $num .'&message=' . $msg . '&senderid=' . $sender;
$agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_exec ($ch);
?>
我假设您已经清空了登录URL中的实际用户名和密钥,对吗?否则,您将需要使用ClickSend提供的功能。毫无疑问,您将能够在某处的帐户中设置API密钥,等等。
我也看到将CURLOPT_RETURNTRANSFER
其设置为1
,但是由于您目前正在调试,因此您应该将其设置为0
(这将在运行脚本后向您显示ClickSend的“响应”)
其余的看起来不错。将ClickSend响应呈现到页面后,它应该使您更好地了解问题的根源是什么。
尝试运行此脚本,告诉我们页面上的内容。
<?php
//You *MUST* define your username and key. It is availible in your ClickSend dashboard.
$_my_clicksend_username = "clicksendusername";
$_my_clicksend_key = "abc123";
//You *MUST* define the 'to', 'message' and 'senderid'
$to = "the recipient";
$message = "the message";
$senderid = "the sender ID";
//Tell CURL where to post, and what data to send.
$url = "https://api.clicksend.com/http/v2/send.php?method=http&username=$_my_clicksend_username&key=$_my_clicksend_key";
$data = '&to=' . $to .'&message=' . $message . '&senderid=' . $senderid;
//Now tell CURL to POST the data and write the outcome on the page.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec ($ch);
curl_close($ch);
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句