349 lines
12 KiB
PHP
Executable File
349 lines
12 KiB
PHP
Executable File
<?php
|
|
$nomFicAppelant = basename(__FILE__);
|
|
// -----------------------------------------------------
|
|
// Init
|
|
// -----------------------------------------------------
|
|
$continuer=0;
|
|
|
|
if ($_SESSION['idSms']==1) $nbSMS=800;
|
|
if ($_SESSION['idSms']==2) $nbSMS=2000;
|
|
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $nbSMS=1;
|
|
|
|
// -----------------------------------------------------
|
|
// Debug
|
|
// -----------------------------------------------------
|
|
if (isset($debug[1]) && $debug[1] == '1') {
|
|
echo '<br>nom = ' .$contactMsg[10];
|
|
echo '<br>prenom = ' .$contactMsg[41];
|
|
echo '<br>address1 = ' .$contactMsg[13];
|
|
echo '<br>codePostal = ' .$contactMsg[15];
|
|
echo '<br>city = ' .$contactMsg[14];
|
|
echo '<br>mail = ' .$emailAdmin;
|
|
echo '<br>tel = ' .$phoneAdmin;
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// Tester s'il a pas déjà un compte : cas du réabonnement ou changement de forfait
|
|
// -----------------------------------------------------
|
|
$reqSelect="SELECT * from `prestas` WHERE idModule=3;";
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {echo '<br>reqSelect SMS presta = ' .$reqSelect. ' | <br>';}
|
|
$resConn='';
|
|
$resConn=$idPdo->query($reqSelect);
|
|
if ($resConn) {
|
|
$existMarchand=1;
|
|
$tabResult = $resConn->fetch(PDO::FETCH_ASSOC);
|
|
$idCompteSMS=$tabResult['idCompte'];
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {
|
|
echo '<br>marchand existe : ' .$existMarchand;
|
|
echo '<br>idCompteSMS : ' .$idCompteSMS;
|
|
echo '<br>';
|
|
}
|
|
}
|
|
else {
|
|
$existMarchand=0;
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {echo 'marchand existe pas : ' .$existMarchand;}
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// Il n'a pas de compte, créer le sub account avec ma clé
|
|
// -----------------------------------------------------
|
|
if ($existMarchand==0) {
|
|
// https://secure.smsfactor.com/token.html;
|
|
include ($includePathAdmin. "/psk/psk.smsFactor.php");
|
|
// $token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MzQxMyIsImlhdCI6MTYxOTI5NzM4OX0.WF7mz-IkZ_wXIs7khuibbBypEDKile9nSo3wc7nu-mk ";
|
|
|
|
// -----------------------------------------------------
|
|
// Créer le CLient dans smsFactor
|
|
// -----------------------------------------------------
|
|
$postdata = array(
|
|
'account' => array(
|
|
'email' => $emailAdmin,
|
|
'password' => $pwdAdmin,
|
|
'firstname' => $contactMsg[10],
|
|
'lastname' => $contactMsg[41],
|
|
'city' => $contactMsg[14],
|
|
'phone' => $phoneAdmin,
|
|
'address1' => $contactMsg[13],
|
|
'zip' => $contactMsg[15],
|
|
'country_code' => 'fr',
|
|
'isChild' => 1,
|
|
'description' => 'Sous-compte 123ventes',
|
|
'unlimited' => $nbSMS,
|
|
)
|
|
);
|
|
|
|
// -----------------------------------------------------
|
|
// Execution Curl
|
|
// -----------------------------------------------------
|
|
$ch = curl_init();
|
|
try {
|
|
curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/account");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
|
|
|
|
// Execution et Retour
|
|
$response = json_decode(curl_exec($ch),true);
|
|
if (curl_errno($ch)) {
|
|
echo curl_error($ch);
|
|
die();
|
|
}
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
if ($http_code == intval(200)) {
|
|
if (isset($debug[1]) && $debug[1] == '1') {
|
|
echo '<PRE>';
|
|
print_r($response);
|
|
echo '</PRE>';
|
|
}
|
|
$output= 'Compte SMS créé'; $continuer=1;
|
|
$statut=$response['status'];
|
|
$message=$response['message'];
|
|
$idCompteSMS=$response['id'];
|
|
$active=$response['active'];
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> statut ='.($statut);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> message ='.($message);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> active ='.($active);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> idCompteSMS ='.($idCompteSMS);
|
|
$_SESSION['idCompteSMS']=$idCompteSMS;
|
|
|
|
|
|
// if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> statut =>' .$statut;
|
|
// /if ($statut=='-7') {
|
|
// echo '<br>' .$retourDet;
|
|
// $continuer=0;
|
|
// }
|
|
// else $continuer=1;
|
|
// if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> continuer =' .$continuer;
|
|
|
|
|
|
}
|
|
else {
|
|
echo "<br>Ressource introuvable : " .$http_code. "<br>";
|
|
$output='Erreur création compte SMS : '.curl_error($ch); $continuer=0;
|
|
}
|
|
}
|
|
catch (\Throwable $th) {
|
|
throw $th;
|
|
$err = curl_error($ch);
|
|
echo $err;
|
|
$output='Erreur création compte SMS : '.curl_error($ch); $continuer=0;
|
|
}
|
|
finally {
|
|
curl_close($ch);
|
|
}
|
|
|
|
// if ($response === false)
|
|
// { }
|
|
// else
|
|
// {}
|
|
// curl_close($ch);
|
|
|
|
// // Debug
|
|
// if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> ' .$output;
|
|
// $response=str_replace('\u00e9', "é", $response);
|
|
// $response=str_replace('\\u00e0', "à", $response);
|
|
// if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> Response =' .$response;
|
|
// if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> debug = ' .$debug;
|
|
|
|
// $tabResp=json_decode($response, true);
|
|
|
|
// $idCompteSMS=$tabResp['id'];
|
|
// $retour=$tabResp['message'];
|
|
// $retourDet=$tabResp['details'];
|
|
// $_SESSION['idCompteSMS']=$idCompteSMS;
|
|
|
|
|
|
// utilisateur déjà existant avec ce mail ( cas du réabo ) mais on ne devrait plus passer par là
|
|
|
|
|
|
|
|
// -----------------------------------------------------
|
|
// Créer la prestation
|
|
// -----------------------------------------------------
|
|
if ($continuer==1) {
|
|
if (!empty($subAccountToken)) {
|
|
$reqInsert="INSERT INTO `prestas` (idModule,idCompte,activ ) VALUES (3, '" .$idCompteSMS. ",'1') ;";
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {echo '<br>reqInsert SMS presta= ' .$reqInsert. ' | <br>';}
|
|
$resConn=$idPdo->query($reqSelect);
|
|
if ($resConn) {
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {echo 'insert SMS into prestas ok';}
|
|
}
|
|
else {
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {echo "insert SMS into prestas ko (0.2createCompteSmsFactor.php). Requete =>" .$reqInsert; $admMsgClass='ko';}
|
|
}
|
|
}
|
|
} //continuer
|
|
} // pas deja un compte
|
|
|
|
// -----------------------------------------------------
|
|
// Il a déjà un compte
|
|
// -----------------------------------------------------
|
|
if ($existMarchand==1) {
|
|
include ($includePathAdmin. "/psk/psk.smsFactor.php");
|
|
|
|
// -----------------------------------------------
|
|
// Code a garder : retrouver tous les comptes = ok
|
|
// -----------------------------------------------
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
// curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/sub-accounts");
|
|
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
|
|
// $response = curl_exec($ch);
|
|
// $err = curl_error($ch);
|
|
// echo $response;
|
|
|
|
// -----------------------------------------------
|
|
// Code a garder : retrouver un sous compte = ok
|
|
// -----------------------------------------------
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
// curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/sub-accounts/54366");
|
|
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
|
|
// $response = curl_exec($ch);
|
|
// $err = curl_error($ch);
|
|
// echo $response;
|
|
|
|
// -----------------------------------------------
|
|
// activer son compte
|
|
// -----------------------------------------------
|
|
// pour activer un compte
|
|
// GET /account/:id/lock
|
|
//
|
|
$ch = curl_init();
|
|
try {
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/account/" .$idCompteSMS. "/unlock");
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
|
|
$response = json_decode(curl_exec($ch),true);
|
|
if (curl_errno($ch)) {
|
|
echo curl_error($ch);
|
|
die();
|
|
}
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
if ($http_code == intval(200)) {
|
|
echo "<br>Ressource trouvable : " .$http_code. "<br>";
|
|
if (isset($debug[1]) && $debug[1] == '1') {
|
|
echo '<PRE>';
|
|
print_r($response);
|
|
echo '</PRE>';
|
|
}
|
|
}
|
|
else {
|
|
echo "<br>Ressource introuvable : " .$http_code. "<br>";
|
|
}
|
|
|
|
}
|
|
catch (\Throwable $th) {
|
|
throw $th;
|
|
$err = curl_error($ch);
|
|
echo $err;
|
|
}
|
|
finally {
|
|
curl_close($ch);
|
|
}
|
|
|
|
// -----------------------------------------------
|
|
// Faire un update de son credit sur smsFactor
|
|
// -----------------------------------------------
|
|
// POST /account/transfer HTTP/1.1
|
|
// Host: api.smsfactor.com
|
|
// Authorization: Bearer your.token
|
|
// Accept: application/json
|
|
|
|
// -----------------------------------------------------
|
|
// Preparation Curl
|
|
// -----------------------------------------------------
|
|
$postdata = array(
|
|
'transfer'=>array (
|
|
'to_account' => $idCompteSMS,
|
|
'credits' => $nbSMS
|
|
)
|
|
);
|
|
|
|
// -----------------------------------------------------
|
|
// Execution Curl
|
|
// -----------------------------------------------------
|
|
$ch = curl_init();
|
|
try {
|
|
curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/account/transfer");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
|
|
|
|
// Execution et Retour
|
|
$response = json_decode(curl_exec($ch),true);
|
|
if (curl_errno($ch)) {
|
|
echo curl_error($ch);
|
|
die();
|
|
}
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
if ($http_code == intval(200)) {
|
|
if (isset($debug[1]) && $debug[1] == '1') {
|
|
echo '<PRE>';
|
|
print_r($response);
|
|
echo '</PRE>';
|
|
}
|
|
|
|
$status=$response['status'];
|
|
$message=$response['message'];
|
|
$details=$response['details'];
|
|
$child_credits=$response['child_credits'];
|
|
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> status ='.($status);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> message ='.($message);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> details ='.($details);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> child_credits ='.($child_credits);
|
|
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='<br> nbSMS ='.($nbSMS);
|
|
if ($status==1) {
|
|
$output= 'Compte SMS crédité';
|
|
$continuer=1;
|
|
}
|
|
else {
|
|
$output='Erreur créditation compte SMS';
|
|
$continuer=0;
|
|
}
|
|
}
|
|
else {
|
|
echo "<br>Ressource introuvable : " .$http_code. "<br>";
|
|
$output='Erreur créditation compte SMS : '.curl_error($ch); $continuer=0;
|
|
}
|
|
}
|
|
catch (\Throwable $th) {
|
|
throw $th;
|
|
$err = curl_error($ch);
|
|
echo $err;
|
|
$output='Erreur creditation compte SMS : '.curl_error($ch); $continuer=0;
|
|
}
|
|
finally {
|
|
curl_close($ch);
|
|
}
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { echo "<br>" .$output;}
|
|
|
|
|
|
|
|
// on fera un update de son compte 123ventes/projets en passant le staut a actif dans 123ventes, à l'etape 4
|
|
if (isset($debug[1]) && $debug[1] == '1' ) { echo "<br>Marchand existe -> mettre son compte actif en etape 4";}
|
|
}
|
|
|
|
?>
|