191 lines
8.3 KiB
PHP
Executable File
191 lines
8.3 KiB
PHP
Executable File
<?php
|
|
$nomFicAppelant = basename(__FILE__);
|
|
// ---------------------------------------------------
|
|
// ---------------------------------------------------
|
|
// Eric : 21/01/2021
|
|
// Envoi de SMS Marchand : lors d'une commande payée, client inscrit
|
|
// Quand on vient ici on a dejà dans l'appel :
|
|
// - verifié que SMS est activé ( hummm a verifier pas fait je crois pas)
|
|
// - fabriqué le message
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
// Si demo => usr Site message
|
|
// ---------------------------------------------------
|
|
if ($bdd=='demo' || $_SESSION['bdd']=='demo' || $_SESSION['isDemo']==1) {
|
|
// $usrSiteMsg=$usrSiteMsg .= 'Si l\'option SMS est activée, on envoi un SMS au gestionnaire (mais pas en démo) =><br> ' .$smsMessage;
|
|
}
|
|
else {
|
|
// ---------------------------------------------------
|
|
// 1 - recup gestionnaire send sms=1
|
|
// ---------------------------------------------------
|
|
$reqSelect="SELECT loginWeb FROM admin WHERE sms_oui='1';";
|
|
$resConn=$idPdo->query($reqSelect);
|
|
|
|
if (isset($debug[2]) && $debug[2] == '1' ) $debugMsg .= monDebug(2,['reqSelect' => $reqSelect],'sendMarchandSMS.php');
|
|
$mailExist='';
|
|
while ($result=$resConn->fetch(PDO::FETCH_ASSOC)) {
|
|
$mailExist=$result['loginWeb'];
|
|
}
|
|
|
|
// ---------------------------------------------------
|
|
// 1.1 - recup statut abo SMS depuis 123projets
|
|
// ---------------------------------------------------
|
|
include ("./admin/adminInclude/123connect.php");
|
|
$includePathAdmin="./admin/adminInclude";
|
|
include ("./admin/adminInclude/req/reqRecupClient123.php");
|
|
$aboSMS='';
|
|
$resConn='';
|
|
|
|
$reqSelect="SELECT `statut` from `123projets` WHERE idModule=3 AND idClient=" .$idClient123. "; ";
|
|
if (isset($debug[2]) && $debug[2] == '1' ) { $debugMsg .= monDebug(2,['reqSelect' => $reqSelect],''); }
|
|
$resConn=$connexion->query($reqSelect);
|
|
if ($resConn) {
|
|
$result=$resConn->fetch(PDO::FETCH_ASSOC);
|
|
$aboSMS=$result['statut'];
|
|
if (isset($debug[2]) && $debug[2] == '1' ) $debugMsg .= monDebug(2,['aboSMS' => $aboSMS],'');
|
|
}
|
|
else if (isset($debug[2]) && $debug[2] == '1' ) $debugMsg .= monDebug(2,['pas de resConn aboSMS' => $aboSMS],'');
|
|
|
|
if ($aboSMS=='actif' && $mailExist!='') {
|
|
// ---------------------------------------------------
|
|
// Recup infos,
|
|
// si trouvé,
|
|
// si credit >0
|
|
// liste des admins, pour chaque admin=sms_oui => envoi sms
|
|
// Sinon mail alerte credit
|
|
// Message pas trouvé marchand
|
|
// ---------------------------------------------------
|
|
|
|
// ---------------------------------------------------
|
|
// Récupérer le credit du compte marchand SMS
|
|
// ---------------------------------------------------
|
|
include ("./admin/extensions/sms/0.5retrieveCompteSmsFactor.php");
|
|
|
|
// ---------------------------------------------------
|
|
// si abonnement smsFactor existe et est trouvé
|
|
// ---------------------------------------------------
|
|
if ($trouve!=0) {
|
|
if ($credits >0) {
|
|
|
|
// ---------------------------------------------------
|
|
// Récupérer le token du marchand
|
|
// pourquoi 1 ?
|
|
// ---------------------------------------------------
|
|
$reqSelect="SELECT * from `prestas` WHERE idModule=3;";
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { $debugMsg .= monDebug(2,['reqSelect' => $reqSelect],''); }
|
|
$resConn="";
|
|
$existMarchand=0;
|
|
try{
|
|
$resConn=$idPdo->query($reqSelect);
|
|
|
|
if ($resConn) {
|
|
$tabFetch=$resConn->fetch(PDO::FETCH_ASSOC);
|
|
if ($tabFetch) {
|
|
// heu..je bugg quel clé on veut ici ?
|
|
$marchandToken=$tabFetch['valPubTestK'];
|
|
$existMarchand=1;
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { $debugMsg .= monDebug(2,['marchandToken' => $marchandToken],''); }
|
|
}
|
|
}
|
|
else {
|
|
$existMarchand=0;
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { $debugMsg .= monDebug(2,['marchand inexistant ' => $marchandToken],''); }
|
|
}
|
|
}
|
|
catch (PDOException $e) {
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { $debugMsg .= monDebug(2,['PDOException ' => $e],''); }
|
|
}
|
|
|
|
if ($existMarchand==1) {
|
|
|
|
// ---------------------------------------------------
|
|
// Preparer datas
|
|
// ---------------------------------------------------
|
|
$numbers='';
|
|
// charger les admins
|
|
if (empty($tableLibAdmin)) include ("./_include/req/15-init.adminMsgList");
|
|
|
|
// charger les n° tel admins
|
|
$n=0;
|
|
for($a=0;$a<count($tableLibAdmin);$a++) {
|
|
if ($tableAdminSms[$a]==1) {
|
|
|
|
// ---------------------------------------------------
|
|
// envoi par SMS Factor
|
|
// ---------------------------------------------------
|
|
// https://secure.smsfactor.com/token.html;
|
|
// ---------------------------------------------------
|
|
$sender = $_SESSION['nom_site']; //nom site
|
|
|
|
$postdata = array(
|
|
'sms' => array(
|
|
'message' => array(
|
|
'text' => $smsMessage,
|
|
'sender' => $sender
|
|
),
|
|
'recipients' => array('gsm' => $tableAdminAdresseSms[$a])
|
|
)
|
|
);
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/send");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $marchandToken));
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { $debugMsg .= monDebug(2,['Retour SMS' => $response ],''); }
|
|
}
|
|
|
|
// ---------------------------------------------------
|
|
// FORMAT DE LA REPONSE
|
|
// ---------------------------------------------------
|
|
// "status": 1,
|
|
// "message": "OK",
|
|
// "ticket": "14672468", //The id of your campaign
|
|
// "cost": 1, //The cost of your campaign
|
|
// "credits": 642, //Your credits after your campaign has been created
|
|
// "total": 1, //Number of message before filtering
|
|
// "sent": 1, //Number of message after filtering
|
|
// "blacklisted": 0, //Number of blacklisted numbers
|
|
// "duplicated": 0, //Number of duplicated numbers
|
|
// "invalid": 0, //Number of invalid numbers
|
|
// "npai": 0 //Number of npai numbers
|
|
} //for
|
|
} //existMarchand
|
|
|
|
} // credit >0
|
|
else {
|
|
// alerte mail credit
|
|
include ("./_include/_mail/mail_marchand_SMS_epuise.php");
|
|
$envMail = mailer(1, '','', 0, $_SESSION['smtpServer123'], $sujet, $message_business, $tableLibAdmin[$kk], '', '', 0, $navMsg[10], 'Alerte SMS épuisés envoyée avec succès', 0, '', '', $_SESSION['expediteur_mails123'], $_SESSION['from_mails123'], '', $lg);
|
|
|
|
// ---------------------------------------------------
|
|
// Modifier le statut de l'abonnement SMS de Actif a epuisé
|
|
// ---------------------------------------------------
|
|
if (empty($includePathAdmin)) $includePathAdmin="./admin/adminInclude";
|
|
|
|
|
|
// 1 - recup idClient 123clients
|
|
include ($includePathAdmin. "/req/reqRecupClient123.php");
|
|
|
|
if (!empty($idClient123)) {
|
|
$reqUpdate="UPDATE `123projets` SET statut='epuisé' WHERE idClient=" .$idClient123. " AND idModule=3;";
|
|
|
|
if (isset($debug[2]) && $debug[2] == '1' ) $debugMsg .= monDebug(2,['reqUpdate' => $reqUpdate ],'');
|
|
$resConn=$connexion->query($reqUpdate);
|
|
$resConn=$connexion->query($reqUpdate);
|
|
if ($resConn) {
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .= monDebug(2,['Mise à jour du l\'abonnement sms epuisé' => 'ok' ],'');
|
|
}
|
|
else {
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .= monDebug(2,['Echec de la mise à jour de l\'abonnement sms epuisé => marchandTokenSMS.php' => $reqUpdate ],'');
|
|
}
|
|
}// pas empty 123client
|
|
}//credit >0
|
|
} // marchand trouvé
|
|
else if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .= monDebug(2,['Marchand non trouvé' => $response ],'');
|
|
} // pas actif
|
|
} //pas demo
|
|
?>
|