我正在创建需要从 php 代码中发送 php 创建的消息的快速网络应用程序。 cURL 显然是完成这项工作的工具,但我很难理解它以使其正常工作。
我正在处理的 API 的文档是 here .特别是我想使用记录在案的简单的基于 GET 的短信通知 here .后一个资源指出 GET API 很简单:
http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber={PHONENUMBER}&Message={MESSAGE}&LicenseKey={LICENSEKEY}
事实上,如果我在浏览器中输入以下 URL,我会得到预期的结果:
http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=15362364325&Message=mymessage&LicenseKey=2134234882347139482314987123487
我现在正尝试在 php 中创建相同的效果。这是我的尝试:
<html>
<body>
<?php
$num = '13634859126';
$message = 'some swanky test message';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=".urlencode($num)."&Message=".urlencode($message)."&LicenseKey=2345987342583745349872");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
</body>
</html>
我的其他 PHP 网页运行良好,因此我知道 php 和 apache 都已正确设置。但是当我将浏览器指向上面的页面时,我的手机上没有收到任何消息。谁能告诉我我做错了什么?
注意:所有数字都是伪造的...正如您所怀疑的那样。
最佳答案
您真的需要 CURL 吗?您只需使用 PHP 的 file_get_contents($url)
,它将执行 GET 请求并返回响应值。
关于php - 使用 PHP cURL 发送 SMS 文本消息的简单 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4188332/