• PHP实现微信公众号授权获取用户信息


    class WxAuthModel extends BaseModel
    {
        var $appId = APPID;
        var $appSecret = APPSECRET;
    
    
        /*微信x小程序,获取微信openid
         *前端的回调url:填写成你的请求地址,然后微信会自己在这个回调url后加一个code,获取通过url传过来的code来换取access_token
        */
        public function get_access_token($code){
            $token_url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$this->appId."&secret=".$this->appSecret."&js_code=".$code."&grant_type=authorization_code";
            $token_info = $this->http_request($token_url);
            return json_decode($token_info, true);
        }
    
    
        //HTTP请求(支持HTTP/HTTPS,支持GET/POST)
        private function http_request($url, $data = null)
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            if (!empty($data)){
                curl_setopt($curl, CURLOPT_POST, TRUE);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            }
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
            $output = curl_exec($curl);
            curl_close($curl);
            file_put_contents('/tmp/heka_weixin.' . date("Ymd") . '.log', date('Y-m-d H:i:s') . "	" . $output . "
    ", FILE_APPEND); //记录微信请求日志
            return $output;
        }
    
    
    }
    
    
  • 相关阅读:
    kvm虚拟迁移(5)
    kvm虚拟化网络管理(4)
    计算系数
    排列组合
    错排
    加分二叉树
    皇宫看守
    战略游戏
    数字转换
    JDK8 HashMap源码分析
  • 原文地址:https://www.cnblogs.com/xinxinmifan/p/9687751.html
Copyright © 2020-2023  润新知