$ AUTH_XML = "
$ CLOSE_XML = '';
$ RESOURCE_XML = '
"
"
$ SESSION_XML = '
"Sesión> xmlns="urn:ietf:params:xml:ns:xmpp-session"/> ';
$ Start_tls = '
open_connection función ($ servidor) {
print "[INFO] conexión de apertura ...";
$ Fp = fsockopen ($ servidor, 5222, $ errno, $ errstr);
if ($ fp) {
print "$ errstr ($ errno)
";
} Else {
print "
connnection abierto";
}
return $ fp;
}
función send_xml ($ fp, $ xml) {
fwrite ($ fp, $ xml);
}
función recv_xml ($ fp, $ size = 4096) {
$ Xml = fread ($ fp, $ size);
if ($ xml === "") {
return null;
}
/ / Analiza xml
$ Xml_parser xml_parser_create = ();
xml_parse_into_struct ($ xml_parser, $ xml, $ val, $ index);
xml_parser_free ($ xml_parser);
return array ($ val, $ index);
}
función find_xmpp ($ fp, $ etiqueta, $ value = null, y $ ret = null) {
estática $ val = null, $ indice = null;
do {
if ($ val === índice null & & $ === null) {
list ($ val, $ index) = recv_xml ($ fp);
if ($ val === null | | $ índice === null) {
return false;
}
}
foreach ($ index como $ tag_key => $ tag_array) {
if ($ tag_key === $ tag) {
if ($ valor === null) {
if (isset ($ val [$ tag_array [0]] ['valor'])) {
$ Ret = $ val [$ tag_array [0]] ['valor'];
}
return true;
}
foreach ($ i $ como tag_array => $ pos) {
if ($ val [$ pos] ['tag'] === $ tag & & isset ($ val [$ pos] ['valor']) & &
$ Val [$ pos] ['valor'] === $ valor) {
$ Ret = $ val [$ pos] ['valor'];
return true;
}
}
}
}
$ Val = $ index = null;
Mientras} (! Feof ($ fp));
return false;
}
xmpp_connect función ($ opciones, $ access_token) {
global $ STREAM_XML, AUTH_XML $, $ RESOURCE_XML, SESSION_XML $, $ CLOSE_XML, $ start_tls;
$ Fp = open_connection ($ options ['server']);
if ($ fp) {
return false;
}
/ / Inicia el proceso de autenticación (con X-FACEBOOK_PLATFORM)
send_xml ($ fp, $ STREAM_XML);
if (find_xmpp ($ fp, 'STREAM: STREAM'!)) {
return false;
}
if (! find_xmpp ($ fp, "mecanismo", "X-Facebook-plataforma")) {
return false;
}
/ / Tls de partida - obligatorio el uso de OAuth TOKEN!!
send_xml ($ fp, $ start_tls);
if (! find_xmpp ($ fp, "proceder", null, $ proceda)) {
return false;
}
stream_socket_enable_crypto ($ fp, es cierto, STREAM_CRYPTO_METHOD_TLS_CLIENT);
send_xml ($ fp, $ STREAM_XML);
if (find_xmpp ($ fp, 'STREAM: STREAM'!)) {
return false;
}
if (! find_xmpp ($ fp, "mecanismo", "X-Facebook-plataforma")) {
return false;
}
/ / Obtiene desafío desde el servidor y decodificarlo
send_xml ($ fp, $ AUTH_XML);
if (! find_xmpp ($ fp, 'Desafío', null, $ reto)) {
return false;
}
$ Reto = base64_decode ($ reto);
$ Reto urldecode = ($ reto);
parse_str ($ reto, $ challenge_array);
/ / Crea la matriz de respuesta
$ Resp_array = array (
'Método' => $ challenge_array ['método'],
'Nonce' => $ challenge_array ['nonce'],
"Access_token '=> $ access_token,
"Api_key '=> $ options [' app_id '],
"Call_id '=> 0,
'V' => '1 .0 ',
);
/ / Crea la firma
$ Respuesta = http_build_query ($ resp_array);
/ / Envía la respuesta y espera para el éxito
$ Xml = "
base64_encode ($ respuesta respuesta ).' ';
send_xml ($ fp, $ xml);
if (! find_xmpp ($ fp, 'Exito')) {
return false;
}
/ / Finaliza el proceso de autenticación
send_xml ($ fp, $ STREAM_XML);
if (find_xmpp ($ fp, 'STREAM: STREAM'!)) {
return false;
}
if (find_xmpp ($ fp, 'STREAM: OPCIONES'!)) {
return false;
}
send_xml ($ fp, $ RESOURCE_XML);
if (! find_xmpp ($ fp, "JID")) {
return false;
}
send_xml ($ fp, $ SESSION_XML);
if (! find_xmpp ($ fp, 'sesión')) {
return false;
}
/ / ¡Lo logramos!
send_xml ($ fp, $ CLOSE_XML);
print ("
autenticación completa");
fclose ($ fp);
return true;
}
/ / Obtiene access_token con permiso xmpp_login
función get_access_token ($ app_id, $ app_secret, $ my_url) {
$ Code = $ _REQUEST ["code"];
if (empty ($ code)) {
$ Dialog_url = "http://www.facebook.com/dialog/oauth?scope=xmpp_login".
"Y client_id =". $ App_id. "Y redirect_uri =". urlencode ($ my_url);
echo ("
No hay comentarios:
Publicar un comentario