登录联调
This commit is contained in:
parent
1d9bd5b179
commit
c5eadb85b4
|
@ -10,6 +10,7 @@ WORKDIR /app
|
||||||
|
|
||||||
# 设置环境变量
|
# 设置环境变量
|
||||||
ENV GOPROXY=https://goproxy.cn,direct
|
ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
# 复制项目源码
|
# 复制项目源码
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
|
@ -46,6 +46,8 @@ const (
|
||||||
InsertUserFail = 3001
|
InsertUserFail = 3001
|
||||||
//邮储code解析失败
|
//邮储code解析失败
|
||||||
YouChuCodeFail = 4001
|
YouChuCodeFail = 4001
|
||||||
|
//客户号为空
|
||||||
|
YouChuCustNoEmpty = 4002
|
||||||
)
|
)
|
||||||
|
|
||||||
var MsgEN = map[int]string{
|
var MsgEN = map[int]string{
|
||||||
|
@ -75,6 +77,7 @@ var MsgZH = map[int]string{
|
||||||
InsertUserFail: "用户新增失败",
|
InsertUserFail: "用户新增失败",
|
||||||
Fail: "请求失败",
|
Fail: "请求失败",
|
||||||
YouChuCodeFail: "Code解析失败",
|
YouChuCodeFail: "Code解析失败",
|
||||||
|
YouChuCustNoEmpty: "客户编号为空",
|
||||||
}
|
}
|
||||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||||
|
|
||||||
|
|
|
@ -185,8 +185,9 @@ func GetUserId(c *gin.Context) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserPhone(c *gin.Context) string {
|
// GetUserCustNo 获取用户custNo
|
||||||
userIdStr, _ := c.Get("phone")
|
func GetUserCustNo(c *gin.Context) string {
|
||||||
|
userIdStr, _ := c.Get("custNo")
|
||||||
if userIdStr != nil {
|
if userIdStr != nil {
|
||||||
var userId, _ = userIdStr.(string)
|
var userId, _ = userIdStr.(string)
|
||||||
return userId
|
return userId
|
||||||
|
|
|
@ -18,16 +18,14 @@ import (
|
||||||
|
|
||||||
func CreateOrder(c *gin.Context) {
|
func CreateOrder(c *gin.Context) {
|
||||||
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
|
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
|
||||||
//userId := controllers.GetUserId(c)
|
userId := controllers.GetUserId(c)
|
||||||
userId := 1
|
|
||||||
code, data := services.CreateOrderService(userId, request.ProductId)
|
code, data := services.CreateOrderService(userId, request.ProductId)
|
||||||
controllers.HandCodeRes(c, data, code)
|
controllers.HandCodeRes(c, data, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OrderList(c *gin.Context) {
|
func OrderList(c *gin.Context) {
|
||||||
var request = controllers.GetRequest(c).(*front.OrderListRequest)
|
var request = controllers.GetRequest(c).(*front.OrderListRequest)
|
||||||
//userId := controllers.GetUserId(c)
|
userId := controllers.GetUserId(c)
|
||||||
userId := 1
|
|
||||||
code, orderList, count := services.OrderQueryService(userId, request)
|
code, orderList, count := services.OrderQueryService(userId, request)
|
||||||
var rsp []front.OrderListResponse
|
var rsp []front.OrderListResponse
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
|
|
@ -5,7 +5,7 @@ type UnionLoginRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
Token string
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type YouChuDecryptData struct {
|
type YouChuDecryptData struct {
|
||||||
|
|
|
@ -31,7 +31,7 @@ func Auth() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Set("userId", claims.Id)
|
c.Set("userId", claims.Id)
|
||||||
c.Set("phone", claims.Phone)
|
c.Set("custNo", claims.CustNo)
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,8 +58,8 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
v1.POST("/product/detail", front.ProductDetail)
|
v1.POST("/product/detail", front.ProductDetail)
|
||||||
|
|
||||||
//auth
|
//auth
|
||||||
auth := v1.Group("auth")
|
//auth := v1.Group("auth")
|
||||||
//auth := v1.Group("auth", middlewares.Auth())
|
auth := v1.Group("auth", middlewares.Auth())
|
||||||
{
|
{
|
||||||
order := auth.Group("/order")
|
order := auth.Group("/order")
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,21 +20,20 @@ func YouChuLogin(req *front.UnionLoginRequest) (code int, login front.LoginRespo
|
||||||
}
|
}
|
||||||
if YouChuResponse.RespCode == "000000" {
|
if YouChuResponse.RespCode == "000000" {
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
var user usersmodel.Users
|
user := usersmodel.Users{}
|
||||||
err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Find(&user)
|
has, _ := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Get(&user)
|
||||||
code = handErr(err)
|
if !has && YouChuResponse.CustNo != "" {
|
||||||
if user.Id == "" {
|
|
||||||
user.CustNo = YouChuResponse.CustNo
|
user.CustNo = YouChuResponse.CustNo
|
||||||
user.Status = strconv.Itoa(common.STATUSABLED)
|
user.Status = strconv.Itoa(common.STATUSABLED)
|
||||||
user.CreateTime = time.Now()
|
user.CreateTime = time.Now()
|
||||||
_, err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Insert(&user)
|
_, err := usersmodel.GetInstance().GetDb().Insert(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorcode.InsertUserFail, front.LoginResponse{}
|
return errorcode.InsertUserFail, front.LoginResponse{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
login.Token = utils.GeneratorJwtToken(utils.User{
|
login.Token = utils.GeneratorJwtToken(utils.User{
|
||||||
Id: user.Id,
|
Id: user.Id,
|
||||||
Phone: user.CustNo,
|
CustNo: user.CustNo,
|
||||||
})
|
})
|
||||||
return errorcode.Success, login
|
return errorcode.Success, login
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,6 +39,7 @@ func (this *YouChuClient) Login(code string) (Code int, response front.YouChuLog
|
||||||
}
|
}
|
||||||
requestData := EncryptRequest(request)
|
requestData := EncryptRequest(request)
|
||||||
bytes, err := json.Marshal(requestData)
|
bytes, err := json.Marshal(requestData)
|
||||||
|
utils.Log(nil, "YouChuLoginRequest", string(bytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorcode.SystemError, response
|
return errorcode.SystemError, response
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,8 +372,8 @@ func IsNil(x interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id string
|
Id string
|
||||||
Phone string
|
CustNo string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GeneratorJwtToken(user User) string {
|
func GeneratorJwtToken(user User) string {
|
||||||
|
@ -382,9 +382,9 @@ func GeneratorJwtToken(user User) string {
|
||||||
|
|
||||||
// 创建一个MapClaims对象,用于存放自定义的声明信息
|
// 创建一个MapClaims对象,用于存放自定义的声明信息
|
||||||
claims := jwt.MapClaims{
|
claims := jwt.MapClaims{
|
||||||
"id": user.Id,
|
"id": user.Id,
|
||||||
"phone": user.Phone,
|
"custNo": user.CustNo,
|
||||||
"exp": time.Now().Add(time.Hour * 24).Unix(), // 设置过期时间为24小时后
|
"exp": time.Now().Add(time.Hour * 24).Unix(), // 设置过期时间为24小时后
|
||||||
}
|
}
|
||||||
// 使用HS256算法创建一个Token对象
|
// 使用HS256算法创建一个Token对象
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
|
@ -399,8 +399,8 @@ func GeneratorJwtToken(user User) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
Id int
|
Id string
|
||||||
Phone string
|
CustNo string
|
||||||
jwt.StandardClaims
|
jwt.StandardClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue