公众服务号怎么样实现一键登陆

移动开发 码拜 8年前 (2016-04-12) 1001次浏览
如下图
公众服务号怎么样实现一键登陆
给个代码例子。
解决方案

5

这个没研究过,弄过订阅号,但是手机不能登

45

服务认证号,带网页授权功能,假如你运营的号不是服务认证号,可以其他的也利用别的服务认证号实现

public function joinUs(){
        if(!is_weixin()) return false;
        $wechat_info = $this->winfo;
        $w_id = getWid();
        if($wechat_info["w_auth"]!=1){   
           //代理官方认证号
           if(SITEDOMAIN!="www.".C("officialDomain")){
               $off_wid = D("User")->findProxyAuthen($w_id);
               if(!$off_wid) return false;              
               $wechat_info =  D("Wechat")->getWechatCache($off_wid);
           }else{
               //官方认证号
               $wechat_info = M("wechat_extend")->where(array("lower(w_weixin)"=>C("officialWx")))->find();
           }       
      
        }
        if($_GET["code"]){           
           $cfg["appid"] = $wechat_info["w_appid"];
           $cfg["secret"] = $wechat_info["w_secret"];
           $s = json_decode(getRemoteContent("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$cfg["appid"]."&secret=".$cfg["secret"]."&code=".$_GET["code"]."&grant_type=authorization_code"),true);
           $urs = json_decode(getRemoteContent("https://api.weixin.qq.com/sns/userinfo?access_token=".$s["access_token"]."&openid=".$s["openid"]."&lang=zh_CN"),true);
           if($urs["openid"]){                  
             $r = M("wechat_user");  
             $uid = getUid();            
             $nickname = filterNickName($urs["nickname"]);
             //当前公众号入库数据补充
             $sfile = "./Public/Uploads/weixin/avatar/".md5($urs["openid"]).".jpg";
             $data["headimgurl"] = D("WechatUser")->getAvatar($urs["headimgurl"],$sfile);
             $data = array("nickname"=>$nickname,"headimgurl"=>$sfile,"sex"=>$urs["sex"],"country"=>$urs["country"],"province"=>$urs["province"],"city"=>$urs["city"]);
             M("wechat_user")->where(array("id"=>$uid))->save($data); 
             if($uid && $nickname && $nickname!="网友"){             
               $this->assign("msg","授权完成");
             }elseif(!$uid){
               $this->assign("msg","用户信息未入库,请检查公众号配置参数能否正确");
             }else{
               $this->assign("msg","很遗憾,请确认您的微信能否设置了昵称");
             }
             $this->display("index");
            
           }else{
             $this->assign("msg","授权失败");
             $this->display("index"); 
           }  
        }else{
            $this->assign("msg","您取消了授权");
            $this->display("index");           
           
        }
          
      }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明公众服务号怎么样实现一键登陆
喜欢 (0)
[1034331897@qq.com]
分享 (0)