• 微信机器人 index


    <?php
    require_once ('src/wechat.php');
    $wechat = new wechat();
    $act = isset($_GET['act'])?$_GET['act']:'index';
    session_start();
    /*$res = $wechat->getLoginStatus();
    print_r($res);die;*/
    switch ($act) {
    case 'index':
    //登录页
    $uuid = $wechat->getUuid();
    $qrcode = "https://login.weixin.qq.com/qrcode/{$uuid}?t=webwx";
    include_once('tpl/qrcode.php');
    break;
    case 'status':
    //获取登录状态
    $uuid = $_GET['uuid'];
    $res = $wechat->getLoginStatus($uuid);
    if($res == 201){
    //已扫描,待确认
    $data = array('status' => 1);
    }elseif (substr_count($res, 'http')) {
    //确认成功
    $data = array('status' => 2);
    }else{
    //待扫描
    $data = array('status' => 0);
    }
    $data['msg'] = $res;
    exit(json_encode($data));
    break;
    case 'cookies':
    //获取用户uin 和 sid
    $url = $_POST['url'];
    $wxinfo = $wechat->getCookies($url);
    $wxinfo['status'] = 1;

    exit(json_encode($wxinfo));
    break;
    case 'chat':
    //主聊天框页面
    include_once('tpl/chat.php');
    break;
    case 'init':
    //初使化微信信息
    $json_info = $wechat->initWebchat();
    exit($json_info);
    break;
    case 'users':
    //获取所有好友列表
    $users = $wechat->getContact();
    echo $users;
    break;
    case 'sync':
    //服务器同步
    $synckey = $_POST['synckey'];
    $message = $wechat->wxsync($synckey);

    exit($message);
    break;
    case 'send':
    $toUsername = $_POST['toUsername'];
    $content = $_POST['content'];

    $res = $wechat->sendMessage($toUsername, $content);
    exit($res);
    break;
    case 'avatar':
    $uri = $_GET['uri'];
    $res = $wechat->getAvatar($uri);
    header('Content-Type: image/jpeg');
    imagejpeg($res);
    break;
    case 'tuling':
    //图灵机器人接管消息
    $toUsername = $_POST['toUsername'];
    $content = $_POST['content'];
    if($toUsername != $_SESSION['username']){
    $mes = $wechat->sendMessageToTuling($content);
    $res = $wechat->sendMessage($toUsername, $mes);
    //拼接上机器人的回话
    $tlCon = json_decode($res,true);
    $tlCon['tlc'] = $mes;
    $tlCon['status'] = 1;
    exit(json_encode($tlCon));
    }
    exit(json_encode(array('status' => 0)));
    break;
    default:
    # code...
    break;
    }

    ?>

  • 相关阅读:
    【More Effective C++ 条款4】非必要不提供default constructor
    【More Effective C++ 条款3】最好不要以多态方式处理数组
    【C++】Debug模式和Release模式的区别
    【More Effective C++ 条款2】最好使用C++转型操作符
    【More Effective C++ 条款1】仔细区别pointers和references
    程序崩溃时的堆栈捕捉
    快速排序--来自维基百科
    十六进制转为字符串
    linux那些事
    svnsync备份
  • 原文地址:https://www.cnblogs.com/wangxiaozhuo/p/10488229.html
Copyright © 2020-2023  润新知