0

嗨,我正在尝试使用 php 中的批量短信 api 发送批量短信我是新手,所以我不太了解这个 bt 我通过谷歌找到了一些脚本,但是当我尝试发送短信时,它显示错误“不DATA RECIEVED" 谁能帮我这里是 m 脚本

<?php

    if (isset($_POST["submit"])) {


         require("includes/config.php");
         require("includes/dbconnect.php");
         require("includes/functions.php");

        $tourdb = DBSUFFIX . $_SESSION["cono"] . "_" . $_SESSION["tourname"];
        mysql_select_db($tourdb);

        $message = substr($_POST["sms"], 0, 160);

        $cond = "";
        if (!empty($_POST["district"])) {
            $district = trim($_POST["district"]);
            $cond .= "AND `district` = '$district'";
        }

        if (!empty($_POST["state"])) {
            $state = trim($_POST["state"]);
            $cond .= "AND `state` = '$state'";
        }

        if (!empty($_POST["for"])) {
            $for = trim($_POST["for"]);
            $cond .= "AND `visitingfor` = '$for'";
        }

        $ccond = "";
        if (!empty($_POST["Airline"])) {
            $air = trim($_POST["Airline"]);
            $ccond .= "AND `airline_code` = '$air'";
        }

        if (!empty($_POST["bjdate"])) {
            $date1 = trim($_POST["bjdate"]);
            $ccond .= "AND `dept_date` = '$date1'";
        }

        if (!empty($_POST["jbdate"])) {
            $date2 = trim($_POST["jbdate"]);
            $ccond .= "AND `dept_date` = '$date2'";
        }

        if (!empty($_POST["siscono"])) {
            $siscono = trim($_POST["siscono"]);
            $cond .= "AND `company` = '$siscono'";
        }

        if (!empty($_POST["batch"])) {
            $batch = $_POST["batch"];
            $ccond .= " AND `batchno` = '$batch' ";
        }

        $hajicond = "";
        if (!empty($_POST["fromhaji"]) && !empty($_POST["tohaji"])) {
            $fromhaji = $_POST["fromhaji"];
            $tohaji = $_POST["tohaji"];
            $hajicond = " AND `hajino` BETWEEN '$fromhaji' AND '$tohaji'";
        }

        $paxcond = "";
        if (!empty($_POST["frompax"]) && !empty($_POST["topax"])) {
            $frompax = $_POST["frompax"];
            $topax = $_POST["topax"];
            $paxcond = " AND `paxid` BETWEEN '$frompax' AND '$topax'";
        }

        $msg = $_POST["sms"];



        $ctr = 0;
        $query = mysql_query("SELECT RIGHT(`mobile`,10) as `mobile`  FROM `pax` WHERE LENGTH(`mobile`) >= 10 AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE paxno IS NOT NULL $ccond) $cond $hajicond $paxcond ") or die(mysql_error());
            while ($pax = mysql_fetch_array($query)){
                $ctr++;
                $to.= "$pax[mobile],";
             }  

    $to.= "8652372200";

    $user = "****";
    $password = "t*****"; 
    $mobilenumbers = "$to";
    $message = "$msg";
    $senderid = "****";
    $url = "http://tran.mobilogi.com/api/httpapi.php";
    $message = urlencode($message);
    $ch = curl_init();
    echo "$user";
    if (!$ch) {
        die("Couldn't initialize a cURL handle");
    }
    $ret = curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$user&password=$password&to=$mobilenumbers&sender=$senderid&message=$message");

    $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);



    $curlresponse = curl_exec($ch);
    if (curl_errno($ch))
        echo 'curl error : ' . curl_error($ch);

    if (empty($ret)) {

        die(curl_error($ch));
        curl_close($ch); 
    } else {
        $info = curl_getinfo($ch);
        curl_close($ch);

        echo $curlresponse;
        }



    }
    ?>
4

2 回答 2

1

PHP或javascript中没有可以直接发送短信的功能。SMS 基本上基于短消息点对点 (SMPP) 协议,因此您无法直接以编程方式发送短信。是的,您可以使用 smsgateway 或现有的 api,您可以在其中从 php 发出 http 请求。有很多短信服务提供商,比如增值服务提供商,还有很多免费和开源的短信网关,比如 kannel,您可以使用它们来发送/接收短信,或者您也可以配置自己的网关

您需要一个第三方来发送您的消息,并且您还必须支付一些费用才能发送它们。我自己没有尝试过,但是这个关于通过 HTTP 发送 SMS 的教程似乎是一个不错的方法。它将使您能够

Use PHP and the HTTP protocol to send text-messages from your website through an SMS gateway.
于 2013-03-02T07:20:05.123 回答
0

您可以使用我们的 API。由于您已经通过curl 库使用 http 请求,因此使用我们为批量短信请求提供的两个选项之一是没有问题的(例如,请参阅此答案):

完整形式

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

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"
  }
}

查看本教程以更顺畅地深入了解 API。

于 2017-09-17T19:33:18.160 回答