I use yahoo messenger api for sending bulk chat messages to different groups(which is define by us for different package users ) but after some time JYMSG API automatically sign off How can we stay sign in?
<?php
error_reporting(0);
include("includes/dbconn.php");
function sendreq($mid)
{
$sql = mysql_query("select * from cv_requests where medium = 'yahoo' and medium_id = '".$mid."'");
if(mysql_num_rows($sql) > 0)
{
return 'already available';
}
else
{
mysql_query("insert into cv_requests (medium, medium_id) values ('yahoo', '".$mid."')");
return 'not available';
}
}
/*
*
*Software Copyright License Agreement (BSD License)
*
*Copyright (c) 2010, Yahoo! Inc.
*All rights reserved.
*
*Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
** Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
** Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
** Neither the name of Yahoo! Inc. nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission of Yahoo! Inc.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
$sqlytalk = mysql_query("select * from cv_yahoo");
$rowy = mysql_fetch_array($sqlytalk);
define('USERNAME', $rowy['username']);
define('PASSWORD', $rowy['password']);
define('CONSUMER_KEY', $rowy['cons_key']);
define('SECRET_KEY', $rowy['sec_key']);
include_once 'jymengine.class.php';
$engine = new JYMEngine(CONSUMER_KEY, SECRET_KEY, USERNAME, PASSWORD);
$engine->debug = true;
if ($engine->debug) echo '> Fetching request token'. PHP_EOL;
if (!$engine->fetch_request_token()) die('Fetching request token failed');
if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
if (!$engine->fetch_access_token()) die('Fetching access token failed');
if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
if (!$engine->signon('CapitalVia Logged In')) die('Signon failed first');
$seq = -1;
while (true)
{
$resp = $engine->fetch_long_notification($seq+1);
if ($resp === 'error')
{
if ($engine->get_error() != -10)
{
if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
if (!$engine->fetch_access_token()) die('Fetching access token failed');
if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
if (!$engine->signon('CapitalVia Logged In')) die('Signon failed loop');
$seq = -1;
}
// Add customers
$sqlgetcustomers = mysql_query("select distinct cs.yahoo from cv_customers as cs, cv_requests as rq where cs.yahoo != '' and cs.yahoo != rq.medium_id");
if(mysql_num_rows($sqlgetcustomers) > 0 )
{
while($rowcust = mysql_fetch_array($sqlgetcustomers))
{
$arrmediumcust = explode("@",$rowcust['yahoo']);
if(is_array($arrmediumcust))
{
$rowcust['yahoo'] = $arrmediumcust[0];
}
if(sendreq($rowcust['yahoo']) == 'not available')
{
$engine->add_contact($rowcust['yahoo']);
}
}
}
// Send message and signout
$sqlytalk = mysql_query("select * from cv_yahoo");
$rowy = mysql_fetch_array($sqlytalk);
if($rowy['isstart'] == '0')
{
$engine->signoff();
die();
}
$sqlcontinue = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");
if(mysql_num_rows($sqlcontinue) < 1)
{
continue;
}
$sql = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");
if(mysql_num_rows($sql) > 0)
{
while($rowsql = mysql_fetch_array($sql))
{
$arrmedium = explode("@",$rowsql['medium_id']);
if(is_array($arrmedium))
{
$rowsql['medium_id'] = $arrmedium[0];
}
if(sendreq($rowsql['medium_id']) == 'not available')
{
$engine->add_contact($rowsql['medium_id']);
}
$engine->send_message($rowsql['medium_id'], json_encode($rowsql['message']));
mysql_query("update cv_messages set issent = 1 where id = ".$rowsql['id']);
}
}
continue;
}
else
{
$response_array = $resp;
foreach($response_array as $resrow)
{
foreach($resrow as $key=>$val)
{
if ($val['sequence'] > $seq) $seq = intval($val['sequence']);
/*
* do actions
*/
if ($key == 'buddyInfo') //contact list
{
if (!isset($val['contact'])) continue;
if ($engine->debug) echo PHP_EOL. 'Contact list: '. PHP_EOL;
foreach ($val['contact'] as $item)
{
if ($engine->debug) echo $item['sender']. PHP_EOL;
}
if ($engine->debug) echo '----------'. PHP_EOL;
}
if ($key == 'message') //incoming message
{
if ($engine->debug) echo '+ Incoming message from: "'. $val['sender']. '" on "'. date('H:i:s', $val['timeStamp']). '"'. PHP_EOL;
if ($engine->debug) echo ' '. $val['msg']. PHP_EOL;
if ($engine->debug) echo '----------'. PHP_EOL;
//reply
$words = explode(' ', trim(strtolower($val['msg'])));
if ($words[0] == 'yahoobotbandhoja123')
{
$engine->send_message($val['sender'], json_encode("Good Bye - CapitalVia"));
$engine->signoff();
die();
}
}
else if ($key == 'buddyAuthorize') //incoming contact request
{
if ($engine->debug) echo PHP_EOL. 'Accept buddy request from: '. $val['sender']. PHP_EOL;
if ($engine->debug) echo '----------'. PHP_EOL;
if (!$engine->response_contact($val['sender'], true, 'Welcome to CapitalVia Yahoo'))
{
$engine->delete_contact($val['sender']);
$engine->response_contact($val['sender'], true, 'Welcome to CapitalVia Yahoo');
}
}
}
}
// Add customers
$sqlgetcustomers = mysql_query("select distinct cs.yahoo from cv_customers as cs, cv_requests as rq where cs.yahoo != '' and cs.yahoo != rq.medium_id");
if(mysql_num_rows($sqlgetcustomers) > 0 )
{
while($rowcust = mysql_fetch_array($sqlgetcustomers))
{
$arrmediumcust = explode("@",$rowcust['yahoo']);
if(is_array($arrmediumcust))
{
$rowcust['yahoo'] = $arrmediumcust[0];
}
if(sendreq($rowcust['yahoo']) == 'not available')
{
$engine->add_contact($rowcust['yahoo']);
}
}
}
// Send message and signout
$sqlytalk = mysql_query("select * from cv_yahoo");
$rowy = mysql_fetch_array($sqlytalk);
if($rowy['isstart'] == '0')
{
$engine->signoff();
die();
}
$sqlcontinue = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");
if(mysql_num_rows($sqlcontinue) < 1)
{
continue;
}
$sql = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");
if(mysql_num_rows($sql) > 0)
{
while($rowsql = mysql_fetch_array($sql))
{
$arrmedium = explode("@",$rowsql['medium_id']);
if(is_array($arrmedium))
{
$rowsql['medium_id'] = $arrmedium[0];
}
if(sendreq($rowsql['medium_id']) == 'not available')
{
$engine->add_contact($rowsql['medium_id']);
}
$engine->send_message($rowsql['medium_id'], json_encode($rowsql['message']));
mysql_query("update cv_messages set issent = 1 where id = ".$rowsql['id']);
}
}
continue;
}
continue;
}
?>