@@ -36,25 +36,25 @@ class Snapchat extends SnapchatAgent {
3636 /**
3737 * Snap statuses.
3838 */
39- const STATUS_NONE = -1 ;
40- const STATUS_SENT = 0 ;
41- const STATUS_DELIVERED = 1 ;
42- const STATUS_OPENED = 2 ;
39+ const STATUS_NONE = -1 ;
40+ const STATUS_SENT = 0 ;
41+ const STATUS_DELIVERED = 1 ;
42+ const STATUS_OPENED = 2 ;
4343 const STATUS_SCREENSHOT = 3 ;
4444
4545 /**
4646 * Friend statuses.
4747 */
48- const FRIEND_CONFIRMED = 0 ;
49- const FRIEND_UNCONFIRMED = 1 ;
50- const FRIEND_BLOCKED = 2 ;
51- const FRIEND_DELETED = 3 ;
48+ const FRIEND_CONFIRMED = 0 ;
49+ const FRIEND_UNCONFIRMED = 1 ;
50+ const FRIEND_BLOCKED = 2 ;
51+ const FRIEND_DELETED = 3 ;
5252
5353 /**
5454 * Privacy settings.
5555 */
56- const PRIVACY_EVERYONE = 0 ;
57- const PRIVACY_FRIENDS = 1 ;
56+ const PRIVACY_EVERYONE = 0 ;
57+ const PRIVACY_FRIENDS = 1 ;
5858
5959 const DATA_FOLDER = 'authData ' ;
6060
@@ -467,7 +467,7 @@ public function login($password, $force = FALSE)
467467 return $ auth ;
468468 }
469469 parent ::setGAuth ($ auth );
470- $ attestation = $ this ->getAttestation ($ password , $ timestamp );
470+ $ attestation = $ this ->getAttestation ($ password , $ timestamp );
471471 $ clientAuthToken = $ this ->getClientAuthToken ($ this ->username , $ password , $ timestamp );
472472
473473 $ result = parent ::post (
@@ -846,21 +846,21 @@ public function getConversationAuth($to)
846846 return $ result ;
847847 }
848848
849-
850- public function getConversationInfo ( $ tos ) {
851- if (!is_array ($ tos )) $ tos = array ($ tos );
849+ public function getConversationInfo ( $ tos )
850+ {
851+ if (!is_array ($ tos )) $ tos = array ($ tos );
852852 $ messagesArray = array ();
853853 $ authArray = array ();
854- foreach ($ tos as $ to ){
855- $ authInfo = $ this ->getConversationAuth ($ to );
856- //if user is even a friend
857- if (!property_exists ($ authInfo ["data " ], "messaging_auth " )) continue ;
858- $ authArray [$ to ] = $ authInfo ['data ' ];
859- $ payload = $ authInfo ["data " ]->messaging_auth ->payload ;
860- $ mac = $ authInfo ["data " ]->messaging_auth ->mac ;
861- $ genID = md5 (uniqid ());
862- $ id = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
863- $ messagesArray [] = array (
854+ foreach ($ tos as $ to ){
855+ $ authInfo = $ this ->getConversationAuth ($ to );
856+ //if user is even a friend
857+ if (!property_exists ($ authInfo ["data " ], "messaging_auth " )) continue ;
858+ $ authArray [$ to ] = $ authInfo ['data ' ];
859+ $ payload = $ authInfo ["data " ]->messaging_auth ->payload ;
860+ $ mac = $ authInfo ["data " ]->messaging_auth ->mac ;
861+ $ genID = md5 (uniqid ());
862+ $ id = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
863+ $ messagesArray [] = array (
864864 "presences " => array (
865865 $ this ->username => true ,
866866 $ to => false
@@ -907,83 +907,84 @@ public function getConversationInfo($tos){
907907 "type " => "presence "
908908 );
909909 }
910- $ messages = json_encode ($ messagesArray );
911- $ timestamp = parent ::timestamp ();
912- $ result = parent ::post (
913- '/loq/conversation_post_messages ' ,
914- array (
915- 'auth_token ' => $ this ->auth_token ,
916- 'messages ' => $ messages ,
917- 'timestamp ' => $ timestamp ,
918- 'username ' => $ this ->username ,
919- ),
920- array (
921- $ this ->auth_token ,
922- $ timestamp ,
923- ),
924- $ multipart = false ,
925- $ debug = $ this ->debug
926- );
927- $ resultsf = array ();
928- foreach ($ result ['data ' ]->conversations as $ convo ){
929- $ split = explode ("~ " , $ convo ->id );
930- $ un = (strtolower ($ split [0 ]) != strtolower ($ this ->username )) ? $ split [0 ] : $ split [1 ];
931- $ resultsf [$ un ] = $ convo ;
932- }
910+ $ messages = json_encode ($ messagesArray );
911+ $ timestamp = parent ::timestamp ();
912+ $ result = parent ::post (
913+ '/loq/conversation_post_messages ' ,
914+ array (
915+ 'auth_token ' => $ this ->auth_token ,
916+ 'messages ' => $ messages ,
917+ 'timestamp ' => $ timestamp ,
918+ 'username ' => $ this ->username ,
919+ ),
920+ array (
921+ $ this ->auth_token ,
922+ $ timestamp ,
923+ ),
924+ $ multipart = false ,
925+ $ debug = $ this ->debug
926+ );
927+ $ resultsf = array ();
928+ foreach ($ result ['data ' ]->conversations as $ convo ){
929+ $ split = explode ("~ " , $ convo ->id );
930+ $ un = (strtolower ($ split [0 ]) != strtolower ($ this ->username )) ? $ split [0 ] : $ split [1 ];
931+ $ resultsf [$ un ] = $ convo ;
932+ }
933933 return array ($ resultsf ,$ authArray );
934934 }
935935
936- public function sendMessage ($ tos , $ text ){
937- if (!is_array ($ tos )) $ tos = array ($ tos );
938- $ convoInfo = $ this ->getConversationInfo ($ tos );
939- $ messagesArray = array ();
940- foreach ($ tos as $ to ){
941- if (!array_key_exists ($ to , $ convoInfo [1 ])){ //check if user can be sent a message
942- echo "\nYou have to add {$ to } as a friend first! " ;
943- continue ;
944- }
945- if (!array_key_exists ($ to , $ convoInfo [0 ])){ //new convo
946- $ payload = $ convoInfo [1 ][$ to ]->messaging_auth ->payload ;
947- $ mac = $ convoInfo [1 ][$ to ]->messaging_auth ->mac ;
948- $ seq_num = 0 ;
949- $ conv_id = implode ('~ ' , array ($ to , $ this ->username ));
950- }else { //conversation already exists
951- $ payload = $ convoInfo [0 ][$ to ]->conversation_messages ->messaging_auth ->payload ;
952- $ mac = $ convoInfo [0 ][$ to ]->conversation_messages ->messaging_auth ->mac ;
953- $ name = $ this ->username ;
954- $ seq_num = $ convoInfo [0 ][$ to ]->conversation_state ->user_sequences ->$ name ;
955- $ conv_id = $ convoInfo [0 ][$ to ]->id ;
956- }
957- $ genID = md5 (uniqid ());
958- $ chatID = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
959- $ genID = md5 (uniqid ());
960- $ id = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
961- $ timestamp = parent ::timestamp ();
962- $ messagesArray [] =
963- array (
964- 'body ' => array (
965- 'text ' => $ text ,
966- 'type ' => 'text '
967- ),
968- 'chat_message_id ' => $ chatID ,
969- 'seq_num ' => $ seq_num + 1 ,
970- 'timestamp ' => $ timestamp ,
971- 'header ' => array (
972- 'auth ' => array (
973- 'mac ' => $ mac ,
974- 'payload ' => $ payload
975- ),
976- 'to ' => array ($ to ),
977- 'conv_id ' => $ conv_id ,
978- 'from ' => $ this ->username ,
979- 'conn_seq_num ' => 1
936+ public function sendMessage ($ tos , $ text )
937+ {
938+ if (!is_array ($ tos )) $ tos = array ($ tos );
939+ $ convoInfo = $ this ->getConversationInfo ($ tos );
940+ $ messagesArray = array ();
941+ foreach ($ tos as $ to ){
942+ if (!array_key_exists ($ to , $ convoInfo [1 ])){ //check if user can be sent a message
943+ echo "\nYou have to add {$ to } as a friend first! " ;
944+ continue ;
945+ }
946+ if (!array_key_exists ($ to , $ convoInfo [0 ])){ //new convo
947+ $ payload = $ convoInfo [1 ][$ to ]->messaging_auth ->payload ;
948+ $ mac = $ convoInfo [1 ][$ to ]->messaging_auth ->mac ;
949+ $ seq_num = 0 ;
950+ $ conv_id = implode ('~ ' , array ($ to , $ this ->username ));
951+ }else { //conversation already exists
952+ $ payload = $ convoInfo [0 ][$ to ]->conversation_messages ->messaging_auth ->payload ;
953+ $ mac = $ convoInfo [0 ][$ to ]->conversation_messages ->messaging_auth ->mac ;
954+ $ name = $ this ->username ;
955+ $ seq_num = $ convoInfo [0 ][$ to ]->conversation_state ->user_sequences ->$ name ;
956+ $ conv_id = $ convoInfo [0 ][$ to ]->id ;
957+ }
958+ $ genID = md5 (uniqid ());
959+ $ chatID = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
960+ $ genID = md5 (uniqid ());
961+ $ id = strtoupper (sprintf ('%08s-%04s-%04x-%04x-%12s ' , substr ($ genID , 0 , 8 ), substr ($ genID , 8 , 4 ), substr ($ genID , 12 , 4 ), substr ($ genID , 16 , 4 ), substr ($ genID , 20 , 12 )));
962+ $ timestamp = parent ::timestamp ();
963+ $ messagesArray [] =
964+ array (
965+ 'body ' => array (
966+ 'text ' => $ text ,
967+ 'type ' => 'text '
968+ ),
969+ 'chat_message_id ' => $ chatID ,
970+ 'seq_num ' => $ seq_num + 1 ,
971+ 'timestamp ' => $ timestamp ,
972+ 'header ' => array (
973+ 'auth ' => array (
974+ 'mac ' => $ mac ,
975+ 'payload ' => $ payload
980976 ),
981- 'retried ' => false ,
982- 'id ' => $ id ,
983- 'type ' => 'chat_message '
984- );
985- }
986- if (count ($ messagesArray ) <= 0 ) return null ;
977+ 'to ' => array ($ to ),
978+ 'conv_id ' => $ conv_id ,
979+ 'from ' => $ this ->username ,
980+ 'conn_seq_num ' => 1
981+ ),
982+ 'retried ' => false ,
983+ 'id ' => $ id ,
984+ 'type ' => 'chat_message '
985+ );
986+ }
987+ if (count ($ messagesArray ) <= 0 ) return null ;
987988 $ messages = json_encode ($ messagesArray );
988989 $ timestamp = parent ::timestamp ();
989990 $ result = parent ::post (
@@ -1243,10 +1244,13 @@ function getFriendStories($save = FALSE)
12431244 * An array of phone numbers.
12441245 * FORMATTING: array("name" => "number") !! VERY IMPORTANT !!
12451246 *
1247+ * @param string $country
1248+ * Country, i.e: US, ES, GE...
1249+ *
12461250 * @return mixed
12471251 * An array of user objects or FALSE on failure.
12481252 */
1249- public function findFriends ($ numbers )
1253+ public function findFriends ($ numbers, $ country )
12501254 {
12511255 $ updates = $ this ->getUpdates ();
12521256
@@ -1259,8 +1263,6 @@ public function findFriends($numbers)
12591263 if (!$ itsVerified )
12601264 {
12611265 $ batches = array_chunk (array_flip ($ numbers ), 30 , TRUE );
1262- $ country = $ updates ['data ' ]->updates_response ->country_code ;
1263-
12641266 // Make sure we're logged in and have a valid access token.
12651267 if (!$ this ->auth_token || !$ this ->username )
12661268 {
@@ -1295,7 +1297,7 @@ public function findFriends($numbers)
12951297 return $ results ;
12961298 }
12971299 else if ($ this ->debug )
1298- echo 'DEBUG: You need to verify your phone number ' ;
1300+ echo 'DEBUG: You need to verify your phone number ' ;
12991301 }
13001302
13011303 public function searchFriend ($ friend )
@@ -1506,7 +1508,8 @@ public function deleteFriends($usernames) {
15061508 ),
15071509 $ multipart = false ,
15081510 $ debug = $ this ->debug );
1509- return $ result ;
1511+
1512+ return $ result ;
15101513 }
15111514 /**
15121515 * Adds multiple friends.
0 commit comments