|
@@ -2,7 +2,6 @@ package share
|
|
|
|
|
|
import (
|
|
import (
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
- se "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/message/config"
|
|
"app.yhyue.com/moapp/message/config"
|
|
"app.yhyue.com/moapp/message/db"
|
|
"app.yhyue.com/moapp/message/db"
|
|
@@ -11,9 +10,8 @@ import (
|
|
"github.com/SKatiyar/qr"
|
|
"github.com/SKatiyar/qr"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
"log"
|
|
"log"
|
|
- "net/url"
|
|
|
|
- "regexp"
|
|
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -61,8 +59,9 @@ func (c *ShareRouter) Info(r *ghttp.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
func (c *ShareRouter) Receive(r *ghttp.Request) {
|
|
func (c *ShareRouter) Receive(r *ghttp.Request) {
|
|
- openid := se.SE.DecodeString(r.Get("oid").String()) //被分享者openid
|
|
|
|
- if db.Mgo.Count("user", map[string]interface{}{"s_m_openid": openid, "i_appid": 2}) > 0 {
|
|
|
|
|
|
+ userid := r.Header.Get("userId") //被分享者userid
|
|
|
|
+ uid, _ := primitive.ObjectIDFromHex(userid)
|
|
|
|
+ if db.Mgo.Count("user", map[string]interface{}{"_id": uid, "i_appid": 2}) > 0 {
|
|
r.Response.WriteJson(g.Map{
|
|
r.Response.WriteJson(g.Map{
|
|
"error_code": -1,
|
|
"error_code": -1,
|
|
"error_msg": "老用户无法领取奖励",
|
|
"error_msg": "老用户无法领取奖励",
|
|
@@ -73,8 +72,8 @@ func (c *ShareRouter) Receive(r *ghttp.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
shareId := r.Get("shareId").String()
|
|
shareId := r.Get("shareId").String()
|
|
- redisKey := fmt.Sprintf("rec_%s", openid)
|
|
|
|
- log.Println(openid, shareId, redisKey) //分享者和被分享者对应关系
|
|
|
|
|
|
+ redisKey := fmt.Sprintf("rec_%s", userid)
|
|
|
|
+ log.Println(userid, shareId, redisKey) //分享者和被分享者对应关系
|
|
shareUserid := redis.GetStr("other", shareId) //获取分享者
|
|
shareUserid := redis.GetStr("other", shareId) //获取分享者
|
|
if shareUserid == "" {
|
|
if shareUserid == "" {
|
|
r.Response.WriteJson(g.Map{
|
|
r.Response.WriteJson(g.Map{
|
|
@@ -99,6 +98,9 @@ func (c *ShareRouter) List(r *ghttp.Request) {
|
|
userid := r.Header.Get("userId")
|
|
userid := r.Header.Get("userId")
|
|
pNum := r.Get("pageNum").Int()
|
|
pNum := r.Get("pageNum").Int()
|
|
pSize := r.Get("pagesize").Int()
|
|
pSize := r.Get("pagesize").Int()
|
|
|
|
+ if pSize == 0 {
|
|
|
|
+ pSize = 5
|
|
|
|
+ }
|
|
rdata := map[string]interface{}{
|
|
rdata := map[string]interface{}{
|
|
"count": 0,
|
|
"count": 0,
|
|
"haveNextPage": false,
|
|
"haveNextPage": false,
|
|
@@ -130,96 +132,41 @@ func (c *ShareRouter) List(r *ghttp.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
func (c *ShareRouter) Followgift(r *ghttp.Request) {
|
|
func (c *ShareRouter) Followgift(r *ghttp.Request) {
|
|
- client := r.Header.Get("User-Agent")
|
|
|
|
- var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
|
|
|
|
- Wxoauth := `https://open.weixin.qq.com/connect/oauth2/authorize?appid=` + qu.ObjToString(config.Wx.WxJianyu.Appid) + `&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect`
|
|
|
|
|
|
+ shareid := r.Get("shareId").String()
|
|
fdata := map[string]interface{}{
|
|
fdata := map[string]interface{}{
|
|
"error_code": 0,
|
|
"error_code": 0,
|
|
"error_msg": "",
|
|
"error_msg": "",
|
|
}
|
|
}
|
|
idata := map[string]interface{}{}
|
|
idata := map[string]interface{}{}
|
|
- bm := mobileReg.MatchString(client)
|
|
|
|
- openid := r.Header.Get("s_m_openid")
|
|
|
|
- nickname := r.Header.Get("s_nickname")
|
|
|
|
- redisName := "other"
|
|
|
|
- headImg := ""
|
|
|
|
- qrstr := ""
|
|
|
|
- infos := ""
|
|
|
|
- shareid := r.Get("shareId").String()
|
|
|
|
- if !strings.Contains(shareid, "shareId_") {
|
|
|
|
- rdata, ok := db.Mgo.FindOneByField("user", map[string]interface{}{"s_m_openid": shareid, "i_appid": 2}, `{"_id":1}`)
|
|
|
|
- if rdata != nil && ok && len(*rdata) > 0 {
|
|
|
|
- uid := BsonIdToSId((*rdata)["_id"])
|
|
|
|
- infos = redis.GetStr(redisName, fmt.Sprintf("SF_%s", uid))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if shareUserid := redis.GetStr(redisName, shareid); shareUserid == "" && infos == "" {
|
|
|
|
|
|
+ if shareUserid := redis.GetStr("other", shareid); shareUserid == "" {
|
|
r.Response.WriteJson(g.Map{
|
|
r.Response.WriteJson(g.Map{
|
|
"error_code": -1,
|
|
"error_code": -1,
|
|
"error_msg": "无数据",
|
|
"error_msg": "无数据",
|
|
})
|
|
})
|
|
return
|
|
return
|
|
} else {
|
|
} else {
|
|
- if infos == "" {
|
|
|
|
- infos = redis.GetStr(redisName, fmt.Sprintf("SF_%s", shareUserid))
|
|
|
|
- }
|
|
|
|
|
|
+ infos := redis.GetStr("other", fmt.Sprintf("SF_%s", shareUserid))
|
|
if infos != "" {
|
|
if infos != "" {
|
|
- nickname = strings.Split(infos, "#@#@")[1]
|
|
|
|
- headImg = strings.Split(infos, "#@#@")[2]
|
|
|
|
- link := fmt.Sprintf("%s/front/followGift/%s", qu.ObjToString(config.PushConfig.Webdomain), strings.Split(infos, "#@#@")[3])
|
|
|
|
- r, _ := qr.Encode(link, qr.M)
|
|
|
|
- pngdat := r.PNG()
|
|
|
|
- qrstr = base64.StdEncoding.EncodeToString(pngdat)
|
|
|
|
- shareid = strings.Split(infos, "#@#@")[3]
|
|
|
|
- if IsPhone(nickname) {
|
|
|
|
- nickname = string(nickname[0:3]) + "****" + string(nickname[len(nickname)-4:])
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if bm {
|
|
|
|
- if openid == "" {
|
|
|
|
- if r.Header.Get("s_m_openid") == "" {
|
|
|
|
- if r.Get("state").String() == "wx" {
|
|
|
|
- //微信跳回来的
|
|
|
|
- code := r.Get("code").String()
|
|
|
|
- if code != "" {
|
|
|
|
- openid = Getopenid(code)
|
|
|
|
- if openid != "" {
|
|
|
|
- if CheckUserIsSubscribe(openid) {
|
|
|
|
- FindUserAndCreateSess(openid, r.Session, "wx", false)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if CheckWxBrowser(r.Request) {
|
|
|
|
- //所有参数都不再使用,跳到微信验证用户
|
|
|
|
- idata["wxUrl"] = fmt.Sprintf(Wxoauth, url.QueryEscape(r.Host+r.URL.String()), "wx")
|
|
|
|
- fdata["data"] = idata
|
|
|
|
- r.Response.WriteJson(fdata)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ nickname := strings.Split(infos, "#@#@")[1]
|
|
|
|
+ if strings.Contains(nickname, "****") {
|
|
|
|
+ idata["share_nickname"] = nickname
|
|
|
|
+ } else if IsPhone(nickname) {
|
|
|
|
+ idata["share_nickname"] = string(nickname[0:3]) + "****" + nickname[len(nickname)-4:]
|
|
}
|
|
}
|
|
|
|
+ idata["share_headImg"] = strings.Split(infos, "#@#@")[2]
|
|
|
|
+ idata["isWeixin"] = CheckWxBrowser(r.Request)
|
|
|
|
+ link := fmt.Sprintf("%s/front/followGift/%s", qu.ObjToString(config.PushConfig.Webdomain), strings.Split(infos, "#@#@")[3])
|
|
|
|
+ p, _ := qr.Encode(link, qr.M)
|
|
|
|
+ pngdat := p.PNG()
|
|
|
|
+ idata["share_qr"] = base64.StdEncoding.EncodeToString(pngdat)
|
|
|
|
+ idata["shareid"] = shareid
|
|
|
|
+ fdata["data"] = idata
|
|
|
|
+ r.Response.WriteJson(fdata)
|
|
|
|
+ } else {
|
|
|
|
+ r.Response.WriteJson(g.Map{
|
|
|
|
+ "error_code": -1,
|
|
|
|
+ "error_msg": "无数据",
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- idata["shareid"] = shareid
|
|
|
|
- idata["share_nickname"] = nickname
|
|
|
|
- idata["share_headImg"] = headImg
|
|
|
|
- idata["openid"] = se.SE.EncodeString(openid)
|
|
|
|
- idata["share_qr"] = qrstr
|
|
|
|
- mynickname := r.Header.Get("s_nickname")
|
|
|
|
- myavatar := r.Header.Get("s_avatar")
|
|
|
|
- idata["nickname"] = mynickname
|
|
|
|
- idata["avatar"] = myavatar
|
|
|
|
- idata["signature"] = SignJSSDK(r.Host + r.URL.String())
|
|
|
|
- fdata["data"] = idata
|
|
|
|
- r.Response.WriteJson(fdata)
|
|
|
|
- } else {
|
|
|
|
- idata["shareid"] = shareid
|
|
|
|
- idata["share_nickname"] = nickname
|
|
|
|
- idata["share_headImg"] = headImg
|
|
|
|
- idata["signature"] = SignJSSDK(r.Host + r.URL.String())
|
|
|
|
- idata["isWeixin"] = CheckWxBrowser(r.Request)
|
|
|
|
- idata["share_qr"] = qrstr
|
|
|
|
- fdata["data"] = idata
|
|
|
|
- r.Response.WriteJson(fdata)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|