I have problem with schedule message with gateway please, If anybody can help me
This is my code. I have two table bulk_sms_job and bulk_sms_recipient where the Job_ID in bulk_sms_job is the same Job_ID in bulk_sms_recipient.
<?php
$con = mysqli_connect("127.0.0.1","username","passwordroot","database");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$td = @date('Y-m-d');
$tt = @date('H:i:00');
$ntime = @date('h:i:').'00';
$today = @date('Y-m-d H:i:00');
$nt = date('H:i:00', strtotime('+2 hours', strtotime($tt))); //+10 minutes
$ntty = date('Y-m-d H:i:00', strtotime('+10 minutes', strtotime($today)));
$query = mysqli_query($con,"SELECT j.Job_ID as jid, j.Message as msg, j.Schedule_Time as sch, r.MSISDN as msis FROM bulk_sms_job j LEFT JOIN bulk_sms_recipient r ON j.Job_ID = r.Job_ID AND r.Status = 'pending' AND j.Schedule_Time BETWEEN '{$today}' and '{$ntty}'") or die("Query to get Transaction Failed: .". mysqli_error($con));
while($resultT = mysqli_fetch_array($query)){
$jobid = $resultT['jid'];
$schd = $resultT['sch'];
$msisdns = $resultT['msis'];
$msg2 = $resultT['msg'];
$numbers = explode(",", $msisdns);
foreach($numbers as $number){
$msg = $msg2;
// send message to the gateway
$gwUser = "dkti";
$gwPass = "dkti";
$SCode = "";
$nid="";
$post_url = 'http://89.234.44.228:8080/httpbroker';
$post_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><bulk-request login=\"$gwUser\" password=\"$gwPass\" ref-id=\"$nid\" delivery-notification-requested=\"true\" version=\"1.0\">
<message
id=\"1\"
msisdn=\"$number\"
service-number=\"$SCode\"
operator=\"\"
defer-date=\"\"
validity-period=\"7\"
priority=\"1\"><content type=\"text/plain\">$msg</content>
</message>
</bulk-request>";
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml;charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$post_xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$returndata = curl_exec($ch);
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); // result=200
if ($returndata) {
// Update status in bulk_sms_recipient from pending to success
$status = "Success";
$UpdateSch = mysqli_query($con, "UPDATE bulk_sms_recipient SET Status = '{$status}' where Job_ID = '{$jobid}'") or die("Update Request status failed: .". mysqli_error($con));
}
curl_close($ch);
}
}
?>
Schedule Code
Moderator: General Moderators
Re: Schedule Code
You haven't said what the problem is.