WinFuture-Forum.de: Msn Nachricht über Php Verschicken... - WinFuture-Forum.de

Zum Inhalt wechseln

Nachrichten zum Thema: Entwicklung
Seite 1 von 1

Msn Nachricht über Php Verschicken... MSN Class vorhanden, aber funktioniert nicht so recht...


#1 Mitglied ist offline   HuMaN 

  • Gruppe: aktive Mitglieder
  • Beiträge: 208
  • Beigetreten: 01. Januar 05
  • Reputation: 0
  • Geschlecht:Männlich
  • Wohnort:Flensburg

geschrieben 06. Januar 2008 - 11:39

Hallo,

also ich besitze eine MSN Class die eigentlich hervorragend funktioniert, man kann damit die gesamte Kontaktliste auslesen und sogar Nachrichten kann man empfangen...

Soweit so gut, nun wollte ich eine weitere Funktion der Klasse nutzen nämlich das versenden von Nachrichten, dass will jedoch nicht so recht klappen, habe bereits alles versucht...

In der Anleitung ist die Rede davon, dass man den notification server connection richtig angeben muss und genau da muss auch der Fehler bei mir liegen, denn ehrlich gesagt weiß ich nicht wirklich was ich da hinschreiben soll...

Bin für jede Hilfe dankbar, ist echt dringend...

Die Fehlermeldung lautet

Zitat

Warning: fputs(): supplied argument is not a valid stream resource in /home/www/msn/msn_sb.class.php on line 51

Warning: fgets(): supplied argument is not a valid stream resource in /home/www/msn/msn_sb.class.php on line 54
unable to read NS info. last message:


Hier meine Datei:
<?php


	include('msnp9.class.php');
	include('msn_sb.class.php');

	$msn = new msn;

	if ($msn->connect('MSNUSERNAME', 'PASSWORT'))
	{
		// we're connected
		// run rx_data function to 'idle' on the network
		// rx_state will loop until the connection is dropped

$switchboard = new switchboard;
$ns='messenger.hotmail.com';
$switchboard->tx_im($ns, 'test', 'Mailaddi', 'Mailaddi');

		$msn->rx_data();

		echo '<p>Connection dropped</p>';
	}
	else
	{
		// wrong username and password?
		echo '<p>Error Connecting to the MSN Network</p>';
	}

?>



Und hier einmal die 2 Dateien der Class
<?php

class msn
{
	// messenger.hotmail.com is an exchange server
	// using it will redirect to a server with an open slot
	// using a known server ip will help connect faster

	// commenting out $ssh_login will mean the url to the
	// secure login server will be taken from a secure
	// session.  this will slow down connecting a bit.
	// Note: comment out $ssh_login if you experience auth failures

	var $server	=	'messenger.hotmail.com';
	var $port	=	1863;

	var $nexus	=	'https://nexus.passport.com/rdr/pprdr.asp';
	var $ssh_login	=	'login.live.com/login2.srf';

	var $debug	=	1;


	// curl is used for the secure login, if you don't have
	// the php_curl library installed, you can use a curl binary
	// instead. $use_curl needs to be set to 1 to enable this.
	// set $curl to the path where curl is installed.
	// curl can be downloaded here: [url="http://curl.haxx.se/download.html"]http://curl.haxx.se/download.html[/url]

	var $curl_bin	=	0;
	var $curl	=	'/usr/local/bin/curl';	// linux
	//var $curl	=	'c:\curl.exe';		// windows




	/**
	 *
	 * desc	:	Connect to MSN Messenger Network
	 *
	 * in	:	$passport	=	passport i.e: [email protected]
	 *		$password	=	password for passport
	 *
	 * out	:	true on success else return false
	 *
	 */

	function connect($passport, $password)
	{
		$this->trID = 1;

		if ($this->fp = @fsockopen($this->server, $this->port, $errno, $errstr, 2))
		{
			$this->_put("VER $this->trID MSNP9 CVR0\r\n");

			while (! feof($this->fp))
			{
				$data = $this->_get();

				switch ($code = substr($data, 0, 3))
				{
					default:
						echo $this->_get_error($code);

						return false;
					break;
					case 'VER':
						$this->_put("CVR $this->trID 0x0409 win 4.10 i386 MSNMSGR 7.0.0816 MSMSGS $passport\r\n");
					break;
					case 'CVR':
						$this->_put("USR $this->trID TWN I $passport\r\n");
					break;
					case 'XFR':
						list(, , , $ip)  = explode (' ', $data);
						list($ip, $port) = explode (':', $ip);

						if ($this->fp = @fsockopen($ip, $port, $errno, $errstr, 2))
						{
							$this->trID = 1;

							$this->_put("VER $this->trID MSNP9 CVR0\r\n");
						}
						else
						{
							if (! empty($this->debug)) echo 'Unable to connect to msn server (transfer)';

							return false;
						}
					break;
					case 'USR':
						if (isset($this->authed))
						{
							return true;
						}
						else
						{
							$this->passport = $passport;
							$this->password = urlencode($password);

							list(,,,, $code) = explode(' ', trim($data));

							if ($auth = $this->_ssl_auth($code))
							{
								$this->_put("USR $this->trID TWN S $auth\r\n");

								$this->authed = 1;
							}
							else
							{
								if (! empty($this->debug)) echo 'auth failed';

								return false;
							}
						}
					break;
				}
			}
		}
		else
		{
			if (! empty($this->debug)) echo 'Unable to connect to msn server';

			return false;
		}
	}


	function rx_data()
	{
		$this->_put("SYN $this->trID 0\r\n");
		$this->_put("CHG $this->trID NLN\r\n");

		while (! feof($this->fp))
		{
			$data = $this->_get();

			if ($data)
			{
				//echo $data.'<br />';

				switch($code = substr($data, 0, 3))
				{
					default:
						// uncommenting this line here would probably give a load of "error code not found" messages.
						//echo $this->_get_error($code);
					break;
					case 'CHL':
						$bits = explode (' ', trim($data));

						$return = md5($bits[2].'Q1P7W2E4J9R8U3S5');
						$this->_put("QRY $this->trID [email protected] 32\r\n$return");
					break;
					case 'RNG':
						// someone's trying to talk to us
						list(, $sid, $server, , $as, $email, $name) = explode(' ', $data);
						list($sb_ip, $sb_port) = explode(':', $server);


						$sbsess = new switchboard;

						if ($sbsess->auth($sb_ip, $sb_port, $this->passport, $sid, $as))
						{
							// sb session opened
							// recieve users message
							if ($msg = $sbsess->rx_im())
							{
								// send the message straight back!
								$sbsess->tx_im($this->fp, $msg, $this->passport, $email);

								// close IM sessions
								$sbsess->im_close();
							}
							else
							{
								echo 'No message was received from user.';
							}
						}
						else
						{
							echo 'Unable to authenticate with switchboard.';
						}
					break;
				}
			}
		}
	}


	/*====================================*\
		Various private functions
	\*====================================*/

	function _ssl_auth($auth_string)
	{
		if (empty($this->ssh_login))
		{
			if ($this->curl_bin)
			{
				exec("$this->curl -m 60 -LkI $this->nexus", $header);
				$header = implode($header, null);
			}
			else
			{
				$ch = curl_init($this->nexus);

				curl_setopt($ch, CURLOPT_HEADER, 1);
				curl_setopt($ch, CURLOPT_NOBODY, 1);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				// curl_setopt($ch, CURLOPT_TIMEOUT, 2);

				$header = curl_exec($ch);

				curl_close($ch);
			}

			preg_match ('/DALogin=(.*?),/', $header, $out);

			if (isset($out[1]))
			{
				$slogin = $out[1];
			}
			else
			{
				return false;
			}
		}
		else
		{
			$slogin = $this->ssh_login;
		}


		if ($this->curl_bin)
		{
			$header1 = '"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string.'"';

			exec("$this->curl -m 60 -LkI -H $header1 https://$slogin", $auth_string);

			$header = null;

			foreach ($auth_string as $key => $value)
			{
				if (strstr($value, 'Unauthorized'))
				{
					echo 'Unauthorised';
					return false;
				}
				elseif (strstr($value, 'Authentication-Info'))
				{
					$header = $value;
				}
			}
		}
		else
		{
			$ch = curl_init('https://'.$slogin);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array(
							'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string,
							'Host: login.passport.com'
							));

			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_NOBODY, 1);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			// curl_setopt($ch, CURLOPT_TIMEOUT, 2);

			$header = curl_exec($ch);

			curl_close($ch);
		}

		preg_match ("/from-PP='(.*?)'/", $header, $out);

		return (isset($out[1])) ? $out[1] : false;
	}


	function _get()
	{
		if ($data = @fgets($this->fp, 4096))
		{
			if ($this->debug) echo "<div class=\"r\">&lt;&lt;&lt; $data</div>\n";

			return $data;
		}
		else
		{
			return false;
		}
	}


	function _put($data)
	{
		fwrite($this->fp, $data);

		$this->trID++;

		if ($this->debug) echo "<div class=\"g\">&gt;&gt;&gt; $data</div>";
	}


	function _get_error($code)
	{
		switch ($code)
		{
			case 201:
				return 'Error: 201 Invalid parameter';
			break;
			case 217:
				return 'Error: 217 Principal not on-line';
			break;
			case 500:
				return 'Error: 500 Internal server error';
			break;
			case 540:
				return 'Error: 540 Challenge response failed';
			break;
			case 601:
				return 'Error: 601 Server is unavailable';
			break;
			case 710:
				return 'Error: 710 Bad CVR parameters sent';
			break;
			case 713:
				return 'Error: 713 Calling too rapidly';
			break;
			case 731:
				return 'Error: 731 Not expected';
			break;
			case 800:
				return 'Error: 800 Changing too rapidly';
			break;
			case 910:
			case 921:
				return 'Error: 910/921 Server too busy';
			break;
			case 911:
				return 'Error: 911 Authentication failed';
			break;
			case 923:
				return 'Error: 923 Kids Passport without parental consent';
			break;
			case 928:
				return 'Error: 928 Bad ticket';
			break;
			default:
				return 'Error code '.$code.' not found';
			break;
		}
	}

}


?>


<?php

class switchboard
{
	// font colours/styles
	var $font_fn = 'Arial';
	var $font_co = '333333';
	var $font_ef = '';


	// other
	var $debug = 1;
	var $trID = 1;
	var $email = '';


	function switchboard()
	{
		$this->session_start_time = time();
	}


	/**
	 *
	 * desc	:	send IM message
	 *
	 * in	:	$ns		=	notification server connection
	 *		$msg		=	message to send
	 *		$passport	=	current logged in user
	 *		$email		=	user to send message to
	 *
	 * out	:	true on success else return false
	 *
	 */

	function tx_im($ns, $msg, $passport, $email)
	{
		$message = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=$this->font_fn; EF=$this->font_ef; CO=$this->font_co; CS=0; PF=22\r\n\r\n$msg";
		$message = "MSG 20 N ".strlen($message)."\r\n$message";

		if (@is_resource($this->sb))
		{
			// switchboard session already open
			$this->_put($message);

			return true;
		}
		else
		{
			// open switchboard session through NS
			fputs($ns, "XFR $this->trID SB\r\n");


			$ns_data = fgets($ns, 4096);

			@list($xfr,,, $server,, $as) = explode(' ', $ns_data);

			if ($xfr != 'XFR')
			{
				echo 'unable to read NS info. last message: ';
				echo $ns_data;

				return false;
			}



			list($server, $port) = explode(':', $server);

			if ($this->sb = @fsockopen($server, $port, $errno, $errstr, 5))
			{
				$this->_put("USR $this->trID $passport $as\r\n");
				$this->_get();

				if (is_array($email))
				{
					foreach($email as $key => $value)
					{
						$this->_put("CAL $this->trID $value\r\n");

						if (strstr($this->_get(), 'CAL'))
						{
							$this->_get(); // should be JOI...
						}
					}
				}
				else
				{
					$this->_put("CAL $this->trID $email\r\n");

					if (strstr($this->_get(), 'CAL'))
					{
						$this->_get(); // should be JOI...
					}
				}



				$this->_put($message);

				return true;
			}
		}

		return false;
	}


	/**
	 *
	 * desc	:	recieve an IM from the switchboard
	 *
	 * in	:	none
	 * out	:	a. null on fail/no message
	 *		b. message string
	 *
	 */

	function rx_im()
	{
		$message = null;
		$msglen = null;

		stream_set_timeout($this->sb, 1);

		while (!feof($this->sb))
		{
			$data = ($msglen) ? $this->_get($msglen) : $this->_get();


			switch (substr($data, 0, 3))
			{
				default:
					//if (empty($msglen)) continue;

					$message.= $data;

					if (strlen($message) >= $msglen && !empty($msglen))
					{
						$mesg = explode("\n", trim($message));

						$last = end($mesg);


						//if (@substr($last, 0, 10) != 'TypingUser')
						if (!strstr($message, 'TypingUser'))
						{
							// this isn't a notification that the user is typing a message
							return $last;
						}


						$msglen = null;
						$message = null;
					}

					if ($this->session_start_time + 10 < time())
					{
						// looks like we've been idle for a while
						echo 'IM timed out';
						$this->im_close();
						return null;
					}
				break;
				case 'MSG':
					list(,,, $msglen) = explode (' ', $data);
				break;
				case 'BYE':
					return null;
				break;
			}
		}

		return null;
	}


	/**
	 *
	 * desc	:	authorise with switchboard from an IM invitation
	 *
	 * in	:	$server		=	switchboard server ip
	 *		$port		=	switchboard server port
	 *		$passport	=	logged in users passport email
	 *		$sID		=	session id
	 *		$as		=	auth string
	 *
	 * out	:	true on success else return false
	 *
	 */

	function auth($server, $port, $passport, $sID, $as)
	{
		if ($this->sb = @fsockopen($server, $port, $errno, $errstr, 5))
		{
			$this->_put("ANS $this->trID $passport $as $sID\r\n");

			if (!$this->rx_iro()) return false;

			return true;
		}

		return false;
	}


	/**
	 *
	 * desc	:	recieve IRO commands from IM session
	 *
	 * in	:	none
	 * out	:	true on success else return false
	 *
	 */

	function rx_iro()
	{
		if ($data = $this->_get())
		{
			@list($iro, , $cur_num, $tot, $email, $name) = explode(' ', $data);

			$sbsess->email = $email;

			if ($iro != 'IRO')
			{
				echo "** BAD data in rx_iro(): see line above **\n";
				return false;
			}

			// recieve names/list of others connected
			for ($i=1; $i<$tot; $i++)
			{
				if (!$data = $this->_get())
				{
					echo "** BAD data in rx_iro(): see line above **\n";
					return false;
				}

			}

			@list($ans) = explode(' ', $this->_get());

			if ($ans != 'ANS') return false;

			return true;
		}

		return false;
	}


	/**
	 *
	 * desc	:	close switchboard connection
	 *
	 * in	:	none
	 * out	:	none
	 *
	 */

	function im_close()
	{
		$this->_put("OUT\r\n");
		@fclose($this->sb);
	}


	/*====================================*\
		Various private functions
	\*====================================*/

	function _get($use_fread=0)
	{
		$data = ($use_fread) ? @fread($this->sb, $use_fread) : @fgets($this->sb, 4096);

		if ($data)
		{
			if ($this->debug) echo "<div class=\"r\">&lt;&lt;&lt; SB: $data</div>\n";
			return $data;
		}
		else
		{
			return false;
		}
	}

	function _put($data)
	{
		@fputs($this->sb, $data);
		$this->trID++;

		if ($this->debug) echo "<div class=\"g\">&gt;&gt;&gt; SB: $data</div>";
	}
}

?>


0

Anzeige



#2 Mitglied ist offline   HuMaN 

  • Gruppe: aktive Mitglieder
  • Beiträge: 208
  • Beigetreten: 01. Januar 05
  • Reputation: 0
  • Geschlecht:Männlich
  • Wohnort:Flensburg

geschrieben 28. April 2012 - 15:39

Bitte das "Thema" löschen, da private Daten wie eMail Adresse im Quellcode sind und ein bearbeiten des Beitrages nicht mehr möglich ist!
0

#3 Mitglied ist offline   nobody is perfect 

  • Gruppe: VIP Mitglieder
  • Beiträge: 5.899
  • Beigetreten: 13. Oktober 06
  • Reputation: 315
  • Geschlecht:Männlich
  • Wohnort:Köln

geschrieben 28. April 2012 - 15:44

Beitrag anzeigenZitat (HuMaN: 28. April 2012 - 15:39)

Bitte das "Thema" löschen, da private Daten wie eMail Adresse im Quellcode sind und ein bearbeiten des Beitrages nicht mehr möglich ist!

schreib einen Mod an,damit das hier gelöscht wird
0

#4 Mitglied ist offline   Urne 

  • Gruppe: Moderation
  • Beiträge: 18.082
  • Beigetreten: 12. Juni 05
  • Reputation: 394
  • Geschlecht:Männlich
  • Wohnort:BL
  • Interessen:Computer

geschrieben 28. April 2012 - 16:02

Falls da noch was privates drin steht, bitte PN.
Alkohol und Nikotin rafft die halbe Menschheit hin und nach alter Sitt und Brauch stirbt die andere Hälfte auch.
0

Thema verteilen:


Seite 1 von 1

1 Besucher lesen dieses Thema
Mitglieder: 0, Gäste: 1, unsichtbare Mitglieder: 0