切换导航条
此项目
正在载入...
登录
郭盛
/
enterprise
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
何书鹏
4 years ago
提交
17e465ea7748411453cd6b570be7a9f7083612cd
1 个父辈
e8b01929
1 个管道 的构建
通过
耗费 0 秒
微信授权登录
变更
2
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
194 行增加
和
0 行删除
application/mobile/controller/User.php
application/mobile/model/UserThird.php
application/mobile/controller/User.php
查看文件 @
17e465e
...
...
@@ -28,6 +28,7 @@ use app\mobile\model\TopicAppraiseGood;
use
app\mobile\model\UserJob
;
use
app\mobile\model\CompanyJob
;
use
app\mobile\model\Statistic
;
use
app\mobile\model\UserThird
;
use
addons\epay\library\Service
;
use
Endroid\QrCode\QrCode
;
...
...
@@ -303,6 +304,104 @@ class User extends Api
}
/**
* 第三方登录
* @ApiWeigh (91)
*
* @ApiTitle (第三方登录)
* @ApiSummary (第三方登录)
* @ApiMethod (POST)
*
* @ApiParams (name="nickname", type="integer", required=true, description="第三方账号昵称")
* @ApiParams (name="avatar", type="integer", required=false, description="第三方账号头像")
* @ApiParams (name="gender", type="integer", required=false, description="第三方性别")
* @ApiParams (name="openid", type="string", required=true, description="第三方登录返回的唯一识别数据")
* @ApiParams (name="unionid", type="string", required=false, description="第三方用户多个产品中的唯一id,如:微信开放平台")
*
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"token": 用户token
}
})
*/
public
function
userThird
()
{
$param
=
$this
->
request
->
param
();
$validate
=
new
Validate
([
'nickname'
=>
'require'
,
'openid'
=>
'require'
,
]);
$validate
->
message
([
'nickname.require'
=>
'缺少参数nickname!'
,
'openid.require'
=>
'缺少参数openid!'
,
]);
if
(
!
$validate
->
check
(
$param
))
{
$this
->
error
(
$validate
->
getError
());
}
// 判断用户是否已绑定该openid
$time
=
time
();
$ip
=
request
()
->
ip
();
$third
=
UserThird
::
where
(
'openid'
,
$param
[
'openid'
])
->
find
();
Db
::
startTrans
();
if
(
$third
)
{
// 修改第三方信息
$result
=
UserThird
::
where
(
'id'
,
$third
[
'id'
])
->
update
([
'openname'
=>
$param
[
'nickname'
],
'logintime'
=>
$time
]);
// 修改用户信息
$user
=
\app\common\model\User
::
get
(
$third
[
'user_id'
]);
if
(
!
empty
(
$param
[
'nickname'
])
&&
empty
(
$user
[
'nickname'
])){
$user
->
nickname
=
$param
[
'nickname'
];
}
if
(
!
empty
(
$param
[
'avatar'
])
&&
(
empty
(
$user
[
'image'
])
||
stripos
(
$user
[
'image'
],
'http'
)
!==
false
)){
$user
->
image
=
$param
[
'avatar'
];
}
if
(
!
empty
(
$param
[
'gender'
])
&&
!
isset
(
$user
[
'sex'
])){
$user
->
sex
=
$param
[
'gender'
]
==
2
?
0
:
$param
[
'gender'
];
}
$user
->
loginip
=
$ip
;
$user
->
logintime
=
$time
;
$user
->
updatetime
=
$time
;
$results
=
$user
->
save
();
// 登录
$login
=
$this
->
auth
->
direct
(
$third
[
'user_id'
]);
}
else
{
// 添加用户信息
$result
=
\app\common\model\User
::
create
([
'nickname'
=>
$param
[
'nickname'
],
'sex'
=>
$param
[
'gender'
]
==
2
?
0
:
$param
[
'gender'
],
'image'
=>
$param
[
'avatar'
],
'status'
=>
'normal'
,
'jointime'
=>
$time
,
'joinip'
=>
$ip
,
'logintime'
=>
$time
,
'loginip'
=>
$ip
,
'prevtime'
=>
$time
]);
// 添加第三方信息
$results
=
UserThird
::
create
([
'user_id'
=>
$result
[
'id'
],
'openname'
=>
$param
[
'nickname'
],
'platform'
=>
'wechat'
,
'openid'
=>
$param
[
'openid'
],
'createtime'
=>
$time
,
'updatetime'
=>
$time
,
'logintime'
=>
$time
,
'unionid'
=>
$param
[
'unionid'
],
]);
// 登录
$login
=
$this
->
auth
->
direct
(
$result
[
'id'
]);
}
if
(
!
$result
||
!
$results
||
!
$login
)
{
Db
::
rollback
();
$this
->
error
(
'授权登录失败'
);
}
Db
::
commit
();
$this
->
success
(
'成功'
,[
'token'
=>
$this
->
auth
->
getToken
()]);
}
/**
* @ApiWeigh (89)
* @ApiTitle (忘记密码)
* @ApiSummary (忘记密码)
...
...
@@ -507,6 +606,85 @@ class User extends Api
}
/**
* @ApiWeigh (77)
* @ApiTitle (绑定微信)
* @ApiSummary (绑定微信)
* @ApiMethod (POST)
*
* @ApiParams (name="nickname", type="integer", required=true, description="第三方账号昵称")
* @ApiParams (name="avatar", type="integer", required=false, description="第三方账号头像")
* @ApiParams (name="gender", type="integer", required=false, description="第三方性别")
* @ApiParams (name="openid", type="string", required=true, description="第三方登录返回的唯一识别数据")
* @ApiParams (name="unionid", type="string", required=false, description="第三方用户多个产品中的唯一id,如:微信开放平台")
*
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"token": 用户token
}
})
*/
public
function
bindThird
()
{
$param
=
$this
->
request
->
param
();
$validate
=
new
Validate
([
'nickname'
=>
'require'
,
'openid'
=>
'require'
,
]);
$validate
->
message
([
'nickname.require'
=>
'缺少参数nickname!'
,
'openid.require'
=>
'缺少参数openid!'
,
]);
if
(
!
$validate
->
check
(
$param
))
{
$this
->
error
(
$validate
->
getError
());
}
// 判断用户是否已绑定该openid
$time
=
time
();
$ip
=
request
()
->
ip
();
$third
=
UserThird
::
where
(
'openid'
,
$param
[
'openid'
])
->
find
();
Db
::
startTrans
();
if
(
$third
)
{
$user
=
\app\common\model\User
::
get
(
$third
[
'user_id'
]);
if
(
$user
[
'id'
]
!=
$this
->
auth
->
id
){
$this
->
error
(
'该微信已绑定其他账号'
);
}
$result
=
UserThird
::
where
(
'id'
,
$third
[
'id'
])
->
update
([
'openname'
=>
$param
[
'nickname'
],
]);
}
else
{
UserThird
::
where
(
'user_id'
,
$this
->
auth
->
id
)
->
delete
();
$user
=
\app\common\model\User
::
get
(
$this
->
auth
->
id
);
$result
=
UserThird
::
create
([
'user_id'
=>
$this
->
auth
->
id
,
'openname'
=>
$param
[
'nickname'
],
'platform'
=>
'wechat'
,
'openid'
=>
$param
[
'openid'
],
'createtime'
=>
$time
,
'updatetime'
=>
$time
,
'logintime'
=>
$time
,
'unionid'
=>
$param
[
'unionid'
],
]);
}
if
(
!
empty
(
$param
[
'nickname'
])
&&
empty
(
$user
[
'nickname'
])){
$user
->
nickname
=
$param
[
'nickname'
];
}
if
(
!
empty
(
$param
[
'avatar'
])
&&
(
empty
(
$user
[
'image'
])
||
stripos
(
$user
[
'image'
],
'http'
)
!==
false
)){
$user
->
image
=
$param
[
'avatar'
];
}
if
(
!
empty
(
$param
[
'gender'
])
&&
!
isset
(
$user
[
'sex'
])){
$user
->
sex
=
$param
[
'gender'
]
==
2
?
0
:
$param
[
'gender'
];
}
$user
->
updatetime
=
$time
;
$results
=
$user
->
save
();
if
(
!
$result
||
!
$results
)
{
Db
::
rollback
();
$this
->
error
(
'绑定微信失败'
);
}
Db
::
commit
();
$this
->
success
(
'成功'
);
}
/**
* @ApiWeigh (76)
* @ApiTitle (加入企业-查询企业)
* @ApiSummary (加入企业-查询企业)
...
...
@@ -928,6 +1106,7 @@ class User extends Api
{
$user
=
\app\mobile\model\User
::
get
(
$this
->
auth
->
id
);
empty
(
$user
[
'image'
])
&&
$this
->
error
(
'请先上传用户头像'
);
empty
(
$user
[
'exam'
])
&&
$this
->
error
(
'请先选择考试'
);
//将用户的头像保存到本地
$user_dir
=
'uploads/user'
;
if
(
!
file_exists
(
$user_dir
)){
...
...
application/mobile/model/UserThird.php
0 → 100644
查看文件 @
17e465e
<?php
namespace
app\mobile\model
;
use
think\Model
;
class
UserThird
extends
Model
{
// 表名
protected
$name
=
'mobile_user_third'
;
// 开启自动写入时间戳字段
protected
$autoWriteTimestamp
=
'int'
;
// 定义时间戳字段名
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
}
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论