Enviando mensajes de WhatsApp

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Enviando mensajes de WhatsApp

Post by Antonio Linares »

He comenzado a revisar el código publicado en:
https://github.com/aesedepece/WhatsAPI/blob/master/php/whatsapp.class.php

Estoy usndo los sockets de Harbour para que funcione desde cualquier sistema operativo. Aqui comparto los primeros pasos
para aquellos que esten interesados y que quieran probar y ayudar:

Code: Select all | Expand

#include "hbsocket.ch"function Main()   local pSocket := hb_socketOpen()      local cIPAddr := hb_socketGetHosts( "bin-short.whatsapp.net" )[ 1 ]   local cBuffer := Space( 1024 )      ? hb_socketConnect( pSocket, { HB_SOCKET_AF_INET, cIPAddr, 5222 } )   ? hb_socketSend( pSocket, "WA" + "\x01\x00\x00\x19\xf8\x05\x01\xa0\x8a\x84\xfc\x11" + ;                    "iPhone-2.6.9-5222" + ;                            "\x00\x08\xf8\x02\x96\xf8\x01\xf8\x01\x7e\x00\x07\xf8\x05\x0f\x5a\x2a\xbd\xa7" )   ? hb_socketRecv( pSocket, @cBuffer )  // Deberiamos recibir una respuesta aqui   HB_SocketShutDown( pSocket )   HB_SocketClose( pSocket )return nil


Deberiamos recibir datos al llamar a hb_socketRecv() pero llegan cero bytes.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

Arreglado, ahora recibimos la respuesta :-)

Code: Select all | Expand

#include "hbsocket.ch"function Main()   local pSocket := hb_socketOpen()      local cIPAddr := hb_socketGetHosts( "bin-short.whatsapp.net" )[ 1 ]   local cBuffer := Space( 1024 )      ? hb_socketConnect( pSocket, { HB_SOCKET_AF_INET, cIPAddr, 5222 } )   ? hb_socketSend( pSocket, "WA" + Chr( 0x01 ) + Chr( 0 ) + Chr( 0 ) + ;                    Chr( 0x19 ) + Chr( 0xF8 ) + Chr( 0x05 ) + Chr( 0x01 ) + ;                    Chr( 0xA0 ) + Chr( 0x8A ) + Chr( 0x84 ) + Chr( 0xFC ) + ;                    Chr( 0x11 ) + "iPhone-2.6.9-5222" + ;                            Chr( 0 ) + Chr( 0x08 ) + Chr( 0xF8 ) + Chr( 0x02 ) + ;                            Chr( 0x96 ) + Chr( 0xF8 ) + Chr( 0x01 ) + Chr( 0xF8 ) + ;                            Chr( 0x01 ) + Chr( 0x7E ) + Chr( 0 ) + Chr( 0x07 ) + Chr( 0xF8 ) + ;                            Chr( 0x05 ) + Chr( 0x0F ) + Chr( 0x5A ) + Chr( 0x2A ) + ;                            Chr( 0xBD ) + Chr( 0xA7 ) )   ? hb_socketRecv( pSocket, @cBuffer )    HB_SocketShutDown( pSocket )   HB_SocketClose( pSocket )return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Andrés González
Posts: 630
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca
Been thanked: 1 time

Re: Enviando mensajes de WhatsApp

Post by Andrés González »

Cuando te refieres a cualquier sistema operativo, te refieres a ellos en general o solo aquellos que corran en un dispositivo móvil. Hace tiempo mire el tema y llegue a la conclusión de que solo se podia hacer si disponias de un numero de telefono, aunque ví que desde el pc se podia hacer una simulación, pero era un tema muy complicado. La verdad es que si se consigue desde cualquier sistema operativo sería un gran logro.

http://www.adslzone.net/article7030-whatsapp-en-el-pc--envia-sms-desde-tu-ordenador.html
Saludos

Andrés González desde Mallorca
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

Andres,

Me refiero a hacerlo desde nuestras aplicaciones, corran en Windows, OSX, Linux, etc. :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
lucasdebeltran
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am
Contact:

Re: Enviando mensajes de WhatsApp

Post by lucasdebeltran »

Antonio,

Excelente!!.

Nuestros clientes lo piden mucho, yo pensé que no era posible...
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

Code: Select all | Expand

#include "FiveWin.ch"#include "hbsocket.ch"function Main()   local oWA := HB_WhatsApp():New()   ? oWA:Connect()   oWA:Login()return nilCLASS HB_WhatsApp   DATA  pSocket   DATA  cHost  INIT "bin-short.whatsapp.net"   DATA  nPort  INIT 5222   DATA  cIP   DATA  aResArray   DATA  cMsg   DATA  _Incomplete_message   METHOD New()   METHOD Connect()   METHOD Login()   METHOD _Identify( cStr )   METHOD _Is_Full_Msg( cStr )   DESTRUCTOR Destroy()ENDCLASSMETHOD New() CLASS HB_WhatsApp   ::cIP = hb_socketGetHosts( ::cHost )[ 1 ]   ::pSocket = hb_socketOpen()return selfMETHOD Connect() CLASS HB_WhatsAppreturn hb_socketConnect( ::pSocket, { HB_SOCKET_AF_INET, ::cIP, ::nPort } )METHOD Login() CLASS HB_WhatsApp   local cBuffer := Space( 1024 ), nLen, cV, cRcvdType   ? hb_socketSend( ::pSocket, "WA" + Chr( 0x01 ) + Chr( 0 ) + Chr( 0 ) + ;                  Chr( 0x19 ) + Chr( 0xF8 ) + Chr( 0x05 ) + Chr( 0x01 ) + ;                  Chr( 0xA0 ) + Chr( 0x8A ) + Chr( 0x84 ) + Chr( 0xFC ) + ;                  Chr( 0x11 ) + "iPhone-2.6.9-5222" + ;                  Chr( 0 ) + Chr( 0x08 ) + Chr( 0xF8 ) + Chr( 0x02 ) + ;                  Chr( 0x96 ) + Chr( 0xF8 ) + Chr( 0x01 ) + Chr( 0xF8 ) + ;                  Chr( 0x01 ) + Chr( 0x7E ) + Chr( 0 ) + Chr( 0x07 ) + Chr( 0xF8 ) + ;                  Chr( 0x05 ) + Chr( 0x0F ) + Chr( 0x5A ) + Chr( 0x2A ) + ;                  Chr( 0xBD ) + Chr( 0xA7 ) )   ? nLen := hb_socketRecv( ::pSocket, @cBuffer )   cBuffer = SubStr( cBuffer, 1, nLen )   ::aResArray = HB_ATokens( cBuffer, Chr( 0 ) )   for each cV in ::aResArray       cRcvdType = ::_Identify( cV )       ? cRcvdType      do case         case cRcvdType == "incomplete_msg"              ::_incomplete_message = cV         case cRcvdType == "msg"              ::cMsg = ::parse_received_message( cV )                  case cRcvdType == "account_info"              ::accinfo = ::parse_account_info( cV )         case cRcvdType == "last_seen"              ::lastseen = ::parse_last_seen( cV )      endcase   nextreturn nilstatic function StartsWith( cStr, cCompare, nPos )return SubStr( cStr, nPos, Len( cCompare ) ) == cComparestatic function EndsWith( cStr, cCompare )return Right( cStr, Len( cCompare ) ) == cCompareMETHOD _Identify( cStr ) CLASS HB_WhatsApp   local cMsg_identifier := Chr( 0x5D ) + Chr( 0x38 ) + Chr( 0xFA ) + Chr( 0xFC )    local cServer_delivery_identifier := Chr( 0x8C )    local cClient_delivery_identifier := Chr( 0x7F ) + Chr( 0xBD ) + Chr( 0xAD )   local cAcc_info_iden := Chr( 0x99 ) + Chr( 0xBD ) + Chr( 0xA7 ) + Chr( 0x94 )       local cLast_seen_ident := Chr( 0x48 ) + Chr( 0x38 ) + Chr( 0xFA ) + Chr( 0xFC )   local cLast_seen_ident2 := Chr( 0x7B ) + Chr( 0xBD ) + Chr( 0x4C ) + Chr( 0x8B )   if ! ::_is_full_msg( cStr )      return "incomplete_msg"   elseif StartsWith( cStr, cMsg_identifier, 3 )      if EndsWith( cStr, cServer_delivery_identifier )         return "server_delivery_report"      elseif EndsWith( cStr, cClient_delivery_identifier )          return "client_delivery_report"      else         return "msg"      endif    elseif StartsWith( cStr, cAcc_info_iden, 3 )      return "account_info"   elseif StartsWith( cStr, cLast_seen_ident, 3 ) .and. cLast_seen_ident2 $ cStr      return "last_seen"      else      return "other"   endifreturn nilMETHOD _Is_Full_Msg( cStr ) CLASS HB_WhatsAppreturn Len( cStr ) == Asc( Left( cStr, 1 ) ) + 1METHOD Destroy() CLASS HB_WhatsApp   HB_SocketShutDown( ::pSocket )   HB_SocketClose( ::pSocket )   ::pSocket = nilreturn nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
lucasdebeltran
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am
Contact:

Re: Enviando mensajes de WhatsApp

Post by lucasdebeltran »

Antonio,

Me dice que incomplete message :(
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
pablovidal
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana
Contact:

Re: Enviando mensajes de WhatsApp

Post by pablovidal »

Hola Antonio,

Donde hay referencia a las funciones de socket que usas ???
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

regards, saludos

Antonio Linares
www.fivetechsoft.com
horacio
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Enviando mensajes de WhatsApp

Post by horacio »

Al compilar el ejemplo me tira este error

Code: Select all | Expand

Error: Unresolved external 'WSAIoctl' referenced from C:\HARBOUR_BCC582\LIB\HBRTL.LIB|hbsocket 

Faltará alguna librería ?
Saludos
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

c:\bcc582\Lib\ws2_32.lib
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
pablovidal
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana
Contact:

Re: Enviando mensajes de WhatsApp

Post by pablovidal »

Antonio, Se podra usar esto sin necesidad de un SmartPhone ???
O hay alguna pagina web donde este disponble este codigo funcionando ???
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

Pablo,

Creo que si, porque lo único que necesita del smartphone es su iMei.

https://github.com/aesedepece/WhatsAPI
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42847
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: Enviando mensajes de WhatsApp

Post by Antonio Linares »

Versión mejorada, ya recibimos algo entendible! :-)

Code: Select all | Expand

#include "FiveWin.ch"#include "hbsocket.ch"function Main()   local oWA := HB_WhatsApp():New()   ? oWA:Connect()   oWA:Login()return nilCLASS HB_WhatsApp   DATA  pSocket   DATA  cHost  INIT "bin-short.whatsapp.net"   DATA  nPort  INIT 5222   DATA  cIP   DATA  aResArray   DATA  cMsg   DATA  _Incomplete_message   METHOD New()   METHOD Connect()   METHOD Login()      METHOD Read()   METHOD Send( cData )   METHOD _Identify( cStr )   METHOD _Is_Full_Msg( cStr )   DESTRUCTOR Destroy()ENDCLASSMETHOD New() CLASS HB_WhatsApp   ::cIP = hb_socketGetHosts( ::cHost )[ 1 ]   ::pSocket = hb_socketOpen()return selfMETHOD Connect() CLASS HB_WhatsAppreturn hb_socketConnect( ::pSocket, { HB_SOCKET_AF_INET, ::cIP, ::nPort } )static function StrToHex( cStr )   local n, cHex := ""       for n = 1 to Len( cStr )      cHex += "0x" + NumToHex( Asc( SubStr( cStr, n, 1 ) ) )      if n < Len( cStr )         cHex += ", "      endif      next   return cHex         METHOD Login() CLASS HB_WhatsApp   local cBuffer, cResponse   ? ::Send( "WA" + Chr( 0x01 ) + Chr( 0 ) + Chr( 0 ) + ;             Chr( 0x19 ) + Chr( 0xF8 ) + Chr( 0x05 ) + Chr( 0x01 ) + ;             Chr( 0xA0 ) + Chr( 0x8A ) + Chr( 0x84 ) + Chr( 0xFC ) + ;             Chr( 0x11 ) + "iPhone-2.6.9-5222" + ;             Chr( 0 ) + Chr( 0x08 ) + Chr( 0xF8 ) + Chr( 0x02 ) + ;             Chr( 0x96 ) + Chr( 0xF8 ) + Chr( 0x01 ) + Chr( 0xF8 ) + ;             Chr( 0x01 ) + Chr( 0x7E ) + Chr( 0 ) + Chr( 0x07 ) + Chr( 0xF8 ) + ;             Chr( 0x05 ) + Chr( 0x0F ) + Chr( 0x5A ) + Chr( 0x2A ) + ;             Chr( 0xBD ) + Chr( 0xA7 ) )   cBuffer = ::Read()   cResponse = hb_base64decode( SubStr( cBuffer, 27 ) )   ? cResponsereturn nilMETHOD Read() CLASS HB_WhatsApp   local cBuffer := Space( 1024 ), cV, cRcvdType   local nLen := hb_socketRecv( ::pSocket, @cBuffer )   cBuffer = SubStr( cBuffer, 1, nLen )   ::aResArray = HB_ATokens( cBuffer, Chr( 0 ) )   // ? StrToHex( cBuffer )      for each cV in ::aResArray       cRcvdType = ::_Identify( cV )       // ? cRcvdType      // ? StrToHex( cV )      do case         case cRcvdType == "incomplete_msg"              ::_incomplete_message = cV         case cRcvdType == "msg"              ::cMsg = ::parse_received_message( cV )                  case cRcvdType == "account_info"              ::accinfo = ::parse_account_info( cV )         case cRcvdType == "last_seen"              ::lastseen = ::parse_last_seen( cV )      endcase   nextreturn cBufferMETHOD Send( cData ) CLASS HB_WhatsAppreturn hb_socketSend( ::pSocket, cData )static function StartsWith( cStr, cCompare, nPos )return SubStr( cStr, nPos, Len( cCompare ) ) == cComparestatic function EndsWith( cStr, cCompare )return Right( cStr, Len( cCompare ) ) == cCompareMETHOD _Identify( cStr ) CLASS HB_WhatsApp   local cMsg_identifier := Chr( 0x5D ) + Chr( 0x38 ) + Chr( 0xFA ) + Chr( 0xFC )    local cServer_delivery_identifier := Chr( 0x8C )    local cClient_delivery_identifier := Chr( 0x7F ) + Chr( 0xBD ) + Chr( 0xAD )   local cAcc_info_iden := Chr( 0x99 ) + Chr( 0xBD ) + Chr( 0xA7 ) + Chr( 0x94 )       local cLast_seen_ident := Chr( 0x48 ) + Chr( 0x38 ) + Chr( 0xFA ) + Chr( 0xFC )   local cLast_seen_ident2 := Chr( 0x7B ) + Chr( 0xBD ) + Chr( 0x4C ) + Chr( 0x8B )   if ! ::_is_full_msg( cStr )      return "incomplete_msg"   elseif StartsWith( cStr, cMsg_identifier, 3 )      if EndsWith( cStr, cServer_delivery_identifier )         return "server_delivery_report"      elseif EndsWith( cStr, cClient_delivery_identifier )          return "client_delivery_report"      else         return "msg"      endif    elseif StartsWith( cStr, cAcc_info_iden, 3 )      return "account_info"   elseif StartsWith( cStr, cLast_seen_ident, 3 ) .and. cLast_seen_ident2 $ cStr      return "last_seen"      else      return "other"   endifreturn nilMETHOD _Is_Full_Msg( cStr ) CLASS HB_WhatsAppreturn Len( cStr ) == Asc( Left( cStr, 1 ) ) + 1METHOD Destroy() CLASS HB_WhatsApp   HB_SocketShutDown( ::pSocket )   HB_SocketClose( ::pSocket )   ::pSocket = nilreturn nil 


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Andrés González
Posts: 630
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca
Been thanked: 1 time

Re: Enviando mensajes de WhatsApp

Post by Andrés González »

Antonio, sinceramente... impresionante. A pesar de que ya había oído en el grado de multimedia que ya habia gente que lo empleaba mediante php, nunca pude imaginar que estubiera al alcance de todos. Email, sms y ahora whatsapp pondran la guinda a nuestros programas... Ahora solo faltará que empecemos a aplicar criterios de usabilidad cambiando la interficie para poderlos hacer mas amigables con nuestros sentidos y salgamos del yugo del mouse. Android y otros ya han sentado las bases y creo que nosotros tenemos que imponer esta nueva usabilidad para nuestra programación en los nuevos dispositivos.
Saludos

Andrés González desde Mallorca
Post Reply