簡體   English   中英

使用Curl通過PHP發送短信

[英]Sending SMS via PHP using Curl

我在下面有這張表格,假設是要向后端發送POST請求,然后在提交時再發送一條SMS:

<form id="sms" method="post">
      <input type="number" name="mobile" id="mobile" class="text"/>
      <button type="button" name="sub" value="Submit">Send</button>
</form>

我是從后端人員那里得到的,沒有其他詳細信息。 我找到了一些在線教程,但是我什么也做不了。

curl -X POST \
  https://example.com/gateway/sms \
  -H 'Accept: application/json' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H 's: APP' \
  -d '{ 
   "mobile": "1112223333"
 }'

誰能指出我一個可以處理此信息的PHP處理器? 我的知識非常有限。

希望您可以與后端人員交談,但是據我所知,他們要求您使用javascript創建POST請求,該請求與示例中的curl命令具有相同的作用。

您的表單無法按原樣工作,因為它將使用編碼表單將請求發送到后端,但是后端需要JSON。

您需要捕獲表單提交,然后執行類似的操作

url = 'https://example.com/gateway/sms';
data = {mobile: _get_number_from_form() };
success = function(data) { console.log(data); };
headers = {s: 'APP'};
jQuery.ajax({
    type: 'POST',
    url: url,
    data: data,
    success: success,
    dataType: 'json',
    headers: headers
});

Chrome中的郵遞員和“網絡”標簽將在此處有用。

 $inNumber = $_REQUEST["inNumber"];
 $sender = $_REQUEST["sender"];
 $keyword = $_REQUEST["keyword"];
 $content = $_REQUEST["content"];
 $email = $_REQUEST["email"];
 $credits = $_REQUEST["credits"];

// Account details
        $apiKey = urlencode('jpvpyVsTv50-O7te5yiz3oP1DjMkdsiuHSUBS');

        // Message details
        $numbers = $_REQUEST["sender"];
        $sender = urlencode('JHSSVE');

        $text = "Thank you for your order";
        $message = rawurlencode($text);
     $test = true;

        // Prepare data for POST request
        $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

        // Send the POST request with cURL
        $ch = curl_init('https://api.textlocal.in/send/');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM