Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถาม JSON กับ PHP หน่อยครับผมต้องการเขียนเพื่อส่ง sms



 

สอบถาม JSON กับ PHP หน่อยครับผมต้องการเขียนเพื่อส่ง sms

 



Topic : 128389



โพสกระทู้ ( 0 )
บทความ ( 0 )



สถานะออฟไลน์




ผมเป็น Network Engineer ไม่รุ้เรื่อง เว็บเลยครับ พอดีได้โจทย์ว่าต้องส่ง sms alarm จาก network device อยากถามว่าผมจะแทรก code json ที่ทาง บริษัท sms gateway เขาส่งมาให้ลงใน หน้าเว็บ php ยังไงได้บ้างครับ พอดีเว็บ server รองรับเป็น php

code detail ประมาณนี้

POST /sms/1/text/single HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
Accept: application/json

{
"from":"InfoSMS",
"to":"41793026727",
"text":"Test SMS."
}



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-07-27 09:06:31 By : pookpix View : 1001 Reply : 1
 

 

No. 1



โพสกระทู้ ( 219 )
บทความ ( 5 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ตัวอย่างสำหรับการส่งผ่านเว็บครับ เอาไปใส่ในเว็บเซริฟเวอร์แล้วก็แก้ไขในส่วน username และ password (ตอนสมัคร infobip เขาจะให้มา)
แก้ไขเสร็จ ก็ลองคีย์ข้อมความที่จะส่ง กด submit

Code (PHP)
<?php
//api.infibip.com API user and pass
$username = "xxxxxxxxxxxxxxxx";
$password = "xxxxxxxxxxxxxxxx";

//if (isset($_POST['toInput'])) { 
if(isset($_POST['submit'])){
    
$message=  rawurlencode($_POST['message']);
//$message="Hello Test";
$FromoPhone="081xxxxxx";
$ToPhone="41793026727";    
//$ToPhone=$_POST['phone'];

// URL for sending request
$postUrl = "https://api.infobip.com//sms/1/text/single";

// creating an object for sending SMS
$destination = array("messageId" => $messageId, "to" => $ToPhone);

//    $message = array("from" => $FromoPhone,
//        "destinations" => array($destination),
//        "text" => $message,
//        "notifyUrl" => $notifyUrl,
//        "notifyContentType" => $notifyContentType,
//        "callbackData" => $callbackData);
    
$message = array("from" => $FromoPhone, "destinations" => array($destination),"text" => $message);
    
$postData = array("messages" => array($message));
// encoding object
$postDataJson = json_encode($postData)
    

$ch = curl_init();
$header = array("Content-Type:application/json", "Accept:application/json");

curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postDataJson);

// response of the POST request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$responseBody = json_decode($response);
curl_close($ch);   
}

//if ($httpCode >= 200 && $httpCode < 300) {
//	$logs = $responseBody->results;
//	foreach ($logs as $log) {
//	    echo "<tr>";
//        echo "<td>" . $log->messageId . "</td>";
//        echo "<td>" . $log->to . "</td>";
//        echo "<td>" . $log->from . "</td>";
//        echo "<td>" . $log->text . "</td>";
//        echo "<td>" . $log->status->groupName . "</td>";
//        echo "<td>" . $log->status->description . "</td>";
//        // format the date
//        $formattedSentAt = date("M d, Y - H:i:s P T", strtotime($log->sentAt));    
//        echo "<td>" . $formattedSentAt . "</td>";
//        echo "</tr>";         
//    }
//}
?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
Phone: <input type="text" name="phone"><br>
Message: <input type="text" name="message"><br>
<input type="submit" name="submit" value="sent">
</form>


หากต้องการส่งค่ามาจาก Netword Device ก็ commect ตรง If(){-----) ให้มันข้ามไป
และไม่ต้องการใช้ Form ก็ตัดออกให้เหลือเฉพาะ php ก็ได้
ดูรายละเอียดจากผู้ให้บริการได้
- https://www.infobip.com/en/blog/step-by-step-sms-api-php-tutorial-create-your-new-web-app
- https://github.com/infobip/infobip-api-php-tutorial








ประวัติการแก้ไข
2017-07-27 23:52:53
2017-07-27 23:56:51
2017-07-28 00:53:51
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-07-27 18:46:14 By : ccjpn
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม JSON กับ PHP หน่อยครับผมต้องการเขียนเพื่อส่ง sms
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่