nom = ' .$contactMsg[10]; echo '
prenom = ' .$contactMsg[41]; echo '
address1 = ' .$contactMsg[13]; echo '
codePostal = ' .$contactMsg[15]; echo '
city = ' .$contactMsg[14]; echo '
mail = ' .$emailAdmin; echo '
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 '
reqSelect SMS presta = ' .$reqSelect. ' |
';} $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 '
marchand existe : ' .$existMarchand; echo '
idCompteSMS : ' .$idCompteSMS; echo '
'; } } 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 '
';
					print_r($response);
					echo '
'; } $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 .='
statut ='.($statut); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
message ='.($message); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
active ='.($active); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
idCompteSMS ='.($idCompteSMS); $_SESSION['idCompteSMS']=$idCompteSMS; // if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
statut =>' .$statut; // /if ($statut=='-7') { // echo '
' .$retourDet; // $continuer=0; // } // else $continuer=1; // if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
continuer =' .$continuer; } else { echo "
Ressource introuvable : " .$http_code. "
"; $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 .='
' .$output; // $response=str_replace('\u00e9', "é", $response); // $response=str_replace('\\u00e0', "à", $response); // if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
Response =' .$response; // if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
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 '
reqInsert SMS presta= ' .$reqInsert. ' |
';} $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 "
Ressource trouvable : " .$http_code. "
"; if (isset($debug[1]) && $debug[1] == '1') { echo '
';
					print_r($response);
					echo '
'; } } else { echo "
Ressource introuvable : " .$http_code. "
"; } } 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 '
';
					print_r($response);
					echo '
'; } $status=$response['status']; $message=$response['message']; $details=$response['details']; $child_credits=$response['child_credits']; if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
status ='.($status); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
message ='.($message); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
details ='.($details); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
child_credits ='.($child_credits); if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='
nbSMS ='.($nbSMS); if ($status==1) { $output= 'Compte SMS crédité'; $continuer=1; } else { $output='Erreur créditation compte SMS'; $continuer=0; } } else { echo "
Ressource introuvable : " .$http_code. "
"; $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 "
" .$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 "
Marchand existe -> mettre son compte actif en etape 4";} } ?>