zoukankan      html  css  js  c++  java
  • 微信登录

    //创建菜单  这是一个二级菜单(一级菜单最多为3个,二级菜单最多5个)

    //在微信公共平台配置自己的线上域名

    public $enableCsrfValidation = false;//必须加这句,否则报错


    public function actionMenu(){
    $config = [
    'app_id' => 'wxa025f2544f08189a',
    'secret' => 'd287ddceae3801fbc246c9dddd95f1d3',
    'token'=>'zhangjinchai',
    'response_type' => 'array',
    ];
    $app=Factory::officialAccount($config);
    $buttons = [
    [
    "name" => "组长团队",
    "sub_button" => [
    [
    "type" => "view",
    "name" => "登录",
    "url" => "http://106.12.144.217/advanced/frontend/web/index.php?r=month/send" //跳转send方法
    ],
    [
    "type" => "view",
    "name" => "二组",
    "url" => "http://v.qq.com/"
    ],
    [
    "type" => "click",
    "name" => "三组",
    "key" => "V1001_GOOD"
    ],
    [
    "type" => "click",
    "name" => "四组",
    "key" => "V1001_GOOD"
    ],
    [
    "type" => "click",
    "name" => "五组",
    "key" => "V1001_GOOD"
    ],
    ],
    ],
    [
    "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"
    ],
    [
    "type" => "click",
    "name" => "纪委",
    "key" => "V1001_GOOD"
    ],
    [
    "type" => "click",
    "name" => "生委",
    "key" => "V1001_GOOD"
    ]
    ],
    ],
    [
    "type" => "click",
    "name" => "优秀学员",
    "key" => "V1001_TODAY_MUSIC"
    ],
    ];
    $app->menu->create($buttons);
    }


    public function actionSend(){
    $config = [
    'app_id' => 'wxa025f2544f08189a',
    'secret' => 'd287ddceae3801fbc246c9dddd95f1d3',
    'token'=>'zhangjinchai',
    'aes_key'=>'BYsaHlHQBvZdMOOLmpY8Tq6jeiZjHAmX2N0XGaY5scX',
    'response_type' => 'array',
    ];(此配置信息为个人微信平台上的配置信息。请按需要填写)
    $app=Factory::officialAccount($config);
    $response = $app->oauth->scopes(['snsapi_userinfo'])
    ->redirect("http://106.12.144.217/advanced/frontend/web/index.php?r=month/getuser");//跳转个人用户信息,获取用户信息
    $response->send();

    //获取用户信息

    public function actionGetuser(){
    $user=$this->getCacheData('weixin_user');//若redis缓存中有相关数据,取出即可
    if(!$user){//如没有,获取用户信息
    $config = [
    'app_id' => 'wxa025f2544f08189a',
    'secret' => 'd287ddceae3801fbc246c9dddd95f1d3',
    'token'=>'zhangjinchai',
    'response_type' => 'array',
    ];
    $app=Factory::officialAccount($config);
    $user=$app->oauth->user()->toJSON();//获取到的数据为json格式,请按需要转换
    $this->setCacheData('weixin_user',$user,7200);//存入redis
    }
    $last=json_decode($user,true);
    print_r($last);//实现登录 打印用户数据
    }

    }


    ///数据存入缓存    
    public function setCacheData($key,$value,$time=3600)
    {
    $cache = Yii::$app->cache;
    if (is_array($value)){
    $value = json_encode($value);
    }
    $cache->set($key,$value,$time);
    }
    //缓存取出数据
    public function getCacheData($key,$is_array=false)
    {
    $cache = Yii::$app->cache;
    $returnData = $cache->get($key);
    if ($is_array){
    $returnData = json_decode($returnData,true);
    }
    return $returnData;
    }
  • 相关阅读:
    SUSE 安装 iServer、iDesktop启动异常问题
    各系统勒索补丁下载地址
    centos 安装atom 笔记
    转载---SuperMap GIS 9D SP1学习视频播单
    SuSE的命令安装软件 zypper
    Leaflet客户端学习笔记
    设置UI控件的Layer属性(边框可见,边框颜色,边框宽度,边框圆角)
    安全清理Xcode 缓存垃圾
    OC变量命名禁忌
    iOS中的应用启动原理
  • 原文地址:https://www.cnblogs.com/chaihtml/p/10254955.html
Copyright © 2011-2022 走看看