Răsfoiți Sursa

新增获取用户详情接口

rdluck 4 ani în urmă
părinte
comite
53e3fc8d57
5 a modificat fișierele cu 128 adăugiri și 21 ștergeri
  1. 51 0
      controllers/user.go
  2. 50 0
      controllers/wechat.go
  3. 20 19
      models/wx_user.go
  4. 5 0
      routers/router.go
  5. 2 2
      utils/config.go

+ 51 - 0
controllers/user.go

@@ -0,0 +1,51 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+)
+
+//用户
+type UserController struct {
+	BaseAuthController
+}
+
+// @Title 获取用户详情
+// @Description 获取用户详情接口
+// @Success 200 {object} models.UserDetail
+// @router /detail [get]
+func (this *UserController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	item, err := models.GetUserDetailByUserId(user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = item
+}
+
+/*
+$app->get('api/user/getSmsCode',"UserController@getSmsCode");//获取短信验证码
+$app->post('api/user/checkSmsCode',"UserController@checkSmsCode");//校验短信验证码
+$app->get('api/user/getEmailCode',"UserController@getEmailCode");//获取邮件验证码
+$app->post('api/user/checkEmailCode',"UserController@checkEmailCode");//校验邮件验证码
+$app->post('api/user/login',"UserController@login");//登录
+$app->post('api/user/apply',"UserController@apply");//申请试用
+$app->get('api/user/smallLimit',"UserController@smallLimit");//是否小套餐客户
+$app->get('api/user/detail',"UserController@detail");//获取用户详情
+*/

+ 50 - 0
controllers/wechat.go

@@ -2,11 +2,15 @@ package controllers
 
 import (
 	"fmt"
+	//"github.com/silenceper/wechat"
+	//"github.com/silenceper/wechat/cache"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
 	"hongze/hongze_api/utils"
 	"strconv"
 	"time"
+
+	//offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
 )
 
 type WechatController struct {
@@ -148,6 +152,52 @@ func (this *WechatCommonController) WechatLogin() {
 	br.Data = resp
 }
 
+//
+//// @Title 微信登录接口
+//// @Description 微信登录接口
+//// @Param   Url   query   string  true       "url地址"
+//// @Success 200 {object} models.WxLoginResp
+//// @router /getWxSign [get]
+//func (this *WechatController) GetWxSign() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//	getUrl := this.GetString("Url")
+//
+//	accessToken, err := services.WxGetAccessToken()
+//	if err != nil {
+//		br.Msg = "获取用户信息失败"
+//		br.ErrMsg = "获取access_token失败,err:" + err.Error()
+//		return
+//	}
+//
+//	wc := wechat.NewWechat()
+//	memory := cache.NewMemory()
+//
+//	cfg := &offConfig.Config{
+//		AppID:     utils.WxAppId,
+//		AppSecret: utils.WxAppSecret,
+//		Token:     accessToken,
+//		Cache: memory,
+//	}
+//	oa := wc.GetOfficialAccount(cfg)
+//	j:=oa.GetJs()
+//	config,err:=j.GetConfig(getUrl)
+//	if err!=nil {
+//		fmt.Println("获取失败:Err:"+err.Error())
+//		return
+//	}
+//	fmt.Println(config)
+//	resp := new(models.WxLoginResp)
+//	br.Ret = 200
+//	br.Success = true
+//	br.Msg = "获取签名成功"
+//	br.Data = resp
+//}
+
+
 
 /*
 $app->bag('api/wechat/getWxSign',"WechatController@getWxSign");

+ 20 - 19
models/wx_user.go

@@ -101,25 +101,26 @@ func AddWxUser(item *WxUser) (err error) {
 	return
 }
 
-/*
- return response()->json(['code'=>'0',
-                                     'data'=>array(
-                                        'open_id'=>$open_id,
-                                        'rddp_access_token'=>$session_data->access_token,
-                                        'user_id'=>$userId,
-                                        'expires'=>$session_data->expire_time,
-                                        'first_login'=>$firstLogin,
-                                        'user_permission'=>$userPermission,
-                                      )
-                                    ]);
-*/
-
 type WxLoginResp struct {
-	Code          int
-	OpenId        string
-	Authorization string
-	UserId        int
-	Expires       time.Time
-	FirstLogin    int
+	Code           int
+	OpenId         string
+	Authorization  string
+	UserId         int
+	Expires        time.Time
+	FirstLogin     int
 	UserPermission int
 }
+
+type UserDetail struct {
+	FirstLogin int    `description:"是否第一次登陆"`
+	Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Mobile     string `description:"手机号码"`
+	Email      string `description:"邮箱"`
+}
+
+func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT first_login,headimgurl,mobile,email FROM wx_user WHERE user_id = ? `
+	err = o.Raw(sql, userId).QueryRow(&item)
+	return
+}

+ 5 - 0
routers/router.go

@@ -46,6 +46,11 @@ func init() {
 				&controllers.WechatCommonController{},
 			),
 		),
+		beego.NSNamespace("/user",
+			beego.NSInclude(
+				&controllers.UserController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 2 - 2
utils/config.go

@@ -54,5 +54,5 @@ func init() {
 	}
 }
 
-//http://adminapi.brilliantstart.cn/admin/
-//http://adminapi.brilliantstart.cn/swagger/
+//http://webapi.brilliantstart.cn/api/
+//http://webapi.brilliantstart.cn/swagger/