21,893
社区成员




public function wxLogin() {
$wechatlogin = M('wechatlogin');//获取code
$code = $this->_get('code');
//echo $code;
//根据code换取access_token
$get_ac_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxxf&code={$code}&grant_type=authorization_code";
$res_data = file_get_contents($get_ac_url);
$res_arr = json_decode($res_data, true);
//echo'<pre>';
//print_r($res_arr);
//根据access_token获取用户信息
$get_user_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$res_arr['access_token']}&openid={$res_arr['openid']}";
$user_data = file_get_contents($get_user_url);
$res_arr1 = json_decode($user_data, true);
//echo'<pre>';
//print_r($res_arr1);
$data['openid'] = $res_arr1['openid'];
$data['nickname'] = $res_arr1['nickname'];
$data['unionid'] = $res_arr1['unionid'];
$data['headimgurl'] = $res_arr1['headimgurl'];
//将用户信息存储到SESSION中
session('user_data', $user_data);
//获取用户ID之后,和微信信息入库进行绑定,构建入库数据
$wx_user_info = json_decode(session('user_data'),true);
//echo $wx_user_info;
//echo'<pre>';
//print_r($wx_user_info);
$arr=array(
"openid"=>$res_arr1['openid'],
"nickname"=>$res_arr1['nickname'],
"unionid"=>$res_arr1['unionid'],
"headimgurl"=>$res_arr1['headimgurl'],
"id" =>$wxbdid,
);
// $data['openid']= '1122';
// $data['nickname']= $wx_user_info['nickname'];
// $data['unionid']= $wx_user_info['unionid'];
//$data['headimgurl']= $$wx_user_info['headimgurl'];
// $data['id'] = $data['id'];
//$wechatlogin->data($data);
$wechatlogin->data($arr)->add();
//提醒用户注册或者绑定已有账号
//保存用户信息
//初始化用户登录状态
$this->display('wechatLogin');
[/quote]
微信表里面eid对应的是邮箱账号的id,在绑定邮箱的时候就绑定两个表的关联,下次扫码登陆就可以连接两个表[/quote]
但是现在不知道怎么实现关联这两个表,下面这个是相似的room_id 和goods_id的关联,但是目前照葫芦画不出来瓢,还是没有实现关联两个表
public function add_four() {
$Room = M('Room');
$User_info = M('User_info');
$Sxtjs = M('Sxtjs');
$GoodsImages = M('GoodsImages');
//会员信息
$hyid=session("hyid");
$jiben = $User_info->where("id = $hyid")->find();
$rid=$this->_get('room_id');
$whrs['hyid']=$hyid;
$whrs['room_id']=$rid;
$upd=$Room->where($whrs)->find();
$gid=$upd['room_id'];
$this->assign('gid',$gid);
$image_list=$GoodsImages->where(array('goods_id'=>$upd['room_id']))->order('id asc')->select();
$this->assign('image_list',$image_list);
if($upd){
if($hyid!=""){
if(IS_POST){
$goods_images=$this->_post('planfile');
$goodsImagesArr = M('GoodsImages')->where("goods_id = $gid")->getField('id,image_url'); // 查出所有已经存在的图片
// 删除图片
foreach($goodsImagesArr as $key => $val)
{
if(!in_array($val, $goods_images))
M('GoodsImages')->where("id = {$key}")->delete(); // 删除所有状态为0的用户数据
}
// 添加图片
foreach($goods_images as $key => $val){
if($val == null) continue;
if(!in_array($val, $goodsImagesArr))
{
$data = array(
'goods_id' => $upd['room_id'],
'image_url' => $val,
);
M("GoodsImages")->data($data)->add(); // 实例化User对象
}
}
if($upd['is_fabu']==0){
redirect(U('Fy/rom_info',array('room_id'=>$rid)));
exit;
}else{
redirect(U('Fy/rom_info',array('room_id'=>$rid)));
exit;
}
}
}else{
$this->error('请先登录',U('Index/index'));
}
}else{
redirect(U('Fy/add_one'));
exit;
}
$this->assign('jiben',$jiben);
$this->assign('tj_list',$tj_list);
$this->display();
}
[/quote]
微信用户表有个eid(关联了邮箱用户表的id),查找微信用户的邮箱用户表信息时,M("邮箱用户表")->where(["id"=>$eid])->find()public function wxLogin() {
$wechatlogin = M('wechatlogin');//获取code
$code = $this->_get('code');
//echo $code;
//根据code换取access_token
$get_ac_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxxf&code={$code}&grant_type=authorization_code";
$res_data = file_get_contents($get_ac_url);
$res_arr = json_decode($res_data, true);
//echo'<pre>';
//print_r($res_arr);
//根据access_token获取用户信息
$get_user_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$res_arr['access_token']}&openid={$res_arr['openid']}";
$user_data = file_get_contents($get_user_url);
$res_arr1 = json_decode($user_data, true);
//echo'<pre>';
//print_r($res_arr1);
$data['openid'] = $res_arr1['openid'];
$data['nickname'] = $res_arr1['nickname'];
$data['unionid'] = $res_arr1['unionid'];
$data['headimgurl'] = $res_arr1['headimgurl'];
//将用户信息存储到SESSION中
session('user_data', $user_data);
//获取用户ID之后,和微信信息入库进行绑定,构建入库数据
$wx_user_info = json_decode(session('user_data'),true);
//echo $wx_user_info;
//echo'<pre>';
//print_r($wx_user_info);
$arr=array(
"openid"=>$res_arr1['openid'],
"nickname"=>$res_arr1['nickname'],
"unionid"=>$res_arr1['unionid'],
"headimgurl"=>$res_arr1['headimgurl'],
"id" =>$wxbdid,
);
// $data['openid']= '1122';
// $data['nickname']= $wx_user_info['nickname'];
// $data['unionid']= $wx_user_info['unionid'];
//$data['headimgurl']= $$wx_user_info['headimgurl'];
// $data['id'] = $data['id'];
//$wechatlogin->data($data);
$wechatlogin->data($arr)->add();
//提醒用户注册或者绑定已有账号
//保存用户信息
//初始化用户登录状态
$this->display('wechatLogin');
[/quote]
微信表里面eid对应的是邮箱账号的id,在绑定邮箱的时候就绑定两个表的关联,下次扫码登陆就可以连接两个表[/quote]
但是现在不知道怎么实现关联这两个表,下面这个是相似的room_id 和goods_id的关联,但是目前照葫芦画不出来瓢,还是没有实现关联两个表
public function add_four() {
$Room = M('Room');
$User_info = M('User_info');
$Sxtjs = M('Sxtjs');
$GoodsImages = M('GoodsImages');
//会员信息
$hyid=session("hyid");
$jiben = $User_info->where("id = $hyid")->find();
$rid=$this->_get('room_id');
$whrs['hyid']=$hyid;
$whrs['room_id']=$rid;
$upd=$Room->where($whrs)->find();
$gid=$upd['room_id'];
$this->assign('gid',$gid);
$image_list=$GoodsImages->where(array('goods_id'=>$upd['room_id']))->order('id asc')->select();
$this->assign('image_list',$image_list);
if($upd){
if($hyid!=""){
if(IS_POST){
$goods_images=$this->_post('planfile');
$goodsImagesArr = M('GoodsImages')->where("goods_id = $gid")->getField('id,image_url'); // 查出所有已经存在的图片
// 删除图片
foreach($goodsImagesArr as $key => $val)
{
if(!in_array($val, $goods_images))
M('GoodsImages')->where("id = {$key}")->delete(); // 删除所有状态为0的用户数据
}
// 添加图片
foreach($goods_images as $key => $val){
if($val == null) continue;
if(!in_array($val, $goodsImagesArr))
{
$data = array(
'goods_id' => $upd['room_id'],
'image_url' => $val,
);
M("GoodsImages")->data($data)->add(); // 实例化User对象
}
}
if($upd['is_fabu']==0){
redirect(U('Fy/rom_info',array('room_id'=>$rid)));
exit;
}else{
redirect(U('Fy/rom_info',array('room_id'=>$rid)));
exit;
}
}
}else{
$this->error('请先登录',U('Index/index'));
}
}else{
redirect(U('Fy/add_one'));
exit;
}
$this->assign('jiben',$jiben);
$this->assign('tj_list',$tj_list);
$this->display();
}
public function wxLogin() {
$wechatlogin = M('wechatlogin');//获取code
$code = $this->_get('code');
//echo $code;
//根据code换取access_token
$get_ac_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxxf&code={$code}&grant_type=authorization_code";
$res_data = file_get_contents($get_ac_url);
$res_arr = json_decode($res_data, true);
//echo'<pre>';
//print_r($res_arr);
//根据access_token获取用户信息
$get_user_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$res_arr['access_token']}&openid={$res_arr['openid']}";
$user_data = file_get_contents($get_user_url);
$res_arr1 = json_decode($user_data, true);
//echo'<pre>';
//print_r($res_arr1);
$data['openid'] = $res_arr1['openid'];
$data['nickname'] = $res_arr1['nickname'];
$data['unionid'] = $res_arr1['unionid'];
$data['headimgurl'] = $res_arr1['headimgurl'];
//将用户信息存储到SESSION中
session('user_data', $user_data);
//获取用户ID之后,和微信信息入库进行绑定,构建入库数据
$wx_user_info = json_decode(session('user_data'),true);
//echo $wx_user_info;
//echo'<pre>';
//print_r($wx_user_info);
$arr=array(
"openid"=>$res_arr1['openid'],
"nickname"=>$res_arr1['nickname'],
"unionid"=>$res_arr1['unionid'],
"headimgurl"=>$res_arr1['headimgurl'],
"id" =>$wxbdid,
);
// $data['openid']= '1122';
// $data['nickname']= $wx_user_info['nickname'];
// $data['unionid']= $wx_user_info['unionid'];
//$data['headimgurl']= $$wx_user_info['headimgurl'];
// $data['id'] = $data['id'];
//$wechatlogin->data($data);
$wechatlogin->data($arr)->add();
//提醒用户注册或者绑定已有账号
//保存用户信息
//初始化用户登录状态
$this->display('wechatLogin');
[/quote]
微信表里面eid对应的是邮箱账号的id,在绑定邮箱的时候就绑定两个表的关联,下次扫码登陆就可以连接两个表public function wxLogin() {
$wechatlogin = M('wechatlogin');//获取code
$code = $this->_get('code');
//echo $code;
//根据code换取access_token
$get_ac_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxxf&code={$code}&grant_type=authorization_code";
$res_data = file_get_contents($get_ac_url);
$res_arr = json_decode($res_data, true);
//echo'<pre>';
//print_r($res_arr);
//根据access_token获取用户信息
$get_user_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$res_arr['access_token']}&openid={$res_arr['openid']}";
$user_data = file_get_contents($get_user_url);
$res_arr1 = json_decode($user_data, true);
//echo'<pre>';
//print_r($res_arr1);
$data['openid'] = $res_arr1['openid'];
$data['nickname'] = $res_arr1['nickname'];
$data['unionid'] = $res_arr1['unionid'];
$data['headimgurl'] = $res_arr1['headimgurl'];
//将用户信息存储到SESSION中
session('user_data', $user_data);
//获取用户ID之后,和微信信息入库进行绑定,构建入库数据
$wx_user_info = json_decode(session('user_data'),true);
//echo $wx_user_info;
//echo'<pre>';
//print_r($wx_user_info);
$arr=array(
"openid"=>$res_arr1['openid'],
"nickname"=>$res_arr1['nickname'],
"unionid"=>$res_arr1['unionid'],
"headimgurl"=>$res_arr1['headimgurl'],
"id" =>$wxbdid,
);
// $data['openid']= '1122';
// $data['nickname']= $wx_user_info['nickname'];
// $data['unionid']= $wx_user_info['unionid'];
//$data['headimgurl']= $$wx_user_info['headimgurl'];
// $data['id'] = $data['id'];
//$wechatlogin->data($data);
$wechatlogin->data($arr)->add();
//提醒用户注册或者绑定已有账号
//保存用户信息
//初始化用户登录状态
$this->display('wechatLogin');