-
-
@@ -334,7 +301,83 @@ function websmsApp() {
},
formatDate(d){ if(!d) return ''; return new Date(d).toLocaleDateString('es-CO',{day:'2-digit',month:'short',year:'numeric',hour:'2-digit',minute:'2-digit'}); },
- copy(text){ navigator.clipboard.writeText(text); this.copied='URL copiada'; setTimeout(()=>this.copied='', 2000); },
+ copy(text){ navigator.clipboard.writeText(text); this.copied='Copiado'; setTimeout(()=>this.copied='', 2000); },
+
+ getCodeExample(tab) {
+ const key = this.secretKey || '{API_KEY}';
+ const url = 'https://admin.u-site.app/api/sms/send';
+ if (tab === 'curl') {
+ return [
+ "curl -X POST " + url + " \\",
+ " -H 'Authorization: Bearer " + key + "' \\",
+ " -H 'Content-Type: application/json' \\",
+ " -d '{",
+ ' "numero": "573001234567",',
+ ' "mensaje": "Hola, este es tu código: 9821"',
+ " }'"
+ ].join('\n');
+ }
+ if (tab === 'js') {
+ return [
+ "const response = await fetch('" + url + "', {",
+ " method: 'POST',",
+ " headers: {",
+ " 'Authorization': 'Bearer " + key + "',",
+ " 'Content-Type': 'application/json',",
+ " },",
+ " body: JSON.stringify({",
+ " numero: '573001234567',",
+ " mensaje: 'Hola, este es tu código: 9821',",
+ " }),",
+ "});",
+ "",
+ "const data = await response.json();",
+ "console.log(data); // { ok: true, id: '6a3d...' }"
+ ].join('\n');
+ }
+ if (tab === 'php') {
+ return [
+ " true,",
+ " CURLOPT_POST => true,",
+ " CURLOPT_HTTPHEADER => [",
+ " 'Authorization: Bearer " + key + "',",
+ " 'Content-Type: application/json',",
+ " ],",
+ ' CURLOPT_POSTFIELDS => json_encode([',
+ " 'numero' => '573001234567',",
+ " 'mensaje' => 'Hola, este es tu código: 9821',",
+ " ]),",
+ "]);",
+ "$response = json_decode(curl_exec($ch), true);",
+ "curl_close($ch);",
+ "// $response['ok'] === true"
+ ].join('\n');
+ }
+ if (tab === 'python') {
+ return [
+ "import requests",
+ "",
+ "response = requests.post(",
+ " '" + url + "',",
+ " headers={",
+ " 'Authorization': 'Bearer " + key + "',",
+ " 'Content-Type': 'application/json',",
+ " },",
+ " json={",
+ " 'numero': '573001234567',",
+ " 'mensaje': 'Hola, este es tu código: 9821',",
+ " },",
+ ")",
+ "",
+ "data = response.json()",
+ "print(data) # {'ok': True, 'id': '6a3d...'}"
+ ].join('\n');
+ }
+ return '';
+ },
}
}