代码之家  ›  专栏  ›  技术社区  ›  Ranjit Singh Shekhawat

无法从smsgateway发送短信。更新后的我

  •  0
  • Ranjit Singh Shekhawat  · 技术社区  · 7 年前

    我从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"

    你能帮我查一下吗。谢谢

    4 回复  |  直到 7 年前
        1
  •  2
  •   31piy    7 年前

    我阅读了他们网站上的文档,似乎您可能忘记了将API密钥与请求一起发送。如果您有API密钥,则需要以 Authorization 标题。

    Authorization: <the api key here>
    

    使用Postman,您可以设置此标头并重试。

        2
  •  2
  •   Kamal Ali    7 年前

    从获取令牌 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;
            }
        }
    
        3
  •  0
  •   Ranjit Singh Shekhawat    7 年前

    由于网站上的文档是新的,并且没有向多个电话号码发送短信的示例,所以我想分享这个jQuery代码,它可以用于使用smsgateway发送短信。我

    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对象中的任何数字发送多条短信。这可能是由于 for

        4
  •  0
  •   Juan Manuel Alcorta Villarreal    6 年前

    我找到了smsGateway。php去年并能够以编程方式实现sms发送,但2018年5月10日,该应用停止工作,我注意到该应用能够连接到smsGateway服务器,但无法检索消息,原因是该程序无法将sms放在smsGateway服务器上,更深入地看,错误是设备id不正确,不正确,深入研究这个问题,我发现从v3到v4实现了一个新版本,需要额外的信息才能将我的php程序表单提交到smsGateway服务器,这是使用登录名和密码访问网页时可以找到的授权密钥。面临的挑战是如何集成到smsGateway中。php我仍然在寻找对新版本进行更改的程序,但我还没有找到它。

    2018年5月16日 SMS高速公路。我现在发布了关于如何集成一些软件以编程方式发送短信的方向,这是一个新的挑战,如果您有PHP 5.3版本,那么在集成新程序时可能会遇到一些问题。顺便说一下,比v3复杂得多。

    还有一条注释“请注意,我们仍在编写文档,不久将推出新的SDK!”这让我有点害怕。我仍在进行集成,但我正在将PHP版本升级到5.6,看看这是否足以消除错误消息。

    在将我的php升级到5.5之后,我能够创建smsgateway。我的工作,来自 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