3,143
社区成员
发帖
与我相关
我的任务
分享
public function index()
{
//echo "<h1><a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=已隐藏70eb2764ff&redirect_uri=http://www.已隐藏com/t/public/index.php/index/wx/welcome&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'>wx_welcome</a></h1>";
$this->success('正在登陆,请稍等','https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6badae70eb2764ff&redirect_uri=http://已隐藏com/t/public/index.php/index/wx/welcome&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect','',0);
}
public function welcome()
{
echo "<h1>已经进入第一步<br/></h1>";
$url='https://api.weixin.qq.com/sns/oauth2/access_token?appid=已隐藏ae70eb2764ff&secret=已隐藏85801782ac31f217afcd72c&code='.input('param.code').'&grant_type=authorization_code';
echo "<h1>已经进入第二步生命数组<br/></h1>";
$data = array();
echo "<h1>已经进入第三步访问html<br/></h1>";
echo "<h1>已经进入第四步获取口令<br/></h1>";
$data = json_decode(file_get_contents($url), true);
dump($data);
echo "<br/><h1>已经输入完毕数据<br/></h1>";
if(array_key_exists("access_token", $data)){
$url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $data['access_token'] . '&openid=' . $data['openid'] .'&lang=zh_CN';
echo "<h1>已经获取url<br/></h1>";
$html = file_get_contents($url);
echo "<h1>已经访问url<br/></h1>";
$data = json_decode($html, true);
echo "<h1>已经转换字符串<br/></h1>";
//var_dump($data);//输出数组 '&wx_tx=' . $data['headimgurl'] .
Session::set('openid',$data['openid'].'@163.com');
Session::set('nickname',urlencode($data['nickname']));
Session::set('headimgurl',$data['headimgurl']);
$this->success('成功','index/index/xunzhao','',0);
// echo $data['access_token'];
//echo "获取信息成功了";
}else{
echo '<h1>'.$url."</h1>";
echo "<br/>";
var_dump($data);//输出数组
echo"获取信息失败了";
}
}