首页 > 代码库 > 微信接口开发之高级篇系列【用户分组接口和生成带参数的二维码】
微信接口开发之高级篇系列【用户分组接口和生成带参数的二维码】
<?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=http://www.mamicode.com/‘{$src}‘>"; }
微信接口开发之高级篇系列【用户分组接口和生成带参数的二维码】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。