最近由于工作生活的事情比较多,所以就没有更新,这篇是国外交友网站开发源码 第十二篇
希望大家能够喜欢。
如果有什么问题需要咨询的,可以加我的扣236-0248-666
私信列表
class WechatController extends SiteController {
public function __construct() {
parent::__construct ();
if(!$this->uinfo){
redirect(U("Public/index"));
exit;
}
$this->assign('nav', 'Wechat');
}
public function sixin(){//私信列表
$myuid = $this->uinfo["id"];
$user_count = M("User_count")->where("uid=".$myuid)->find();
$message = M("Message");
//->cache('ltlist',30)
/*$list= M()->table("(select * from __MESSAGE__ order by msgid desc) as tb")->field("msgid,content,fromuid,touid,isread,sendtime,hash,sum(if(isread=0,'1','0')) as count")->where("fromuid =".$myuid." or touid=".$myuid)->group("hash")->order('msgid desc')->select();*/
$where = "fromuid =".$myuid." or touid=".$myuid;
$count = $message ->where($where) -> count();
$Page = new \Think\Page($count, 15);
$show = $Page -> show();
//$list = $message->distinct(true)->field("hash")->where($where)->order('msgid desc')->limit($Page -> firstRow . ',' . $Page -> listRows)->select();
$list = $message->field("max(msgid)as mid,msgid,hash,fromuid,touid")->where($where)->group("hash")->order('mid desc')->limit($Page -> firstRow . ',' . $Page -> listRows)->select();
foreach($list as $key =>$val){
$arr[]=$val['fromuid'];
$arr[]=$val['touid'];
$arr2[]=$val["mid"];
}
$arr = array_unique($arr);
$arrstr = implode($arr,',');
$arrstr2 = implode($arr2,',');
if($arrstr)
$userarr = M("Users")->field("id,idmd5,avatar,user_nicename,user_rank")->where("id in (".$arrstr.")")->select();
if($arrstr2)
$list2 = $message->field("content,msgid,sendtime,is_zh,fromuid,touid,isread,type")->where("msgid in (".$arrstr2.")")->select();
foreach($userarr as $key =>$val){
unset($userarr[$key]);
$userarr[$val['id']]=$val;
}
foreach($list2 as $key =>$val){
unset($list2[$key]);
$list3[$val['msgid']]=$val;
}
foreach($list as $key =>$val){
$list[$key]['list2arr']=$list3[$val['mid']];
if($val['fromuid']==$myuid){
$list[$key]['avatar']=$userarr[$val['touid']]['avatar'];
$list[$key]['user_nicename']=$userarr[$val['touid']]['user_nicename'];
$list[$key]['user_rank']=$userarr[$val['touid']]['user_rank'];
$list[$key]['uid']=$userarr[$val['touid']]['idmd5'];
}else{
$list[$key]['avatar']=$userarr[$val['fromuid']]['avatar'];
$list[$key]['user_nicename']=$userarr[$val['fromuid']]['user_nicename'];
$list[$key]['user_rank']=$userarr[$val['fromuid']]['user_rank'];
$list[$key]['uid']=$userarr[$val['fromuid']]['idmd5'];
}
if($list[$key]['list2arr']['isread']==0 && $list[$key]['list2arr']['fromuid']!=$myuid){
$list[$key]['list2arr']['noread']=1;
}
if($list[$key]['list2arr']['is_zh']==1 && $list[$key]['list2arr']['fromuid']==$myuid){
unset($list[$key]);
}
}
$media=$this->getMedia('私信');
cookie('wdsxnum',0,3600);
$this->assign('media', $media);
$this->assign('list', $list);
$this->assign('nav2', 'sixin_a');
$this->assign('user_count', $user_count);
$this->assign ( 'page', $show );
if($_GET['p']>=200)exit;
if (I("get.ajax") == 1){
if($list) $data = $this->sitefetch('ajax_sixin_a');
$this->ajaxReturn($data);
}
$this->siteDisplay ( 'sixin_a' );
}
关注
public function subscribe(){//关注
$myuid = $this->uinfo["id"];
$usercountmod = M("User_count");
$user_count = $usercountmod->where("uid=".$myuid)->find();
$where ="touid=".$myuid;
$User = M("User_subscribe");
$count = $User -> where($where) -> count();
$Page = new \Think\Page($count, 15);
$show = $Page -> show();
$list = $User->alias('fs')->field("u.avatar,u.user_nicename,fs.time,u.user_rank,u.id,u.idmd5")->join("__USERS__ as u ON u.id=fs.fromuid")->where($where) -> order('fs.id desc') -> limit($Page -> firstRow . ',' . $Page -> listRows) -> select();
$this->assign('list', $list);
if($_GET['p']>=200)exit;
if (I("get.ajax") == 1){
if($list) $data = $this->sitefetch('ajax_sixin_b');
$this->ajaxReturn($data);
}else{
$User->where("touid=".$myuid)->setField("touser_isread",1);
$usercountmod->where("uid=".$myuid)->setField("wdgznum",0);
}
$this->assign('user_count', $user_count);
$media=$this->getMedia('关注');
cookie('wdsxnum',0,3600);
$this->assign('media', $media);
$this->assign('nav2', 'sixin_b');
$this->siteDisplay ( 'sixin_b' );
}
成为开发者token
class WeixinController extends BaseController
{
public function _initialize(){
header("Content-Type:text/html; charset=utf-8");
}
public function log(){
dump(S('log'));
}
public function index(){
define("TOKEN", C("wxtoken")?C("wxtoken"):"yueai8999");//成为开发者token
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
if($echoStr){
echo $echoStr;
exit;
}else{
$this->getmsg();
}
}
}
获取信息
public function getmsg(){
$ss=0;
if(C("other_url") && C("other_token") && C('malasen')!=2){ //add by lxphp.com
$url = $this->get_other_url();
$re = $this->curlpxml($url,$GLOBALS["HTTP_RAW_POST_DATA"]);
if(strstr($re,'xml')) { $ss=1; echo $re; }
//S('log',$re);
}
$xml=$this->msg();
if(S($xml['FromUserName'].$xml['CreateTime'])==1)exit;
S($xml['FromUserName'].$xml['CreateTime'],1,300);
$db =M('Wxtext');
//$db->add($xml);
$openid = $xml['FromUserName'];
$eventkey = $xml['EventKey'];
if($xml['MsgType']=='event') {
$Event=$xml['Event'];
switch($Event){
case "subscribe":
$usermod = M("Users");
$re = A('Api')->saveinfo($openid);
if($eventkey&& $xml['Ticket']){//二维码关注
$pid = str_replace('qrscene_','',$eventkey);
$pinfo = $usermod->find($pid);
$msg2 = "【".$re["user_nicename"]."】通过您分享的二维码关注了公众号,Ta注册后您有可能获得奖励。";
$this->makeTextbygm($msg2,$pinfo['weixin']);
$re['parent_id']=$datas2['puid']=$pid;
M("User_y_reg")->where("id=".$re['id'])->save($datas2);
}
/* if(C('gzshbval')>0)
A('Api')->sendhb($openid,C('gzshbval'),C('site_title'),C('hbbody'),2); // 关注送红包
if(C('gzsxj')>0) A('Api')->sendzz($openid,C('gzsxj'),C('hbbody'),2); //关注送现金*/
if($re['id']>0){
$msg = C("diygzhf")?C("diygzhf"):0;
$msg = $re['sex']==2?C("diygzhfnv"):$msg;
if($msg) $this->makeTextbygm(html_out($msg),$openid);
if(C('gztstw')==1){
$sex = $re['sex']==1?2:1;
if($re['sex']>0&&$re['cityid']){
$list = $usermod->field("user_nicename,avatar,provinceid,cityid,age,idmd5")->where("sex=".$sex." and cityid=".$re['cityid']." and avatar!=''")->order('last_login_time desc,id desc')->limit(8)->select();
}elseif($re['sex']>0&&$re['provinceid']){
$list = $usermod->field("user_nicename,avatar,provinceid,cityid,age,idmd5")->where("sex=".$sex." and provinceid=".$re['provinceid']." and avatar!=''")->order('last_login_time desc,id desc')->limit(8)->select();
}else{
$list = $usermod->field("user_nicename,avatar,provinceid,cityid,age,idmd5")->where("sex=".$sex." and avatar!=''")->order('last_login_time desc,id desc')->limit(8)->select();
}
$list2[0]['title']="来".C('site_title')."邂逅缘分吧";
$list2[0]['description']=$msg;
$list2[0]['url']="http://".C('site_url').U("Home/Index/index");
$list2[0]['picUrl']="http://www.yueai.me/v4/jiaocheng_03.jpg";
foreach($list as $key=>$val){
$list2[$key+1]['title']=$val['user_nicename']." ".(date('Y',time())-$val['age'])."岁 ".$re['province'].' '.$re['city'];
$list2[$key+1]['description']=$val['user_nicename']." ".(date('Y',time())-$val['age'])."岁";
$list2[$key+1]['url']="http://".C('site_url').U("Home/Show/index",array('uid'=>$val['idmd5']));
$list2[$key+1]['picUrl']=strstr($val['avatar'],'http')?$val['avatar']:'http://'.C('site_url')."/".$val['avatar'];
}
$ss1['items']=$list2;
if($openid!=C('adminopenid'))
$this->makeTextbygm("有新朋友关注:【".$re['user_nicename']."】",C('adminopenid'));
if(is_array($ss1)){//欢迎关注。
exit($this->makeNews($ss1));
}
}
}
//if($msg) $this->makeTextbygm(html_out($msg),$openid);
break;
case "unsubscribe":
A("Api")->unsubscribe($openid);
break;
case "CLICK":
if(C('old_subscribe')){
$data =A("Api")-> saveinfo($openid,1);
if($data['type']=='newreg'){
}
}
if($eventkey=='lxphpcom'){//二维码推广 20151112 by 紫竹
$msg ='正在生成您的推广二维码,请耐心等待...';
if($msg) $this->makeTextbygm($msg,$openid);
$media_id = A("Home/Api")->getewmmediaid($openid);
if($media_id) $this->makeImgbygm($media_id,$openid);
}
$msg = A("Api")->clickfun($eventkey,$openid);
if($msg) $this->makeTextbygm($msg,$openid);
//if($ss==0 && $msg) echo $this->makeText($msg);
//echo $this->makeText($msg);
break;
case "SCAN":
if($eventkey&& $xml['Ticket']){//二维码扫描
$re = A('Api')->saveinfo($openid);
$pid = str_replace('qrscene_','',$eventkey);
$pinfo = M("Users")->find($pid);
$msg2 = "【".$re["user_nicename"]."】扫描了您分享的二维码。";
$this->makeTextbygm($msg2,$pinfo['weixin']);
$datas2['puid']=$pid;
$ymod = M("User_y_reg");
$re2 = $ymod->where("code='$openid'")->find();
if($re2){
$ymod->where("code='$openid'")->save($datas2);
}else{
$datas2['time']=time();
$datas2['code']=$openid;
$ymod->add($datas2);
}
}
break;
}
}
if($xml['MsgType']=='text'){//接收文本消息后返回信息给用户
$xml['Content']=trim($xml['Content']);
echo $this->makeDkf($xml['Content']);
$re = M("ext_autoreplay")->where("keyword='".$xml['Content']."'")->find();
if($re){
$this->makeTextbygm($re['content'],$openid);
if($re['money'] && $re['money']>0){
A('Api')->sendhb($openid,$re['money'],C('site_title'),C('hbbody'),2); // 送红包
}
}
}
exit;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。