Current File : /home/inlingua/www/crm.vprotectindia.com/cron/send_payment_link.php |
<?php
$conn = new mysqli("localhost", "inlingua_vprotect_user", "zDqxZh3sn65?vyjN", "inlingua_vprotect");
// Check connection
if ($conn ->connect_error) {
die("Connection failed: " . $conn ->connect_error);
}
// Data array
$CUSTOMER_TRX_ID=$_GET['CUSTOMER_TRX_ID'];
if (isset($_GET['CUSTOMER_TRX_ID']) && !empty($_GET['CUSTOMER_TRX_ID'])) {
$CUSTOMER_TRX_ID = $_GET['CUSTOMER_TRX_ID']; // get the value
//echo "ID is: " . htmlspecialchars($id);
} else {
$CUSTOMER_TRX_ID ='0';
}
if( $CUSTOMER_TRX_ID>0){
$check = "SELECT * FROM outstanding_reports WHERE customer_trx_id='".$CUSTOMER_TRX_ID."' ";
$result = $conn->query($check);
if ($result->num_rows > 0) {
//echo "recor already exists.".'<br>';
$data = mysqli_fetch_assoc($result);
$customer = "SELECT * FROM customers WHERE ACCOUNT_NUMBER='".$data['customer_number']."' ";
$res_cus = $conn->query($customer);
if ($res_cus->num_rows > 0) {
$row1 = mysqli_fetch_assoc($res_cus);
if($row1['CUSTOMER_PHONE_NUMBER']!=''){
$phone='91'.$row1['CUSTOMER_PHONE_NUMBER'];
$billno=$data['invoice_number'];
$amount=$data['bal_func_amt'];
$DUE_DATE= $data['DUE_DATE'];
$date = new DateTime($DUE_DATE);
$newdate=$date->format("d F Y");
$response = sendTextMessage($phone, $billno, $amount,$newdate);
$response['id'];
"Link Send successfully.";
if($response['id'] !=''){
$created_date=date("Y-m-d h:i:s");
$whatsapp = "INSERT INTO `whatsapp_msgs` (`id`, `title`, `mobile_no`, `send_id`, `amount`, `invoice_number`, `created_date`,`send_way`) VALUES (NULL, '".$data['party_name']."', '".$phone."', '".$response['id']."', '".$amount."', '".$billno."', '".$created_date."','admin-send-link')";
$res_whatsapp = $conn->query($whatsapp);
}
}
//echo "recor already exists.".'<br>';
}
} else {
echo "recor Not exists.".'<br>';
}
}else {
echo "recor Not exists.".'<br>';
}
function sendTextMessage($phone, $billno, $amount,$date) {
$token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwaG9uZU51bWJlciI6Iis5MTg0NDcxMjQ5NjYiLCJwaG9uZU51bWJlcklkIjoiMTM3NjUzNDQ5NDI4NTg4IiwiaWF0IjoxNjk1NzI5ODkxfQ.zouNW93K9Je56uNrDoyHqLWwrApcZbyUtsl88rpd7wo';
$apiBase = 'https://wb.omni.tatatelebusiness.com/whatsapp-cloud/messages';
$body =[
"to"=> $phone,
"type"=> "template",
"source"=> "external",
"template"=> [
"name"=> "bill_notification_v022",
"language"=> [
"code"=> "en"
],
"components"=> [
[
"type"=> "header",
"parameters"=> [
[
"type"=> "image",
"image"=> [
"link"=> "https://crm.vprotectindia.com/public/user/img/brand/white.png"
]
]
]
],
[
"type"=> "body",
"parameters"=> [
[
"type"=> "text",
"text"=> $billno
],
[
"type"=> "text",
"text"=> $amount
],
[
"type"=> "text",
"text"=> $date
]
]
],[
"type"=> "button",
"sub_type"=> "URL",
"index"=> 0,
"parameters"=> [
[
"type"=> "text",
"text"=> $billno
]
]
],[
"type"=> "button",
"sub_type"=> "URL",
"index"=> 1,
"parameters"=> [
[
"type"=> "text",
"text"=> $billno
]
]
]
]
],
"metaData"=> [
"custom_callback_data"=> "<optional_value>"
]
];
//echo '<pre>'; echo json_encode($body); exit;
$ch = curl_init("$apiBase");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization:$token",
"accept: application/json",
"content-type: application/json; charset=utf-8 "
],
CURLOPT_POSTFIELDS => json_encode($body)
]);
$resp = curl_exec($ch);
curl_close($ch);
return json_decode($resp, true);
}
$conn->close();
?>