我已经构建了一个简单的环聊应用程序,当有人在我的网页上发起环聊时通知我——Google plus 之外。
我正处于调用服务器端脚本的阶段,该脚本通知我新用户已发起环聊,我需要将消息传递回环聊以向用户显示更新的提示。类似于以下内容 - 支持工程师已收到此环聊的提醒,并将很快与您联系。
我已经阅读了环聊数据,包括谁从环聊 api 加入,并将其传递给我的服务器端代码没有问题。但我不确定如何通过 ajax 请求将信息传递回我的环聊应用程序。
这是我使用 jQuery 的 ajax 请求。
var hangoutUrl = gapi.hangout.getHangoutUrl();
var personsInHangout = gapi.hangout.getParticipants();
var callbackUrl = 'http://styxofdynamite.bitnamiapp.com/notify.php?';
$.ajax({
url: callbackUrl,
dataType: 'text',
data: {
"personsInHangout" : personsInHangout,
"hangoutUrl" : hangoutUrl,
"topic" : params['gd'],
}
}).done( function(data, status, xhr){
//call was made process result
$('.msg').html(data.msg);
}).fail( function(xhr, status, error){
$('.msg').html("There was a problem contacting the server. (" + status + ")");
});
目前我没有返回任何东西,所以我很高兴达到.fail()
理想状态,我需要从 notify.php 返回一些东西到这个环聊应用程序。
服务器端片段:
$personsInHangout = $_GET['personsInHangout'];
$hangoutUrl = $_GET['hangoutUrl'];
$topic = $_GET['topic'];
$emailMessage = 'Hey Support Team, ';
for($i = 0, $size = count($personsInHangout); $i < $size; ++$i) {
$emailMessage .= $personsInHangout[$i]['person']['displayName'];
$emailMessage .= ' is currently waiting in the support ';
$emailMessage .= '<a href="'.$hangoutUrl.'">hangout</a>';
$emailMessage .= ' to discuss ' . $topic;
}
print $emailMessage;
$to = 'support@team.com';
$subject = 'New Hangout Request';
$headers = 'From: hangout.monitor@team.com' . "\r\n" .
'Reply-To: hangout.monitor@team.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $emailMessage, $headers);
//return something to say that a support engineer has been notified.