2 Star 3 Fork 1

R./wechat_tencent_vod

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
chat_json.php 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
R. 提交于 2017-01-06 10:45 . 更新 chat_json.php
<?php
header('Content-type:text/json'); //这句是重点,它告诉接收数据的对象此页面输出的是json数据;
$chat_id=$_GET['chat_id'];
$vod_id=$_GET['vod_id'];
include 'db.php';/*连接数据库*/
//统计有多少个新聊天数据
$chat_number_tj=0;
$result = mysql_query("SELECT * FROM vod_chat");
while($row = mysql_fetch_array($result))
{
if ($row['id']>$chat_id){
$chat_number_tj=$chat_number_tj+1;
}
}
//生成JSON数据
$chat_number=0;
$result = mysql_query("SELECT * FROM vod_chat");
while($row = mysql_fetch_array($result))
{
if ($row['id']>$chat_id){
$chat_number=$chat_number+1;
if ($chat_number_tj==1){
$chat_json=$chat_json."{'chat_content':[{'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}]}],";
}else{
if ($chat_number==1){
$chat_json=$chat_json."{'chat_content':[{'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}],";
}
if ($chat_number!=1 and $chat_number!=$chat_number_tj){
$chat_json=$chat_json."'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}],";
}
if ($chat_number==$chat_number_tj){
$chat_json=$chat_json."'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}]}],";
}
}
}
}
$result = mysql_query("SELECT * FROM vod_project where id=".$vod_id);
while($row = mysql_fetch_array($result))
{
$chat_json=$chat_json."'user_number':'".$row['number']."'}";
}
//返回值
$callback = $_GET['callback'];
echo "{$callback}(".$chat_json.")";
exit();
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/robinchina/wechat_tencent_vod.git
git@gitee.com:robinchina/wechat_tencent_vod.git
robinchina
wechat_tencent_vod
wechat_tencent_vod
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385