@@ -364,12 +364,16 @@ public function logout()
364364 * The email address to associate with the account.
365365 * @param $birthday string
366366 * The user's birthday (yyyy-mm-dd).
367+ * @param string $phone_verification
368+ * Whether to use phone verification or not.
369+ * @param string $phone_number
370+ * Phone number to use if using phone verification.
367371 *
368372 * @return mixed
369373 * The data returned by the service or FALSE if registration failed.
370374 * Generally, returns the same result as calling self::getUpdates().
371375 */
372- public function register ($ username , $ password , $ email , $ birthday )
376+ public function register ($ username , $ password , $ email , $ birthday, $ phone_verification = FALSE , $ phone_number = NULL )
373377 {
374378 $ timestamp = parent ::timestamp ();
375379 $ result = parent ::post (
@@ -388,21 +392,22 @@ public function register($username, $password, $email, $birthday)
388392 $ debug = $ this ->debug
389393 );
390394
391- if (!isset ($ result-> token ))
395+ if (!isset ($ result[ " data " ]-> auth_token ))
392396 {
393397 return FALSE ;
394398 }
399+ $ this ->auth_token = $ result ['data ' ]->auth_token ;
395400
396401 $ timestamp = parent ::timestamp ();
397402 $ result = parent ::post (
398403 '/loq/register_username ' ,
399404 array (
400- 'email ' => $ email ,
401- 'username ' => $ username ,
405+ 'username ' => $ email ,
406+ 'selected_username ' => $ username ,
402407 'timestamp ' => $ timestamp ,
403408 ),
404409 array (
405- parent :: STATIC_TOKEN ,
410+ $ this -> auth_token ,
406411 $ timestamp ,
407412 ),
408413 $ multipart = false ,
@@ -418,6 +423,21 @@ public function register($username, $password, $email, $birthday)
418423 $ this ->cache = new SnapchatCache ();
419424 $ this ->cache ->set ('updates ' , $ result );
420425
426+ if ($ phone_verification )
427+ {
428+ if (!is_null ($ phone_number ))
429+ {
430+ $ this ->sendPhoneVerification ($ phone_number );
431+ //TODO
432+ //run /bq/phone_verify with proper parameters: req_token, timestamp, action = verifyPhoneNumber, username, code = verification code
433+ }
434+ else
435+ {
436+ echo "\nYou must provide a phone number to verify with. " ;
437+ return FALSE ;
438+ }
439+ }
440+
421441 return $ result ;
422442 }
423443 else
@@ -426,6 +446,57 @@ public function register($username, $password, $email, $birthday)
426446 }
427447 }
428448
449+
450+ /**
451+ * Sends SMS verification.
452+ *
453+ * @param string $phone_number
454+ * Phone number to use if using phone verification.
455+ *
456+ * @return mixed
457+ * The data returned by the service or FALSE if registration failed.
458+ * Generally, returns the same result as calling self::getUpdates().
459+ */
460+ public function sendPhoneVerification ($ phone_number )
461+ {
462+ $ regex = "/ \\+?(9[976] \\d|8[987530] \\d|6[987] \\d|5[90] \\d|42 \\d|3[875] \\d|2[98654321] \\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)( \\d{1,14}$)/ " ;
463+ preg_match ($ regex , $ phone_number , $ matches );
464+ $ countryCode = $ matches [1 ];
465+
466+ $ url = "http://restcountries.eu/rest/v1/callingcode/ {$ countryCode }" ;
467+ if (substr (get_headers ($ url )[0 ], 9 , 3 ) == "200 " )
468+ {
469+ $ countryCodeArray = json_decode (file_get_contents ($ url ), true );
470+ $ countryAlpha2Code = $ countryCodeArray [0 ]["alpha2Code " ];
471+ $ phone_number = $ matches [2 ];
472+ }
473+ else
474+ {
475+ echo "\nInvalid country code: {$ countryCode }" ;
476+ return FALSE ;
477+ }
478+
479+ $ timestamp = parent ::timestamp ();
480+ $ result = parent ::post (
481+ "/bq/phone_verify " ,
482+ array (
483+ "timestamp " => $ timestamp ,
484+ "username " => $ this ->username ,
485+ "phoneNumber " => $ phone_number ,
486+ "action " => "updatePhoneNumber " ,
487+ "countryCode " => $ countryAlpha2Code ,
488+ "skipConfirmation " => true
489+ ),
490+ array (
491+ $ this ->auth_token ,
492+ $ timestamp ,
493+ )
494+ );
495+
496+ return is_null ($ result );
497+ }
498+
499+
429500 /**
430501 * Retrieves general user, friend, and snap updates.
431502 *
0 commit comments