PHP code example of faysoft / fayoauth
1. Go to this page and download the library: Download faysoft/fayoauth library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
faysoft / fayoauth example snippets
//获取OAuth实例
$oauth = OauthService::getInstance(
'weixin',//登录方式代码,对应services\oauth下的文件夹名
{$app_id},//App Id
{$app_secret}//App Secret
);
//获取openId
$open_id = $oauth->getOpenId();
//获取第三方用户
$user = $oauth->getUser();
//获取第三方用户字段
$user->getNickName();//获取第三方昵称
$user->getAvatar();//获取第三方头像链接
$user->getOpenId();//获取第三方对外id(Open Id)
$user->getUnionId();//获取第三方Union Id(微信登录可能会有这个值)
$user->getParam('city');//获取指定字段,根据第三方登录方式不同,字段有所差异
$user->getParams();//获取所有第三方返回的用户字段