首页 文章

如何在php中运行批量短信api [关闭]

提问于
浏览
-1

我希望使用HTML表单接受用户的手机号码并发送短信 . 我有以下工作api链接:

http://bulksms.megawebsource.com/sendsms.jsp?user=XXX&password=XXX&mobiles=919762681119&sms=TESTSMS&senderid=NOTICE

任何人都可以建议我如何在PHP中使用上述链接向用户发送短信?

5 回答

  • 0

    我遇到了同样的问题 . 可能错误在于您的API或消息结构 . 使用此改进的API:

    <?php
    $username = 'XXXXXXXXXXX'; //bulksms username
    $password = 'XXXXXXXXXXX'; //bulksms password
    $mobile = '919762681119'; //Receiver's country code+number
    $sms = "The message you want to send " ; //Double quotes are good for new line characters e.g. \n
    $sms = urlencode($sms); //Very Important Otherwise spaces shall not be parsed correctly
    $url = "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=$username&password=$password&message=$sms&msisdn=$mobile";
    $xml = file_get_contents($url);
    echo $xml;
    ?>
    

    它应该有所帮助 .

  • 0

    在简单的PHP函数(使用CURL)中调用短信RestApi来发送短信:

    function CURLsendsms($number, $message_body){
    
         $textmessage = urlencode($message_body);
         $api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$number.'&message='.$textmessage;
         $smsGatewayUrl = "http://springedge.com";
         $smsgatewaydata = $smsGatewayUrl.$api_params;
    
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_POST, false);
         curl_setopt($ch, CURLOPT_URL, smsgatewaydata);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $output = curl_exec($ch);
         curl_close($ch);
    
         // Use file get contents when CURL is not installed on server.
         if(!$output){
         $output =  file_get_contents($smsgatewaydata);  
         }
    
    }
    

    你也可以使用php类发送短信http://www.phpclasses.org/package/9522-PHP-Send-SMS-messages-with-Spring-Edge-API.html

    上面有两个文件:

    • sendsms.php - 用于调用sms网关restAPI的类文件

    • test.php - 测试短信功能的示例文件 .

    此类使用spring edge sms网关提供程序API,您可以根据需要为任何其他sms提供程序自定义RestAPI url和params .

  • 0

    您需要注册并可能需要付费 . PHP代码非常简单: -

    <?php // sms
    $user = "YOUR-USERNAME";
    $pass = "YOUR-PASSWORD";
    $mob  = "919762681119,919762681118"; // Can come from a database
    $msg  = "Hello";
    $url  = "http://bulksms.megawebsource.com/sendsms.jsp?user=$user&password=$pass&mobiles=$mob&sms=$msg&senderid=NOTICE";
    $xml  = file_get_contents($url);
    // Process XML if you need to
    ?>
    

    通常可以用逗号分隔多个数字 .

  • 0

    我使用此代码发送短信 . 但是,请确保号码应为12位数,包括分机号码 . 例如:918080808080 . 接受用户的10位数字 . 在其上附加分机号码(91) . 还有一件事,有时会发生什么,消息不会转到那个数字 . 原因是他们的手机上的DNA(不允许)服务激活 . 如果在他们的SIM上激活DNA . 然后,这条短信不会GO .

    $OrderMessage=urlencode("Dear Customer, Order $OrderId of Rs. $TotalPayableAmount is accepted by aubree. Thank You");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, 
        "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=Sachin&password=180098734&sendername=Cricket&mobileno=$MobileNo&message=$OrderMessage"
    );
    $content = curl_exec($ch);
    
  • 1

    为什么遭受丑陋和有限的网址?您可以使用现代且方便的our JSON REST API . 由于您已经通过curl library使用了http请求,因此使用我们为批量短信请求提供的两个选项之一是没有问题的(例如,参见this answer):

    完整表格

    当您描述要发送的每条消息时,所有遗漏的内容都将从模板中获取:

    POST /sms/v1/{subAccountId}/many

    {
      "clientBatchId": "Demo#1001",
      "messages": [
        {
          "destination": "6598760001"
        },
        {
          "destination": "659876002",
          "source": "SenderId2",
          "clientMessageId": "id_100001"
        },
        {
          "destination": "509750003",
          "country": "FR",
          "source": "SenderId3",
          "text": "Custom message: สวัสดี",
          "encoding": "UCS2",
          "clientMessageId": "id_100002"
        }
      ],
      "template": {
        "source": "DefaultSenderId",
        "text": "Default message for all phone numbers"
      }
    }
    

    紧凑形式

    当您只列举电话号码时,其他所有内容都来自模板:

    POST /sms/v1/{subAccountId}/many/compact

    {
      "destinations": [
        "6598760000",
        "+659870001",
        "tel+659870002",
        "+33(509)758-000"
      ],
      "template": {
        "source": "BRAND",
        "text": "Your message for all clients"
      }
    }
    

    查看此tutorial以更顺利地深入了解API .

相关问题