我使用来自localhost的php以编程方式发送短信。但是今天在将smsgateway.me更新到v4之后,我无法发送任何消息。我实际上不知道如何将API密钥传递给给定的示例。我尝试了很多但没有成功。
Request Endpoint
Endpoint: https://smsgateway.me/api/v4/message/send
Method: POST
Request Parameters
Name Location Required Description
Content body true JSON payload with the information of SMS messages the API should send
请求示例
[
{
"phone_number": "07791064781",
"message": "Hello World",
"device_id": 1
},
{
"phone_number": "07791064782",
"message": "Hello World",
"device_id": 2
}
]
我也检查邮递员,但它正在返回"500 Internal Server Error"
可以请检查并帮助我。谢谢。
我在他们的网站上阅读了文档,看起来您可能忘记发送带有请求的API密钥。如果您有API密钥,则需要在Authorization
标头中发送它。
Authorization: <the api key here>
使用Postman,您可以设置此标头并重试。
从https://smsgateway.me获取令牌。登录您的帐户并单击设置,然后您将看到令牌。
public function sendMsgWithSmsGatewayApi($msg,$number,$deviceid)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://smsgateway.me/api/v4/message/send",
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "[{\"phone_number\": \"$number\", \"message\": \"$msg\", \"device_id\": $deviceid}]",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Postman-Token: 0dfb5acc-f0ae-415b-a5d3-ca12a2dfdfd3",
"authorization: Your-Token-here"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
由于网站上的文档是新的,并且没有将短信发送到多个电话号码的示例,我想分享这个可用于使用smsgateway.me发送短信的jQuery代码。
var p = {
"phone1": "9999999999",
"phone2": "8888888888"
};
for (var key in p) {
if (p.hasOwnProperty(key)) {
var phone_number = p[key];
var message = "Test SMS";
var device_id = 1;
var obj = [{
"phone_number": phone_number,
"message": message,
"device_id": device_id
}];
var mydata = JSON.stringify(obj);
var settings = {
"async": true,
"crossDomain": true,
"url": "https://smsgateway.me/api/v4/message/send",
"method": "POST",
"headers": {
"Authorization": "YOUR_API_KEY",
"Content-Type": "application/json",
},
"processData": false,
data: mydata
}
$.ajax(settings).done(function(response) {
console.log(response);
});
}
}
这个jQuery代码工作正常,但有时它会向给定js对象中的任何数字发送多个sms。这可能是由于for
循环。
我去年发现了smsGateway.php,并且能够以编程方式实现短信发送,但是在2018年5月10日该应用程序停止工作,我注意到该应用程序能够连接到smsGateway服务器但无法检索消息和原因是因为程序无法将短信放在smsGateway服务器上并且更深层次看错误是设备ID不正确而且不是真的,深入研究问题我发现新版本是从v3实现的需要v4和其他信息才能将我的php程序提交到smsGateway服务器,这是您使用登录名和密码访问网页时可以找到的授权密钥。挑战是如何在smsGateway.php中集成我仍然在寻找新版本的程序,但我还没有找到它。
2018年5月16日smsgateway.me现在发布了关于如何集成某些软件以编程方式发送短信的方向,如果你有一个PHP 5.3版本,你可能会遇到一些问题来集成新程序的新挑战。顺便说一句比v3复杂得多。
还有一个说明'请注意我们仍在处理文档,并将很快推出新的SDK!'这让我有点害怕。我仍然在进行集成,但是,我正在将PHP版本升级到5.6,看看是否足以消除错误消息。
将我的php升级到5.5之后,我能够让smsgateway.me工作,从https://github.com/smsgatewayme/client-php下载下一组程序文件
require_once(__DIR__ . '/autoload.php');
use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;
$clients = new SMSGatewayMe\Client\ClientProvider(
"your key from website"
);
$sendMessageRequest = new SMSGatewayMe\Client\Model\SendMessageRequest
([
'phoneNumber' => $HAMiLote['HASMSTel'],
'message' => $AXMessage, 'deviceId' => 100701
]);
$sentMessages =
$clients->getMessageClient()->sendMessages([$sendMessageRequest]);
?><pre><?php print_r($sentMessages); ?></pre><?php