diff --git a/app/es/hdl/es.go b/app/es/hdl/es.go new file mode 100644 index 0000000..2e32632 --- /dev/null +++ b/app/es/hdl/es.go @@ -0,0 +1,33 @@ +package hdl + +import ( + "applet/app/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" + "context" + "github.com/olivere/elastic/v7" +) + +func EsSelect(ctx context.Context, index string, query elastic.Query, trackTotalHits bool, arg map[string]string) (*elastic.SearchResult, error) { + if arg["size"] == "" { + arg["size"] = arg["limit"] + } + result, err := es.EsClient.Search(). + Index(index). + TrackTotalHits(trackTotalHits). + Query(query). // 设置查询条件 + Size(utils.StrToInt(arg["size"])). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果 + From((utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])). + Pretty(true). // 返回可读的json格式 + Do(ctx) + return result, err +} +func EsSelectOne(ctx context.Context, index string, query elastic.Query, trackTotalHits bool) (*elastic.SearchResult, error) { + result, err := es.EsClient.Search(). + Index(index). + TrackTotalHits(trackTotalHits). + Query(query). // 设置查询条件 + Size(1). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果 + Pretty(true). // 返回可读的json格式 + Do(ctx) + return result, err +} diff --git a/app/es/md/es.go b/app/es/md/es.go new file mode 100644 index 0000000..a1dae32 --- /dev/null +++ b/app/es/md/es.go @@ -0,0 +1,23 @@ +package md + +const EggUserShortLink = "egg_user_short_link" +const EggUserShortLinkMap = ` +{ + "settings" : { + "number_of_shards" : 2, + "number_of_replicas" : 1 + }, + "mappings":{ + "properties":{ + "uid":{ + "type": "integer" + }, + "link":{ + "type": "keyword" + }, + "short_link":{ + "type": "keyword" + } + } + } +}` diff --git a/app/hdl/hdl_advertising.go b/app/hdl/hdl_advertising.go index 777cd8e..2c872c4 100644 --- a/app/hdl/hdl_advertising.go +++ b/app/hdl/hdl_advertising.go @@ -48,3 +48,18 @@ func AdvertisingDetail(c *gin.Context) { func AdvertisingCheck(c *gin.Context) { svc.AdvertisingCheck(c) } + +// AdvertisingState +// @Summary 广告状态 看完之后拿到广告唯一值 +// @Tags 广告位 +// @Description 广告状态 看完之后拿到广告唯一值 +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Param req body md.AdvertisingReq true "注册参数" +// @Success 200 {object} md.AdvertisingState "具体数据" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/advertising/state [post] +func AdvertisingState(c *gin.Context) { + svc.AdvertisingState(c) +} diff --git a/app/hdl/hdl_callback_advertising.go b/app/hdl/hdl_callback_advertising.go index dc8dddf..0094408 100644 --- a/app/hdl/hdl_callback_advertising.go +++ b/app/hdl/hdl_callback_advertising.go @@ -23,24 +23,13 @@ func CallbackChuanshanjia(c *gin.Context) { sign := c.Query("sign") extra := c.Query("extra") id := gjson.Get(extra, "id").String() - types := gjson.Get(extra, "type").String() phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String()) platform := "chuanshanjia" - NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db) - space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id) - if space == nil { + isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform) + if isEnd == 1 { c.String(200, "{\"is_verify\":true,\"reason\":20000}") return } - spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String() - spaceList := make([]map[string]string, 0) - json.Unmarshal([]byte(spaceData), &spaceList) - spaceKey := "" - for _, v := range spaceList { - if v["id"] == primeRit { //找到对应广告位的key - spaceKey = v["key"] - } - } keyStr := spaceKey + ":" + transId // 1. 使用SHA256算法计算摘要 hash := sha256.Sum256([]byte(keyStr)) @@ -51,10 +40,54 @@ func CallbackChuanshanjia(c *gin.Context) { c.String(200, "{\"is_verify\":true,\"reason\":50002}") return } + isEnds := commDoing(c, platform, transId, userId, extra, primeRit) + if isEnds == 1 { + c.String(200, "{\"is_verify\":true,\"reason\":20000}") + return + } + c.String(200, "{\"is_verify\":true,\"reason\":20000}") + return +} +func CallbackYoulianghui(c *gin.Context) { + userId := c.Query("userid") + transId := c.Query("transid") + primeRit := c.Query("pid") + sign := c.Query("sig") + extra := c.Query("extrainfo") + id := gjson.Get(extra, "id").String() + phonePlatform := strings.ToLower(gjson.Get(extra, "platform").String()) + platform := "youlianghui" + isEnd, spaceKey := comm(c, id, primeRit, platform, phonePlatform) + if isEnd == 1 { + c.String(200, "success") + return + } + keyStr := spaceKey + ":" + transId + // 1. 使用SHA256算法计算摘要 + hash := sha256.Sum256([]byte(keyStr)) + // 2. 将摘要转换为十六进制字符串 + signStr := hex.EncodeToString(hash[:]) + fmt.Println(signStr) + if strings.Contains(signStr, sign) == false { + c.String(200, "success") + return + } + isEnds := commDoing(c, platform, transId, userId, extra, primeRit) + if isEnds == 1 { + c.String(200, "success") + return + } + c.String(200, "success") + return +} + +// 公共处理 +func commDoing(c *gin.Context, platform, transId, userId, extra, primeRit string) int { + types := gjson.Get(extra, "type").String() exist, _ := db.Db.Where("platform=? and oid=?", platform, transId).Exist(&model.AdvertisingCallback{}) if exist { c.String(200, "{\"is_verify\":true,\"reason\":20000}") - return + return 1 } var tmp = model.AdvertisingCallback{ Platform: platform, @@ -83,6 +116,22 @@ func CallbackChuanshanjia(c *gin.Context) { ch.PublishV2(md.EggAdvertisingQueueExchange, arg, md.EggAdvertisingSign) } } - c.String(200, "{\"is_verify\":true,\"reason\":20000}") - return + return 0 +} +func comm(c *gin.Context, id, primeRit, platform, phonePlatform string) (int, string) { + NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db) + space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(id) + if space == nil { + return 1, "" + } + spaceData := gjson.Get(space.Info, platform+"."+phonePlatform+"_ad_id").String() + spaceList := make([]map[string]string, 0) + json.Unmarshal([]byte(spaceData), &spaceList) + spaceKey := "" + for _, v := range spaceList { + if v["id"] == primeRit { //找到对应广告位的key + spaceKey = v["key"] + } + } + return 0, spaceKey } diff --git a/app/hdl/hdl_user.go b/app/hdl/hdl_user.go index bc1d228..97e9277 100644 --- a/app/hdl/hdl_user.go +++ b/app/hdl/hdl_user.go @@ -3,13 +3,23 @@ package hdl import ( "applet/app/db" "applet/app/e" + "applet/app/es/hdl" + md2 "applet/app/es/md" "applet/app/md" "applet/app/svc" "applet/app/utils" + "applet/app/utils/qrcode" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/kuaizhan" + "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" + "context" "github.com/gin-gonic/gin" + "github.com/olivere/elastic/v7" "github.com/syyongx/php2go" + "github.com/tidwall/gjson" + "strings" ) // UserInfo @@ -172,3 +182,135 @@ func UserBindParent(c *gin.Context) { e.OutSuc(c, "success", nil) return } + +// UpdatePassword +// @Summary 修改密码-不要原密码 换成验证码 +// @Tags 账号与安全 +// @Description 修改密码 +// @Accept json +// @Produce json +// @Param req body md.UpdatePasswordReq true "注册参数" +// @Success 200 string "登录成功返回" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/memberCenter/updatePassword [post] +func UpdatePassword(c *gin.Context) { + var req md.UpdatePasswordReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = svc.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + user := svc.GetUser(c) + data := svc.AliyunSmsBase(c, "") + //校验短信 + err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code) + if err != nil { + e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试")) + return + } + user.Password = utils.Md5(req.Password) + db.Db.Where("id=?", user.Id).Cols("password").Update(user) + e.OutSuc(c, "success", nil) + return +} + +// UpdatePasscode +// @Summary 修改支付宝密码 +// @Tags 账号与安全 +// @Description 修改支付宝密码 +// @Accept json +// @Produce json +// @Param req body md.UpdatePasscodeReq true "注册参数" +// @Success 200 string "登录成功返回" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/memberCenter/updatePasscode [post] +func UpdatePasscode(c *gin.Context) { + var req md.UpdatePasscodeReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = svc.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + user := svc.GetUser(c) + data := svc.AliyunSmsBase(c, "") + //校验短信 + err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code) + if err != nil { + e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试")) + return + } + user.Passcode = utils.Md5(req.PassCode) + db.Db.Where("id=?", user.Id).Cols("passcode").Update(user) + e.OutSuc(c, "success", nil) + return +} + +// InviteUrl +// @Summary 邀请链接 +// @Tags 邀请海报 +// @Description 邀请链接 +// @Accept json +// @Produce json +// @Success 200 {object} md.InviteUrl "登录成功返回" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/memberCenter/inviteUrl [get] +func InviteUrl(c *gin.Context) { + user := svc.GetUser(c) + + link := svc.GetSysCfgStr("kuaizhan_url") + res := md.InviteUrl{ + Link: "", + InviteCode: user.SystemInviteCode, + } + if user.CustomInviteCode != "" { + res.InviteCode = user.CustomInviteCode + } + link += "?inviteCode=" + res.InviteCode + EggUserShortLink := md2.EggUserShortLink + boolQueryToItem := elastic.NewBoolQuery() // 创建bool查询 + aggsMatch := elastic.NewMatchQuery("link", link) //设置查询条件 + boolQueryToItem.Must(aggsMatch) + result, _ := hdl.EsSelectOne(context.Background(), EggUserShortLink, boolQueryToItem, false) + isHas := 0 + if result != nil && len(result.Hits.Hits) > 0 { + for _, hit := range result.Hits.Hits { + if hit == nil { + continue + } + jsonByte, _ := hit.Source.MarshalJSON() + if gjson.Get(string(jsonByte), "short_link").String() != "" { + isHas = 1 + link = gjson.Get(string(jsonByte), "short_link").String() + } + } + } + if isHas == 0 { + send, _ := kuaizhan.KuaizhanSend(svc.GetSysCfgStr("kuaizhan_app_key"), svc.GetSysCfgStr("kuaizhan_app_secret"), link) + if gjson.Get(send, "url").String() != "" { + var uniqueId = php2go.Md5(link) + oldLink := link + link = gjson.Get(send, "url").String() + tmp := map[string]interface{}{ + "uid": user.Id, + "link": oldLink, + "short_link": link, + } + doc, _ := es.FirstDoc(EggUserShortLink, uniqueId) + if doc == nil { + es.CreateDoc(EggUserShortLink, uniqueId, tmp) + } else { + es.UpdateDoc(EggUserShortLink, uniqueId, tmp) + } + } + } + res.Link = link + QRcode := qrcode.GetPNGBase64(link) + QRcode = strings.ReplaceAll(QRcode, "\u0000", "") + res.Qrcode = QRcode + e.OutSuc(c, res, nil) + return +} diff --git a/app/md/md_advertising.go b/app/md/md_advertising.go index dc4f3f1..69e372c 100644 --- a/app/md/md_advertising.go +++ b/app/md/md_advertising.go @@ -27,6 +27,9 @@ type AdvertisingSpace struct { type AdvertisingCheck struct { IsCanVisit string `json:"is_can_visit"` } +type AdvertisingState struct { + IsSuccess string `json:"is_success"` +} type AdvertisingFunction struct { Name string `json:"name" example:"名称"` Type string `json:"type" example:"位置"` diff --git a/app/md/md_login.go b/app/md/md_login.go index 81bcea4..e124d07 100644 --- a/app/md/md_login.go +++ b/app/md/md_login.go @@ -2,7 +2,7 @@ package md type SmsSendReq struct { Mobile string `json:"mobile" binding:"required"` - Type string `json:"type" example:"h5Register:h5注册页、wechatBindPhone:微信绑定手机、login:登陆、findPwd:找回密码、changePwd:修改密码"` + Type string `json:"type" example:"h5Register:h5注册页、wechatBindPhone:微信绑定手机、login:登陆、findPwd:找回密码、changePwd:修改密码、changePasscode:修改支付密码"` LotNumber string `json:"lot_number" example:"阿里云图形验证码对应参数"` GenTime string `json:"gen_time" example:"阿里云图形验证码对应参数"` CaptchaOutput string `json:"captcha_output" example:"阿里云图形验证码对应参数"` @@ -26,6 +26,14 @@ type FindPasswordReq struct { Code string `json:"code" example:"验证码"` Password string `json:"password" example:"密码 如 123"` } +type UpdatePasswordReq struct { + Code string `json:"code" example:"验证码"` + Password string `json:"password" example:"密码 如 123"` +} +type UpdatePasscodeReq struct { + Code string `json:"code" example:"验证码"` + PassCode string `json:"passcode" example:"密码 如 123"` +} type WechatLoginReq struct { OpenID string `json:"open_id" example:"微信openId"` UnionId string `json:"union_id" example:"微信UnionId"` @@ -46,3 +54,8 @@ type LoginReq struct { type LoginResponse struct { Token string `json:"token"` } +type InviteUrl struct { + Link string `json:"link"` + InviteCode string `json:"invite_code"` + Qrcode string `json:"qrcode"` +} diff --git a/app/router/router.go b/app/router/router.go index b40d378..a286369 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -57,6 +57,7 @@ func route(r *gin.RouterGroup) { rCallback := r.Group("/callback") { rCallback.GET("/advertising/chuanshanjia", hdl.CallbackChuanshanjia) //穿山甲广告回调 + rCallback.GET("/advertising/youlianghui", hdl.CallbackYoulianghui) //优量汇广告回调 } r.Use(mw.CheckSign) @@ -80,7 +81,11 @@ func route(r *gin.RouterGroup) { r.GET("/getModuleSetting", hdl.GetModuleSetting) // 获取页面样式 r.Use(mw.Auth) // 以下接口需要JWT验证 rComm(r.Group("/comm")) - r.POST("/advertising/check", hdl.AdvertisingCheck) //广告位判断能不能看 + + { + r.POST("/advertising/check", hdl.AdvertisingCheck) //广告位判断能不能看 + r.POST("/advertising/state", hdl.AdvertisingState) //广告位状态 + } rHomePage := r.Group("/homePage") { @@ -102,8 +107,11 @@ func route(r *gin.RouterGroup) { } rMemberCenter := r.Group("/memberCenter") { - rMemberCenter.GET("/getBasic", hdl.MemberCenterGetBasic) // 会员中心-基础数据 - rMemberCenter.POST("/bindParent", hdl.UserBindParent) //绑定上级 + rMemberCenter.GET("/getBasic", hdl.MemberCenterGetBasic) // 会员中心-基础数据 + rMemberCenter.POST("/bindParent", hdl.UserBindParent) //绑定上级 + rMemberCenter.POST("/updatePassword", hdl.UpdatePassword) //修改密码 + rMemberCenter.POST("/updatePasscode", hdl.UpdatePasscode) //修改支付密码 + rMemberCenter.GET("/inviteUrl", hdl.InviteUrl) //邀请链接 } rPointsCenter := r.Group("/pointsCenter") // 积分中心 { diff --git a/app/svc/svc_advertising.go b/app/svc/svc_advertising.go index 1fd3162..2f45d18 100644 --- a/app/svc/svc_advertising.go +++ b/app/svc/svc_advertising.go @@ -6,6 +6,7 @@ import ( "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "encoding/json" "fmt" "github.com/gin-gonic/gin" @@ -115,6 +116,27 @@ func AdvertisingCheck(c *gin.Context) { e.OutSuc(c, res, nil) return } +func AdvertisingState(c *gin.Context) { + var req md.AdvertisingReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + isSuccess := "0" + var data model.AdvertisingCallback + db.Db.Where("oid=? ", req.Id).Get(&data) + if data.Id > 0 { + isSuccess = "1" + } + res := md.AdvertisingState{ + IsSuccess: isSuccess, + } + e.OutSuc(c, res, nil) + return +} func AdvertisingDetail(c *gin.Context) { eg := db.Db var req md.AdvertisingReq diff --git a/go.mod b/go.mod index 064f1f1..cb4c67f 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( require ( code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128030209-743f36ef9dad - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241128063602-ed11b9dad994 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241128075251-3c7f4a91e52c code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible