/* php 5 voorbeeldscript
*************************/
$klantid=1; // uw klantid
$apiww="ww"; // uw apiwachtwoord
$smsgroep=1; // het id van de smsgroep
$smstext="Deze tekst dient te worden gesmsed";
$eurocent=55; // het smstarief voor de ontvanger in centen
/* Lees requestid uit bestand requestid.dat
** let op: bestand moet bestaan en initieel
** gevuld worden met een integer, bv 0
********************************************/
$requestid=file_get_contents('requestid.dat');
$requestid++;
file_put_contents('requestid.dat',$requestid);
/* Genereer xml data
*********************/
$postdata='<executecommands>
<requestid>'.$requestid.'</requestid>
<participantinfo>
<participantid>'.$klantid.'</participantid>
<hash>@@hash@</hash>
</participantinfo>';
$commandlist='<commandlist>
<command id="0">
<name>SendSMS_2_group</name>
<args>
<group id="'.$smsgroep.'"/>
<message type="0">
<text><![CDATA['.$smstext.']]></text>
</message>
<chargesamount>'.sprintf("%.2f",$eurocent/100).'</chargesamount>
<transactiontype>sendimmediate</transactiontype>
</args>
</command>
</commandlist>';
/* bereken hash
****************/
$hashber=$requestid.$klantid.$commandlist.$apiww;
$postdata=str_replace("@@hash@",md5($hashber),$postdata);
$postdata.=$commandlist.'</executecommands>';
/* Roep mkbsms api aan
***********************/
GetURLPost("http://api.mkbsms.com",utf8_encode($postdata),$queryxml);
/* Controleer resultaat
************************/
$fout="";
while ($fout=="") {
if (($xmlarray = simplexml_load_string($queryxml))==FALSE) { $fout="ongeldig
antwoord ontvangen van mkbsms server"; break; }
if
($xmlarray->result['type']!="OK") { $fout=$xmlarray->result->errordetails; break; }
// lees specifieke output van SendSMS_2_group commando
$opdrachtid=$xmlarray->commandlist->command[(int)0]->result->returndata->metatransactionid;
if ($opdrachtid=="") { $fout="geen opdrachtid ontvangen"; break; }
break;
}
if ($fout=="") {
$resulttext='Uw verzendopdracht is met succes aangemaakt! Het opdrachtnummer is '.$opdrachtid;
} else $resulttext='Het aanmaken van uw verzendopdracht is mislukt! Reden: '.$fout;
echo substr($resulttext,0,160);
/* HTTP Post request
*********************/
function GetURLPost($url,$postfields,&$output) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$output=curl_exec($ch);
curl_close ($ch);
}
| Helpdocumentatie v0.2.108, © 2006 mkbsms |