微信接口开发之高级篇系列用户分组接口和生成带参数的二维码

Posted Tinywan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信接口开发之高级篇系列用户分组接口和生成带参数的二维码相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Created by PhpStorm.
 * User: Tinywan
 * Date: 2016/9/11
 * Time: 10:00
 */

namespace Home\Controller;

use Org\Util\WechatAuth;
use Think\Controller;

class UserController extends Controller
{
    private $appid;
    private $appSecret;
    private $WechatAuth = "";//初始化WechatAuth类
    private $accsess_token = "";//缓存token

    public function __construct()
    {
        parent::__construct();
        $this->appid = C(‘WECHAT_OAUTH2.APPID‘);
        $this->appSecret = C(‘WECHAT_OAUTH2.APPSECRET‘);
        // 缓存起来
        if (!session(‘token‘)) {
            $this->WechatAuth = new WechatAuth($this->appid, $this->appSecret);//初始化WechatAuth类
            $WechatAuth = $this->WechatAuth;
            $token = $WechatAuth->getAccessToken();
            session(array(‘expire‘ => $token[‘expires_in‘]));//设置过期时间
            session(‘token‘, $token[‘accsess_token‘]);//缓存token
            $this->accsess_token = $token;
        } else {
            $token = session(‘token‘);
            $this->WechatAuth = new WechatAuth($this->appid, $this->appSecret, $token);//初始化WechatAuth类
            $this->accsess_token = $token;//缓存token
        }

    }

    public function test()
    {
        echo ‘selectGroupsGet‘;
    }


    //获取所有用户组
    public function selectGroupsGet()
    {
        header(‘Content-type:text/html;charset=utf-8;‘);
        $WechatAuth = $this->WechatAuth;
        $data = $WechatAuth->groupsGet();
        var_dump($data);
    }

    //创建一个分组
    public function createGroup()
    {
        header(‘Content-type:text/html;charset=utf-8;‘);
        $WechatAuth = $this->WechatAuth;
        $data = $WechatAuth->groupsCreate(‘万少波分组‘);
        var_dump($data);
    }

    //查询一下指定用户的分组
    public function GroupId()
    {
        $m = M(‘users‘);
        $user = $m->find(3);
        $openid = $user[‘openid‘];
        $WechatAuth = $this->WechatAuth;
        $data = $WechatAuth->groupsGetid($openid);
        var_dump($data);
    }
}

 带参数的二维码:

 // 生成带参数的二维码
    public function createCode()
    {
        $WechatAuth = $this->WechatAuth;
        $ticket = $WechatAuth->qrcodeCreate("10086"); //返回临时票据ticket
        $src = $WechatAuth->showqrcode($ticket[‘ticket‘]); //根据ticket获取二维码URL
        echo "<img width=‘40%‘ src=‘{$src}‘>";

    }

 

以上是关于微信接口开发之高级篇系列用户分组接口和生成带参数的二维码的主要内容,如果未能解决你的问题,请参考以下文章

微信公众平台开发(83) 生成带参数二维码

微信接口开发之高级篇系列微信权限封装类

PHP微信接口开发之高级篇之网页授权获取用户基本信息

如何让学习php微信API接口

微信开发之用户组

生成带参数的微信二维码