...
|
...
|
@@ -4,16 +4,17 @@ import ( |
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
"html/template"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
|
|
|
"ability/internal/repository"
|
|
|
"ability/models"
|
|
|
"ability/protocol"
|
|
|
s_sms "ability/services/sms"
|
|
|
s_im "ability/services/im"
|
|
|
s_sms "ability/services/sms"
|
|
|
|
|
|
"github.com/astaxie/beego"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
...
|
...
|
@@ -40,7 +41,7 @@ func assertImplement() { |
|
|
|
|
|
var (
|
|
|
//服务
|
|
|
sms s_sms.ISmsService = &s_sms.YunPianSmsService{}
|
|
|
sms s_sms.ISmsService = &s_sms.YunPianSmsService{}
|
|
|
ConfigRepository repository.IConfigRepository = &repository.ConfigRepository{}
|
|
|
//仓储
|
|
|
UserRepository repository.IUserRepository = &repository.UserRepository{}
|
...
|
...
|
@@ -49,9 +50,9 @@ var ( |
|
|
//登录
|
|
|
func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
|
|
var (
|
|
|
user *models.Users
|
|
|
userInfo *models.UserInfo
|
|
|
result bool
|
|
|
user *models.Users
|
|
|
userInfo *models.UserInfo
|
|
|
result bool
|
|
|
checkImResponse *protocol.CheckImResponse
|
|
|
)
|
|
|
user, err = UserRepository.GetUsersByMobile(request.Phone)
|
...
|
...
|
@@ -89,19 +90,19 @@ Success: |
|
|
if userInfo.Auth == "" {
|
|
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
|
|
}
|
|
|
if checkImResponse,err=CheckIm(&protocol.CheckImRequest{
|
|
|
Uid:fmt.Sprintf("%v",userInfo.Id),
|
|
|
Uname:userInfo.Uname,
|
|
|
Icon:userInfo.Icon,
|
|
|
IsCreated:userInfo.ImToken=="",
|
|
|
});err!=nil{
|
|
|
if checkImResponse, err = CheckIm(&protocol.CheckImRequest{
|
|
|
Uid: fmt.Sprintf("%v", userInfo.Id),
|
|
|
Uname: userInfo.Uname,
|
|
|
Icon: userInfo.Icon,
|
|
|
IsCreated: userInfo.ImToken == "",
|
|
|
}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
userInfo.ImToken = checkImResponse.ImToken
|
|
|
if userInfo.CsAccount==0{
|
|
|
if userInfo.CsAccount == 0 {
|
|
|
userInfo.CsAccount = checkImResponse.CsAccount
|
|
|
}
|
|
|
userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
|
|
userInfo.AuthExp = time.Now().Add(time.Second * protocol.TokenExpire)
|
|
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -149,7 +150,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
//刷新token
|
|
|
func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
|
|
var (
|
|
|
userInfo *models.UserInfo
|
|
|
userInfo *models.UserInfo
|
|
|
)
|
|
|
_, err = ConfigRepository.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
if err != nil {
|
...
|
...
|
@@ -326,93 +327,92 @@ Fail: |
|
|
return
|
|
|
}
|
|
|
|
|
|
func CheckIm(request *protocol.CheckImRequest)(rsp *protocol.CheckImResponse,err error){
|
|
|
var (
|
|
|
|
|
|
)
|
|
|
func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) {
|
|
|
var ()
|
|
|
if beego.BConfig.RunMode != "prod" {
|
|
|
return
|
|
|
}
|
|
|
rsp =&protocol.CheckImResponse{}
|
|
|
if !request.IsCreated{
|
|
|
if err = imUserCreate(request,rsp);err!=nil{
|
|
|
rsp = &protocol.CheckImResponse{}
|
|
|
if !request.IsCreated {
|
|
|
if err = imUserCreate(request, rsp); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}else{
|
|
|
if err = imUserInfoUpdate(request,rsp);err!=nil{
|
|
|
} else {
|
|
|
if err = imUserInfoUpdate(request, rsp); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if err = imUserRefreshToken(request,rsp);err!=nil{
|
|
|
if err = imUserRefreshToken(request, rsp); err != nil {
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//create
|
|
|
func imUserCreate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
var(
|
|
|
param s_im.UserCreate=s_im.UserCreate{
|
|
|
Accid:request.Uid,
|
|
|
Name:request.Uname,
|
|
|
Icon:request.Icon,
|
|
|
func imUserCreate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
var (
|
|
|
param s_im.UserCreate = s_im.UserCreate{
|
|
|
Accid: request.Uid,
|
|
|
Name: request.Uname,
|
|
|
Icon: request.Icon,
|
|
|
}
|
|
|
resp []byte
|
|
|
out s_im.UserCreateResult
|
|
|
out s_im.UserCreateResult
|
|
|
)
|
|
|
if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
if err = json.Unmarshal(resp, &out); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
|
|
if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
|
|
return s_im.ErrorFailCall
|
|
|
}
|
|
|
rsp.ImToken = out.Info.Token
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//update user info
|
|
|
func imUserInfoUpdate(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
var(
|
|
|
param s_im.UserUpdateUinfo=s_im.UserUpdateUinfo{
|
|
|
Accid:request.Uid,
|
|
|
Name:request.Uname,
|
|
|
Icon:request.Icon,
|
|
|
func imUserInfoUpdate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
var (
|
|
|
param s_im.UserUpdateUinfo = s_im.UserUpdateUinfo{
|
|
|
Accid: request.Uid,
|
|
|
Name: request.Uname,
|
|
|
Icon: request.Icon,
|
|
|
}
|
|
|
resp []byte
|
|
|
out s_im.BaseResp
|
|
|
out s_im.BaseResp
|
|
|
)
|
|
|
if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
if err = json.Unmarshal(resp, &out); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if out.Code!=200{
|
|
|
if out.Code != 200 {
|
|
|
return s_im.ErrorFailCall
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//refresh token
|
|
|
func imUserRefreshToken(request *protocol.CheckImRequest,rsp *protocol.CheckImResponse)(err error){
|
|
|
var(
|
|
|
param s_im.UserRefreshToken=s_im.UserRefreshToken{
|
|
|
Accid:request.Uid,
|
|
|
func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) {
|
|
|
var (
|
|
|
param s_im.UserRefreshToken = s_im.UserRefreshToken{
|
|
|
Accid: request.Uid,
|
|
|
}
|
|
|
resp []byte
|
|
|
out s_im.UserCreateResult
|
|
|
out s_im.UserCreateResult
|
|
|
)
|
|
|
if resp,err=s_im.DefaultImClient.Call(param);err!=nil{
|
|
|
if resp, err = s_im.DefaultImClient.Call(param); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal(resp,&out);err!=nil{
|
|
|
if err = json.Unmarshal(resp, &out); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if out.Code!=200 || (out.Info.Accid!=request.Uid){
|
|
|
if out.Code != 200 || (out.Info.Accid != request.Uid) {
|
|
|
return s_im.ErrorFailCall
|
|
|
}
|
|
|
rsp.ImToken = out.Info.Token
|
|
|
return
|
|
|
} |
|
|
|
|
|
|
...
|
...
|
|