时间:2021-07-01 10:21:17 帮助过:50人阅读
//网页授权获取用户基本信息
public function webUsers(){
$token=session('token');
$wechatAuth=new WechatAuth($this->appId,$this->appSecret,$token);
//$wechatAuth=$this->wechatAuth;
if($_GET['iscode']){
$url="http://hdzs.zhed.com/index.php/Activity/index";
$result=$wechatAuth->getRequestCodeurl($url);
header("Location:{$result}");
}else
if($_GET['code']){
header('Content-type:text/html;charset=utf-8');
$users=$wechatAuth->getAccessToken('code',$_GET['code']);//疑惑语句
$User=M("User");//实例化user对象
$openid=$users['openid'];
session('openid',"$openid");//将用户的openid存入session中
public function users($wechat,$data){
$openid=$data['FromUserName'];
//session(null);
// session('openid',"$openid");
//$wechatAuth=$this->wechatAuth;//实例化 $wechatAuth对象
///$user=$wechatAuth->UserInfo($openid);
$text="你的用户名是:". session('openid');
$this->logger("发送用户消息".$text);
//$wechat->replyText($text);
}```
在微信公众平台开发中 为什么在一个模块下的2个控制器中同一个session不能用
//网页授权获取用户基本信息
public function webUsers(){
$token=session('token');
$wechatAuth=new WechatAuth($this->appId,$this->appSecret,$token);
//$wechatAuth=$this->wechatAuth;
if($_GET['iscode']){
$url="http://hdzs.zhed.com/index.php/Activity/index";
$result=$wechatAuth->getRequestCodeurl($url);
header("Location:{$result}");
}else
if($_GET['code']){
header('Content-type:text/html;charset=utf-8');
$users=$wechatAuth->getAccessToken('code',$_GET['code']);//疑惑语句
$User=M("User");//实例化user对象
$openid=$users['openid'];
session('openid',"$openid");//将用户的openid存入session中
public function users($wechat,$data){
$openid=$data['FromUserName'];
//session(null);
// session('openid',"$openid");
//$wechatAuth=$this->wechatAuth;//实例化 $wechatAuth对象
///$user=$wechatAuth->UserInfo($openid);
$text="你的用户名是:". session('openid');
$this->logger("发送用户消息".$text);
//$wechat->replyText($text);
}```
session(null);
session(null); //已经把session清空了. 当然下面就拿不到了