Watch 2 Star 6 Fork 1

天然呆 / wyx2013PHP

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Nothing here. spread retract

Clone or download
Chat.php 3.25 KB
Copy Edit Web IDE Raw Blame History
天然呆 authored 2019-09-16 23:19 . 聊天后台添加好友完成
<?php
namespace app\index\controller;
use app\common\MemberService;
use app\common\MPChatService;
use app\index\model\AdminUser;
use app\index\model\AppOpen;
use app\index\model\ChatUser;
use app\index\model\WxWebUser;
use EasyWeChat\Factory;
use jwt\JWT;
use service\File;
use think\Exception;
use think\facade\Cookie;
use think\Controller;
use think\facade\Request;
use think\facade\Session;
class Chat extends Controller
{
public function initialize()
{
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: GET, POST, PUT');
parent::initialize(); // TODO: Change the autogenerated stub
}
public function index()
{
return view();
}
public function mobile()
{
return view();
}
/*网页用户聊天页面登录*/
public function chatWebUser()
{
if(!Request::isAjax()){ return; }
$data=Request::only(['password','username'], 'post');
$no_status=Request::get('no_status');//小程序登录
$member_service=new MemberService();
$response=$member_service->ajaxLogin($data,$no_status);
if($response['code']!==0){
return $response;
}
$user_info=$member_service->jwt($response);
return json($user_info);
}
/*用户注册页面*/
public function register()
{
$data=Request::only(['password','username','email','nickname'], 'post');
$member_service=new MemberService();
$response=$member_service->register($data);
if( $response['code']!==0){
return $response;
}
return json($response);
}
/**
* 验证用户名是否可用页面
* */
public function checkUserName()
{
if(input('?get.username')){
$username=strtolower( input('get.username') );
$user=AdminUser::where('username',$username)->find();
if($user){
$response=['err'=>'用户名重复','code'=>20];
}else{
$response=['username'=>$username];
}
return json($response);
}
return null;
}
/*小程序用户聊天页面*/
public function chatMiniProgramUser()
{
if(!input('?get.id')) return;
$str=(string)file_get_contents("php://input");
if(empty($str)){return false;}
$post=json_decode($str,true);
return json( (new MPChatService($post))->jwt() );
}
/*
* 上传文件
* */
public function uploadFile()
{
$tyep=input('get.type');
$file=Request::file('file');
//有传入的$_POST,可以做鉴权
if($tyep==='mp3'){
$info=$file->rule('date')->move('./upload/');
}elseif ($tyep==='img'){
$info=$file->rule('date')->validate(['size'=>200000,'ext'=>'jpg,png,gif'])->move('./upload/');
}else{
return json(['err'=>'末指定类型','code'=>4312]);
}
if($info){
$url=Request::root(true).'/upload/' .$info->getSaveName();
return json(['url'=>$url]);
}else{
return json(['err'=>$file->getError(),'code'=>4311]);
}
}
}

Comment ( 0 )

You need to Sign in for post a comment

PHP
1
https://gitee.com/wuxq1985/wyx2013.git
git@gitee.com:wuxq1985/wyx2013.git

Help Search