| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?phpnamespace App\Services\Common;use GuzzleHttp\Client;/** * qq第三方登录 * Class QqService * @package App\Services\Common */class QqService{    protected $auth_url = "https://graph.qq.com/";    protected $appid;    protected $appkey;    protected $httpClient;    /**     * QqService constructor.     */    public function __construct()    {        $this->httpClient=new Client([            'http_errors' => false        ]);        $this->appid=config('aix.system.oauth.qq.app_id');        $this->appkey=config('aix.system.oauth.qq.app_key');    }    public function getAccessToken($code)    {        $uri=$this->auth_url."oauth2.0/token?grant_type=authorization_code&client_id=$this->appid&client_secret=$this->appkey&code=$code&redirect_uri=".session('qq_redirect_uri');        $resopnse=$this->httpClient->get($uri);        parse_str($resopnse->getBody()->getContents(), $result);        return $result['access_token'];    }    public function getOpenid($access_token)    {        $uri=$this->auth_url."oauth2.0/me?access_token=$access_token";        $resopnse=$this->httpClient->get($uri);        $result=trim(str_replace(['callback(',');'], ["", ""], $resopnse->getBody()->getContents()));        $res_arr=json_decode($result, true);        return $res_arr['openid'];    }    public function getUserInfo($access_token, $openid)    {        $uri=$this->auth_url."user/get_user_info?access_token=$access_token&oauth_consumer_key=$this->appid&openid=$openid";        $resopnse=$this->httpClient->get($uri);        $res_arr=json_decode($resopnse->getBody()->getContents(), true);        return $res_arr;    }    public function getUser($code)    {        $access_token=$this->getAccessToken($code);        $openid=$this->getOpenid($access_token);        $user=$this->getUserInfo($access_token, $openid);        $user['openid']=$openid;        return $user;    }}
 |