作者 yangfu

登录修改

@@ -18,6 +18,9 @@ service Core { @@ -18,6 +18,9 @@ service Core {
18 @handler miniUserApplyJoinCompany 18 @handler miniUserApplyJoinCompany
19 post /mini/user/apply_join_company(MiniUserApplyJoinCompanyRequest) returns (MiniUserApplyJoinCompanyResponse) 19 post /mini/user/apply_join_company(MiniUserApplyJoinCompanyRequest) returns (MiniUserApplyJoinCompanyResponse)
20 @doc "用户登录" 20 @doc "用户登录"
  21 + @handler miniUserWXLogin
  22 + post /mini/user/wx-login (MiniUserLoginRequest) returns (MiniUserLoginResponse)
  23 + @doc "用户登录"
21 @handler miniUserLogin 24 @handler miniUserLogin
22 post /mini/user/login (MiniUserLoginRequest) returns (MiniUserLoginResponse) 25 post /mini/user/login (MiniUserLoginRequest) returns (MiniUserLoginResponse)
23 } 26 }
@@ -75,6 +78,16 @@ service Core { @@ -75,6 +78,16 @@ service Core {
75 } 78 }
76 79
77 type( 80 type(
  81 + MiniUserWXLoginRequest {
  82 + Code string `json:"code"` // 授权码
  83 + }
  84 + MiniUserLoginResponse {
  85 + SessionKey string `json:"sessionKey"`
  86 + OpenId string `json:"openId"`
  87 + }
  88 +)
  89 +
  90 +type(
78 MiniUserLoginRequest { 91 MiniUserLoginRequest {
79 LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login 92 LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
80 WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 93 WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
@@ -7,7 +7,7 @@ Timeout: 30000 @@ -7,7 +7,7 @@ Timeout: 30000
7 # CertFile: ./key/fjmaimaimai.com_bundle.crt 7 # CertFile: ./key/fjmaimaimai.com_bundle.crt
8 # KeyFile: ./key/fjmaimaimai.com.key 8 # KeyFile: ./key/fjmaimaimai.com.key
9 Log: 9 Log:
10 - Mode: file 10 + #Mode: file
11 Encoding: plain 11 Encoding: plain
12 Level: debug # info 12 Level: debug # info
13 MaxSize: 1 # 2MB 13 MaxSize: 1 # 2MB
@@ -32,3 +32,7 @@ ApiAuth: @@ -32,3 +32,7 @@ ApiAuth:
32 Name: ApiAuth 32 Name: ApiAuth
33 Host: http://digital-platform-dev.fjmaimaimai.com 33 Host: http://digital-platform-dev.fjmaimaimai.com
34 Timeout: 0s 34 Timeout: 0s
  35 +
  36 +Wechat:
  37 + AppID: wxae5b305849343ec8
  38 + AppSecret: f584adb68f7d784425b60e1ebb2ffd4b
@@ -63,6 +63,7 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res @@ -63,6 +63,7 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res
63 Success: true, 63 Success: true,
64 } 64 }
65 if loginInfo.User == nil { 65 if loginInfo.User == nil {
  66 + resp.Token = ""
66 resp.Success = false 67 resp.Success = false
67 } 68 }
68 return 69 return
@@ -88,6 +89,9 @@ type WxClientLogin struct { @@ -88,6 +89,9 @@ type WxClientLogin struct {
88 89
89 func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) { 90 func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) {
90 code := r.Code 91 code := r.Code
  92 + response := &domain.LoginInfo{
  93 + Phone: "",
  94 + }
91 miniprogram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{ 95 miniprogram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
92 AppID: c.l.svcCtx.Config.Wechat.AppID, 96 AppID: c.l.svcCtx.Config.Wechat.AppID,
93 AppSecret: c.l.svcCtx.Config.Wechat.AppSecret, 97 AppSecret: c.l.svcCtx.Config.Wechat.AppSecret,
@@ -95,7 +99,7 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo @@ -95,7 +99,7 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo
95 }) 99 })
96 authResult, err := miniprogram.GetAuth().GetPhoneNumber(code) 100 authResult, err := miniprogram.GetAuth().GetPhoneNumber(code)
97 if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" { 101 if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" {
98 - return nil, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult)) 102 + return response, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult))
99 } 103 }
100 var ( 104 var (
101 users []*domain.User 105 users []*domain.User
@@ -106,11 +110,9 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo @@ -106,11 +110,9 @@ func (c WxClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.Lo
106 MustWithKV("phone", phone). 110 MustWithKV("phone", phone).
107 MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) 111 MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
108 if err != nil { 112 if err != nil {
109 - return nil, err  
110 - }  
111 - response := &domain.LoginInfo{  
112 - Phone: phone, 113 + return response, err
113 } 114 }
  115 + response.Phone = phone
114 if len(users) != 0 { 116 if len(users) != 0 {
115 response.User = users[0] 117 response.User = users[0]
116 } 118 }