码迷,mamicode.com
首页 > 其他好文 > 详细

easywechat在laravel框架中的应用-代码参考

时间:2019-05-14 15:00:33      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:com   php   DDM   day   add   case   ati   网址   ret   

<?php
namespace App\Http\Controllers;
class WeChatController extends Controller{
    //用户列表
    public function userList()
    {
        $app = app(‘wechat.official_account.default‘);
        return $app->user->list();
    }

    //获取菜单
    public function getMenu(){
        $app = app(‘wechat.official_account.default‘);
        return $app->menu->list();
    }

    //创建临时二维码
    public function createQrcode(){
        $app = app(‘wechat.official_account.default‘);
        $result = $app->qrcode->temporary(‘foo‘, 6 * 24 * 3600);//创建
        return $result;
    }

    //获取二维码网址
    public function getUrl(){
        $app = app(‘wechat.official_account.default‘);
        $url = $app->qrcode->url(‘gQGX7zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyQjhwRFpMN2RmckMxTm9TeXhzYzUAAgRYTdpcAwQA6QcA‘);
        echo $url;
    }

    //删除全部菜单
    public function delMenu(){
        $app = app(‘wechat.official_account.default‘);
        $res = $app->menu->delete(); // 全部
        return $res;
    }

    //添加菜单
    public function addMenu(){
        $app = app(‘wechat.official_account.default‘);
        $buttons = [
            [
                "type" => "click",
                "name" => "今日歌曲",
                "key"  => "V1001_TODAY_MUSIC"
            ],
            [
                "name"       => "菜单",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "搜索",
                        "url"  => "http://www.soso.com/"
                    ],
                    [
                        "type" => "view",
                        "name" => "视频",
                        "url"  => "http://v.qq.com/"
                    ],
                    [
                        "type" => "click",
                        "name" => "赞一下我们",
                        "key" => "V1001_GOOD"
                    ],
                ],
            ],
        ];
        $res = $app->menu->create($buttons);
        return $res;
    }

    //消息
    public function server(){
        $app = $app = app(‘wechat.official_account.default‘);
        $app->server->push(function ($message) use ($app){
//            $user = $app->user->get($message[‘FromUserName‘]);
//            return ‘你好‘.$user[‘nickname‘].‘;您刚刚说了一句:‘.$message[‘Content‘];
            switch ($message[‘MsgType‘]) {
                case ‘event‘:
                    return ‘收到事件消息‘;
                    break;
                case ‘text‘:
                    return ‘收到文字消息‘;
                    break;
                case ‘image‘:
                    return ‘收到图片消息‘;
                    break;
                case ‘voice‘:
                    return ‘收到语音消息‘;
                    break;
                case ‘video‘:
                    return ‘收到视频消息‘;
                    break;
                case ‘location‘:
                    return ‘收到坐标消息‘;
                    break;
                case ‘link‘:
                    return ‘收到链接消息‘;
                    break;
                case ‘file‘:
                    return ‘收到文件消息‘;
                // ... 其它消息
                default:
                    return ‘收到其它消息‘;
                    break;
            }
        });
        $response = $app->server->serve();
        return $response;
    }
}

 

easywechat在laravel框架中的应用-代码参考

标签:com   php   DDM   day   add   case   ati   网址   ret   

原文地址:https://www.cnblogs.com/jiangshiguo/p/10861951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!