zoukankan      html  css  js  c++  java
  • 微信网页授权

    代码很少


    //
    获取code $appid='xxxxxx'; $redirect_uri = urlencode ('http://xxxxxxxxxxxx'); $url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; header("Location:".$url);




    if (!empty($_GET['code']))
    {
                                        
                $appid  = C('APPID'); 
    
                $secret = C('SECRET');
                
                $code   =  $_GET['code']; //通过code换取token  
                
                $url    =  "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code";
                
                $json   =  file_get_contents($url);
                
                $arr    =  json_decode($json,true);
                
                $token  =  $arr['access_token']; 
                
                $openid =  $arr['openid']; 
                            
                $url    =  "https://api.weixin.qq.com/sns/userinfo?access_token=$token&openid=$openid&lang=zh_CN";  //拿到token后获取用户基本信息
                
                $json   =  file_get_contents($url);  //获取微信用户基本信息
                
                
                $arr    =  json_decode($json,true); 
    }
  • 相关阅读:
    tuple-1
    禅语-1
    综述的写作技巧-1
    皆大欢喜组合
    类和对象-3
    双棍练习
    CodeBlocks开发环境使用-1
    类和对象-2
    类和对象-1
    13-归并排序-分治策略应用于排序
  • 原文地址:https://www.cnblogs.com/zhangxiangdong/p/8510086.html
Copyright © 2011-2022 走看看