Commit 09d2add9 authored by 康帅杰's avatar 康帅杰 :speech_balloon:
Browse files

task#1210 写入订阅获取用户信息的时候,判断用户唯一错误

No related merge requests found
Showing with 17 additions and 12 deletions
+17 -12
......@@ -21,15 +21,12 @@ class SocialiteLogUserListener{
public function handle(SocialiteLogUser $event){
$class = 'Yjtec\\Socialite\\Models\\'.ucfirst($event->driver);
$clientId = $event->clientId;
$formatUser = (new $class($event->user))->toArray();
if(!(new $class)->where($formatUser)->get()->isNotEmpty()){
if(!(new $class)->uniqUser($event->user)){
$user = (new $class)->create(array_merge(
$event->user,
['client_id'=>$clientId]
));
$social = (new Socialite)->create([
'socialitetable_id' => $user->id,
'socialitetable_type' => $class
......
<?php
namespace Yjtec\Socialite\Models;
use Illuminate\Database\Eloquent\Model;
abstract class AbstractModel extends Model{
abstract public function uniqUser(array $user);
}
\ No newline at end of file
<?php
namespace Yjtec\Socialite\Models;
use Illuminate\Database\Eloquent\Model;
class Apple extends Model
class Apple extends AbstractModel
{
protected $table = 'socialite_apple';
protected $fillable = ['sub','client_id'];
public function uniqUser(array $user){
return $this->where('sub',$user['sub'])->first();
}
}
<?php
namespace Yjtec\Socialite\Models;
use Illuminate\Database\Eloquent\Model;
class Wechat extends Model
class Wechat extends AbstractModel
{
protected $table = 'socialite_wechat';
protected $fillable = ['client_id','openid','unionid','nickname','sex','city','province','country','headimgurl'];
public function uniqUser(array $user){
return $this->where('openid',$user['openid'])->first();
}
public function setNicknameAttribute($value){
$this->attributes['nickname'] = userTextEncode($value);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment