Bir proje için hazırlamış olduğum toplusms.com.tr api php sınıfı. Github veya aşağıdan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
<?php /** * Global Media www.globalmedia.com.tr * Created by PhpStorm. * Author: Emre KURT www.emrekurt.net * toplusms.com.tr API ClASS * *********************************************************************************************************** * How To Use: ****** * $sms = new GloballySms('YOUR_USERNAME','YOUR_PASSWORD','YOUR_ORGINATOR'); ****** * $sms->sendMultiReceiver('Kadir Geceniz Mübarek Olsun (Test)',['5444059964','5424981217']); ****** *********************************************************************************************************** */ namespace Globally\TopluSms; class TopluSms { public $username; public $password; public $origin; /** * GloballySms constructor. * @param $username * @param $password * @param $origin */ function __construct($username, $password, $origin) { $this->username = $username; $this->password = $password; $this->origin = $origin; } /** * @param $site_name * @param $send_xml * @return string */ function sendRequest($site_name, $send_xml) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $site_name); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $send_xml); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $results = curl_exec($ch); curl_close($ch); return $results; } /** * @param $site_name * @param $datas (no need to username and password) * @return string */ function getRequest($site_name, $datas = null) { $params = "UserName=$this->username&PassWord=$this->password"; if ($datas) foreach ($datas as $key => $data) $params = $params . "&$key=$data"; $url = $site_name . '?' . $params; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url )); $resp = curl_exec($curl); curl_close($curl); return $resp; } /** * @param $to * @param $text * @param null $sendDate = "240320160930"; (24/03/2016 09:30) date("dmYHi"); * @return string */ function singleSms($to, $text, $sendDate = null) { $xml = "<SingleTextSMS><UserName>$this->username</UserName><PassWord>$this->password</PassWord><Action>1</Action><Mesgbody>$text</Mesgbody><Numbers>$to</Numbers><Originator>" . $this->origin . "</Originator><SDate>$sendDate</SDate></SingleTextSMS>"; return $this->sendRequest('http://www.toplusms.com.tr/api/mesaj_gonder', 'data=' . $xml); } /** * @param $sendDate = "240320160930"; (24/03/2016 09:30) date("dmYHi"); * @array $smsInfo = array( * ['no'=>5444059964,'msg'=>'Bu Bir Test Mesajıdır'], * ['no'=>5424891217, 'msg'=> 'Bu Diğer Kişiye Mesajdır'] * ); * @return string */ function multiSms($smsInfo, $sendDate = null) { $xml = "<MultiTextSMS><UserName>$this->username</UserName><PassWord>$this->password</PassWord><Action>11</Action>"; $xml = "$xml<Messages>"; $inline = ""; foreach ($smsInfo as $smsItem) { $inline = $inline . "<Message><Mesgbody>" . $smsItem['msg'] . "</Mesgbody><Number>" . $smsItem['no'] . "</Number></Message>"; } $xml = $xml.$inline."</Messages><Originator>" . $this->origin . "</Originator><SDate>$sendDate</SDate></MultiTextSMS>"; //return $xml; return $this->sendRequest('http://www.toplusms.com.tr/api/mesaj_gonder', 'data=' . $xml); } /** * @param $text * @array $numbers * @return string */ function singleToMulti($text, $numbers, $sendDate = null) { $nums = join(',',$numbers); $xml = "<SingleTextSMS><UserName>$this->username</UserName><PassWord>$this->password</PassWord><Action>1</Action><Mesgbody>$text</Mesgbody><Numbers>$nums</Numbers><Originator>$this->origin</Originator><SDate>$sendDate</SDate></SingleTextSMS>"; return $this->sendRequest('http://www.toplusms.com.tr/api/mesaj_gonder', 'data=' . $xml); } /** * @param $id (Message ID) * @return string */ function getReportId($id) { /** * Get Request * http:// toplusms.com.tr/api/mesaj_raporu?UserName=gsm no&PassWord=123456&MsgId=64598895 */ return $this->getRequest('http:// toplusms.com.tr/api/mesaj_raporu', ['MsgId' => $id]); } /** * @param $startDate (Format: DDMMYYYY) * @param $endDate (Format: DDMMYYYY) * @return string */ function getReportDate($startDate, $endDate) { /** * Get Request * http:// toplusms.com.tr/api/tarih_raporu?UserName=gsm no&PassWord=sifre&Sdate=24032016&Fdate=08042016 */ return $this->getRequest('http://toplusms.com.tr/api/tarih_raporu', ['Sdate' => $startDate, 'Fdate' => $endDate]); } /** * @return string(xml) * You can use SimpleXMLElement class for converting xml data to array. */ function getCredit() { return $this->getRequest('http://toplusms.com.tr/api/kredi_raporu'); } } |
Bir cevap yazın