不要泛滥,不要泛滥,不要泛滥
和谐了,你我都不好受
不知道是啥的,看演示地址: https://forum.runpod.cn/OAuthLogin/WeChat
php代码如下,大佬们自行研究吧
做的太简单和谐的快
- <?php
namespace App\Plugins\OAuthLogin\src\Controller\WeChat;
use App\Plugins\OAuthLogin\src\Model\OauthLoginWechat;
use App\Plugins\OAuthLogin\src\Model\OauthLoginWechatBind;
use App\Plugins\User\src\Event\AfterLogin;
use App\Plugins\User\src\Lib\UserAuth;
use App\Plugins\User\src\Models\User;
use App\Plugins\User\src\Models\UserClass;
use App\Plugins\User\src\Models\UsersOption;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Utils\Str;
use HyperfExt\Hashing\Hash;
#[Controller(prefix:"/api/OAuthLogin/WeChat")]class ApiController
{
private string $appid = "wx311697afe4355554";
private string $redirect_uri = "https://lol.qq.com/";
private string $qrcode_uri = "https://open.weixin.qq.com/connect/qrcode/";
// 获取二维码
public function getQrCode(){
return $this->qrcode_uri.$this->getUuid();
}
private function getSessionId(){
if(!session()->get("OAuthLogin_WeChat")){
session()->set("OAuthLogin_WeChat",Str::random());
}
return session()->get("OAuthLogin_WeChat");
}
// 获取uuid
private function getUuid(){
$session_id = $this->getSessionId();
if(cache()->has("oauth.wechat.uuid.".$session_id)){
return cache()->get("oauth.wechat.uuid.".$session_id);
}
$data = http("raw")->get("https://open.weixin.qq.com/connect/qrconnect?appid=".$this->appid."&redirect_uri=".$this->redirect_uri."&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect")->getBody();
$uuid = Str::after((string)$data,'"https://long.open.weixin.qq.com/connect/l/qrconnect?uuid=');
$uuid = Str::before($uuid,'"');
cache()->set("oauth.wechat.uuid.".$session_id,$uuid,300);
return cache()->get("oauth.wechat.uuid.".$session_id);
}
// get open id
public function getWxCode(){
$data = http("raw")->get("https://long.open.weixin.qq.com/connect/l/qrconnect?uuid=".$this->getUuid())->getBody();
$wx_errcode = Str::after((string)$data,'window.wx_errcode=');
$wx_errcode = Str::before($wx_errcode,";");
if($wx_errcode!=405){
return null;
}
$wx_code = Str::after((string)$data,"window.wx_code='");
$wx_code = Str::before($wx_code,"'");
return $wx_code;
}
// 获取SMsg
public function getSMsg(){
if(!cache()->has("oauth.wechat.wxcode.".$this->getWxCode())){
$config = [
"headers" =>[
"authority" => "apps.game.qq.com",
"referer" => "https://lol.qq.com/"
] ];
$data = http('array')->get("https://apps.game.qq.com/ams/ame/codeToOpenId.php?appid=".$this->appid."&wxcode=".$this->getWxCode()."&sServiceType=lol&wxcodedomain=lol.qq.com&acctype=wx",$config);
cache()->set("oauth.wechat.wxcode.".$this->getWxCode(),$data,600);
}
return cache()->get("oauth.wechat.wxcode.".$this->getWxCode());
}
private function getOpenId(){
$data= $this->getSMsg();
if($data['iRet']!=0){
return null;
}
return json_decode($data['sMsg'],true)['openid'];
}
public function get_access_token(){
$data= $this->getSMsg();
if($data['iRet']!=0){
return null;
}
return json_decode($data['sMsg'],true)['access_token'];
}
#[PostMapping(path:"get_user_info")] public function get_user_info(){
$data = http("raw")->get("https://api.weixin.qq.com/sns/userinfo?access_token=".$this->get_access_token()."&openid=".$this->getOpenId())->getBody();
return json_decode(stripcslashes($data),true);
}
#[PostMapping(path:"status")] public function status(){
if(!$this->getUuid()){
return Json_Api(403,false,['msg' => 'uuid不存在']);
}
$data = http("raw")->get("https://long.open.weixin.qq.com/connect/l/qrconnect?uuid=".$this->getUuid())->getBody();
$wx_errcode = Str::after((string)$data,'window.wx_errcode=');
$wx_errcode = Str::before($wx_errcode,";");
$msg = match (@(string)$wx_errcode){
'404' => '扫码成功',
'405' => '确认登录',
'403' => '取消登陆',
'402' => '超时或获取失败,需要重新获取二维码',
'408' => '暂未扫码'
};
if($wx_errcode==405){
return Json_Api(200,true,['msg' => $msg]);
}
return Json_Api((int)$wx_errcode,false,['msg' => $msg]);
}
#[PostMapping(path:"remove_cookie")] public function remove_cookie(){
// get session id
$session_id = $this->getSessionId();
// remove uuid
cache()->delete("oauth.wechat.uuid.".$session_id);
return Json_Api(200,true,['msg' => 'cookie清理完毕']);
}
#[PostMapping(path:"bind")] public function bind(){
// 绑定
if($this->get_wechat_id()===false){
// 没读到openid
return Json_Api(403,false,['msg' => '未获取到open_id']);
}
if(auth()->check()){
// 开始绑定
return $this->logind_bind($this->get_wechat_id());
}
if(OauthLoginWechatBind::query()->where(['wechat_id'=>$this->get_wechat_id()])->exists()){
$user_id = OauthLoginWechatBind::query()->where(['wechat_id'=>$this->get_wechat_id()])->first()->user_id;
$user_data = User::query()->where('id',$user_id)->first();
$this->SignIn($user_data);
$this->remove_cookie();
return Json_Api(302,true,['msg' => '登陆成功!']);
}
return Json_Api(301,true,['msg' => '未登录,注册或登录后自动绑定']);
}
private function SignIn($user){
// 数据库里的密码
$token = Str::random(17);
session()->set('auth', $token);
(new UserAuth())->create($user->id,$token);
session()->set("auth_data",User::query()->where("id",auth()->id())->with("Class")->first());
session()->set("auth_data_class",UserClass::query()->where("id",auth()->data()->class_id)->first());
session()->set("auth_data_options",UsersOption::query()->where("id",auth()->data()->options_id)->first());
EventDispatcher()->dispatch(new AfterLogin($user));
return true;
}
private function logind_bind($wechat_id){
if(OauthLoginWechatBind::query()->where("wechat_id",$wechat_id)->exists()){
return Json_Api(403,false,['msg' => '绑定失败,此微信已被别的用户绑定!']);
}
OauthLoginWechatBind::query()->where("wechat_id",$wechat_id)->create([
'user_id' => auth()->id(),
'wechat_id' => $wechat_id
]);
$this->remove_cookie();
return Json_Api(200,true,['msg' => '绑定成功!']);
}
// 读oauth_login_wechat表数据:id
private function get_wechat_id():bool|int{
if($this->getOpenId()){
if(OauthLoginWechat::query()->where("open_id",$this->getOpenId())->exists()){
return (int)OauthLoginWechat::query()->where("open_id",$this->getOpenId())->first()->id;
}
$data = http("raw")->get("https://api.weixin.qq.com/sns/userinfo?access_token=".$this->get_access_token()."&openid=".$this->getOpenId())->getBody();
OauthLoginWechat::query()->create([
'open_id' => $this->getOpenId(),
'data' => $data
]);
return (int)OauthLoginWechat::query()->where("open_id",$this->getOpenId())->first()->id;
}
return false;
}
}
开源QQ机器人程序 https://hostloc.com/thread-978890-1-1.html
开源论坛程序 https://hostloc.com/thread-978629-1-1.html
推荐楼 ZeroOne 6小时前
早几个月前我就分析过了,只能说用来做些临时的项目可以(或者对已有用户系统进行绑定实现快速登录也可以,一旦失效自身的用户登录系统还可用),如果没有自身账号密码登录系统的话长远考虑并不推荐,因为一旦被封用不了了将丢失全部用户。
推荐楼 爱发卡 半小时前
消失一年半的大佬回归了
推荐楼 靠你几哇 6小时前
不止英雄联盟,还可以盗用王者荣耀的微信登录
2楼 i可乐 6小时前
大佬牛逼啊
3楼 aipage 6小时前
还是想念大佬的WP开心主题
4楼 sagit 6小时前
前排膜拜
5楼 lingtong 6小时前
牛逼 我改个.net的
6楼 好运 6小时前
谢谢大佬
8楼 Chappako 6小时前
这是个真大佬
9楼 robot 6小时前
NB PULS
10楼 p62 6小时前
nbnb
12楼 dole 6小时前
13楼 laox 6小时前
看不懂什么东西,只能说nb
14楼 靠你几哇 6小时前
不止英雄联盟,还可以盗用王者荣耀的微信登录
15楼 inkedus 6小时前
不止英雄联盟,还可以盗用王者荣耀的微信登录
有一个能用的足够了
16楼 dwf135 6小时前
小马哥牛皮试试
17楼 ZeroOne 6小时前
早几个月前我就分析过了,只能说用来做些临时的项目可以(或者对已有用户系统进行绑定实现快速登录也可以,一旦失效自身的用户登录系统还可用),如果没有自身账号密码登录系统的话长远考虑并不推荐,因为一旦被封用不了了将丢失全部用户。
18楼 太上皇 5小时前
这个很强啊
19楼 adminii 4小时前
感谢分享,先mark。
20楼 flipwalls 半小时前
不止英雄联盟,还可以盗用王者荣耀的微信登录
王者荣耀的直接避开扫码吗?
22楼 三丫的 半小时前
小号注册了一个,还没实名,天天说违规违法登录
23楼 kosuo 11分钟前
早几个月前我就分析过了,只能说用来做些临时的项目可以(或者对已有用户系统进行绑定实现快速登录也可以, ...
hahahaha,你分析的我那个站,我用的微云和英雄联盟
申明:本文内容由网友收集分享,仅供学习参考使用。如文中内容侵犯到您的利益,请在文章下方留言,本站会第一时间进行处理。
