|
@@ -1,131 +1,135 @@
|
|
|
package front
|
|
|
|
|
|
import (
|
|
|
- util "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- fx "app.yhyue.com/moapp/jypkg/filter/xweb"
|
|
|
- "fmt"
|
|
|
- jutil "jy/src/jfw/jyutil"
|
|
|
- "log"
|
|
|
- "net/http"
|
|
|
- "net/url"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ fx "app.yhyue.com/moapp/jypkg/filter/xweb"
|
|
|
+ "fmt"
|
|
|
+ jutil "jy/src/jfw/jyutil"
|
|
|
+ "log"
|
|
|
+ "net/http"
|
|
|
+ "net/url"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
- . "jy/src/jfw/public"
|
|
|
+ . "jy/src/jfw/public"
|
|
|
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
)
|
|
|
|
|
|
type Jyshare struct {
|
|
|
- *xweb.Action
|
|
|
- wxShare xweb.Mapper `xweb:"/front/wxshare/([^.]*)"` //微信分享图片
|
|
|
- share xweb.Mapper `xweb:"/front/share/([^.]*)"` //电脑版微信二维码
|
|
|
+ *xweb.Action
|
|
|
+ wxShare xweb.Mapper `xweb:"/front/wxshare/([^.]*)"` //微信分享图片
|
|
|
+ share xweb.Mapper `xweb:"/front/share/([^.]*)"` //电脑版微信二维码
|
|
|
}
|
|
|
|
|
|
func init() {
|
|
|
- xweb.AddAction(&Jyshare{})
|
|
|
+ xweb.AddAction(&Jyshare{})
|
|
|
}
|
|
|
|
|
|
// 电脑版微信二维码
|
|
|
func (m *Jyshare) Share(pid string) error {
|
|
|
- //生成的pid中,有时候结尾会带有/,pid是接收不到的,所以pid直接从url中取
|
|
|
- urlEntity, _ := url.Parse(m.Url())
|
|
|
- log.Println(urlEntity)
|
|
|
- pid = strings.TrimLeft(urlEntity.Path, "/front/share/")
|
|
|
- var pngdata = []byte{}
|
|
|
- pid = se.DecodeString(pid)
|
|
|
- if pid == "" {
|
|
|
- pid = "jy001"
|
|
|
- log.Println(pid, "-share_referer-", m.Request.Referer())
|
|
|
- }
|
|
|
- if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
|
|
|
- pngdata = *ret
|
|
|
- } else {
|
|
|
- //id, _ := strconv.Atoi(pid)
|
|
|
- GetShareQRStr(pid)
|
|
|
- tmp, err := redis.GetBytes("sso", "p_share_"+pid)
|
|
|
- if err == nil {
|
|
|
- pngdata = *tmp
|
|
|
- }
|
|
|
- }
|
|
|
- source := m.GetString("source") //企业信用报告新增
|
|
|
- if source != "" {
|
|
|
- fx.SetVisitSource(m.Session(), source)
|
|
|
- }
|
|
|
- //page_action 页面请求 GetLoginNum 函数,页面对应id,会有二维码不经过此函数,直接获取二维码。此时 page_action 没有值,后续可以把GetLoginNum 逻辑放在此处
|
|
|
- go ErBindVisitInfo(pid, m.Session(), m.Request)
|
|
|
- w := m.ResponseWriter
|
|
|
- w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
|
|
|
- w.Header().Set("Prama", "no-cache")
|
|
|
- w.Header().Set("Expires", "0")
|
|
|
- w.Header().Set("Content-Type", "image/png")
|
|
|
- w.Write(pngdata)
|
|
|
- return nil
|
|
|
+ //生成的pid中,有时候结尾会带有/,pid是接收不到的,所以pid直接从url中取
|
|
|
+ urlEntity, _ := url.Parse(m.Url())
|
|
|
+ log.Println(urlEntity)
|
|
|
+ pid = strings.TrimLeft(urlEntity.Path, "/front/share/")
|
|
|
+ var pngdata = []byte{}
|
|
|
+ pid = se.DecodeString(pid)
|
|
|
+ if pid == "" {
|
|
|
+ pid = "jy001"
|
|
|
+ log.Println(pid, "-share_referer-", m.Request.Referer())
|
|
|
+ }
|
|
|
+ if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
|
|
|
+ pngdata = *ret
|
|
|
+ } else {
|
|
|
+ //id, _ := strconv.Atoi(pid)
|
|
|
+ GetShareQRStr(pid)
|
|
|
+ tmp, err := redis.GetBytes("sso", "p_share_"+pid)
|
|
|
+ if err == nil {
|
|
|
+ pngdata = *tmp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ source := m.GetString("source") //企业信用报告新增
|
|
|
+ if source != "" {
|
|
|
+ fx.SetVisitSource(m.Session(), source)
|
|
|
+ }
|
|
|
+ //page_action 页面请求 GetLoginNum 函数,页面对应id,会有二维码不经过此函数,直接获取二维码。此时 page_action 没有值,后续可以把GetLoginNum 逻辑放在此处
|
|
|
+ go ErBindVisitInfo(pid, m.Session(), m.Request)
|
|
|
+ w := m.ResponseWriter
|
|
|
+ w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
|
|
|
+ w.Header().Set("Prama", "no-cache")
|
|
|
+ w.Header().Set("Expires", "0")
|
|
|
+ w.Header().Set("Content-Type", "image/png")
|
|
|
+ w.Write(pngdata)
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// 取微信分享 用户的二维码 图片
|
|
|
func (m *Jyshare) WxShare(openids string) error {
|
|
|
- wxidCode := strings.Split(openids, "__")
|
|
|
- var openid = ""
|
|
|
- var jyCode = ""
|
|
|
- if len(wxidCode) > 0 {
|
|
|
- openid = wxidCode[0]
|
|
|
- jyCode = wxidCode[1]
|
|
|
- }
|
|
|
- var pngData []byte
|
|
|
- openid = se.DecodeString(openid)
|
|
|
- pid := jutil.FindMyShareId(openid, jyCode)
|
|
|
- if pid == "" {
|
|
|
- pid = "jy002"
|
|
|
- log.Println(pid, "-WxShare_referer-", m.Request.Referer())
|
|
|
- }
|
|
|
- if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
|
|
|
- pngData = *ret
|
|
|
- } else {
|
|
|
- GetShareQRStr(pid)
|
|
|
- tmp, _ := redis.GetBytes("sso", "p_share_"+pid)
|
|
|
- pngData = *tmp
|
|
|
- }
|
|
|
- //微信分享默认是32
|
|
|
- m.Session().Set("page_action", "32")
|
|
|
- go ErBindVisitInfo(pid, m.Session(), m.Request)
|
|
|
- w := m.ResponseWriter
|
|
|
- w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
|
|
|
- w.Header().Set("Prama", "no-cache")
|
|
|
- w.Header().Set("Expires", "0")
|
|
|
- w.Header().Set("Content-Type", "image/png")
|
|
|
- w.Write(pngData)
|
|
|
- return nil
|
|
|
+ wxidCode := strings.Split(openids, "__")
|
|
|
+ var openid = ""
|
|
|
+ var jyCode = ""
|
|
|
+ if len(wxidCode) > 0 {
|
|
|
+ openid = wxidCode[0]
|
|
|
+ jyCode = wxidCode[1]
|
|
|
+ }
|
|
|
+ var pngData []byte
|
|
|
+ openid = se.DecodeString(openid)
|
|
|
+ pid := jutil.FindMyShareId(openid, jyCode)
|
|
|
+ if pid == "" {
|
|
|
+ pid = "jy002"
|
|
|
+ log.Println(pid, "-WxShare_referer-", m.Request.Referer())
|
|
|
+ }
|
|
|
+ if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
|
|
|
+ pngData = *ret
|
|
|
+ } else {
|
|
|
+ GetShareQRStr(pid)
|
|
|
+ tmp, _ := redis.GetBytes("sso", "p_share_"+pid)
|
|
|
+ pngData = *tmp
|
|
|
+ }
|
|
|
+ //微信分享默认是32
|
|
|
+ m.Session().Set("page_action", "32")
|
|
|
+ //微信分享用户来源
|
|
|
+ if fx.GetVisitSource(m.Session()) == "" {
|
|
|
+ fx.SetVisitSource(m.Session(), fmt.Sprintf("微信好友分享:%s", jyCode))
|
|
|
+ }
|
|
|
+ go ErBindVisitInfo(pid, m.Session(), m.Request)
|
|
|
+ w := m.ResponseWriter
|
|
|
+ w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
|
|
|
+ w.Header().Set("Prama", "no-cache")
|
|
|
+ w.Header().Set("Expires", "0")
|
|
|
+ w.Header().Set("Content-Type", "image/png")
|
|
|
+ w.Write(pngData)
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// 访问者信息和二维码进行绑定 用于 微信扫码 关注或者扫码登录记录信息
|
|
|
func ErBindVisitInfo(erId string, sess *httpsession.Session, r *http.Request) {
|
|
|
- sessVal := sess.GetMultiple()
|
|
|
- data := make(map[string]interface{})
|
|
|
- ua := "" //UA
|
|
|
- if len(r.Header["User-Agent"]) > 0 {
|
|
|
- ua = r.Header["User-Agent"][0]
|
|
|
- }
|
|
|
- data["Ros"] = util.GetOS(ua) //系统
|
|
|
- data["Rip"] = util.GetIp(r) //ip
|
|
|
- data["Rbrowse"] = util.GetBrowse(ua) //浏览器
|
|
|
- data["RURL"] = r.Referer() //当前页面 请求地址
|
|
|
- data["RModule"] = sessVal["RModule"] //模块 基本不使用
|
|
|
- data["RActiveCode"] = sessVal["RActiveCode"] //活动代码
|
|
|
- data["RReferer"] = sessVal["RReferer"] //referer
|
|
|
- data["RSource"] = fx.GetVisitSource(sess) //来源
|
|
|
- data["Rparamarea"] = sessVal["paramarea"] //标签查询 地区
|
|
|
- data["Rparaminfotype"] = sessVal["paraminfotype"] //标签查询 信息类型
|
|
|
- pageAction := util.InterfaceToStr(sessVal["page_action"]) //二维码 对应页面的id seo.json 根据当前页面请求地址 获取对应的配置 page_action (不够规范)
|
|
|
- if _, err := strconv.Atoi(erId); err == nil {
|
|
|
- pageAction = erId
|
|
|
- }
|
|
|
- data["action"] = pageAction
|
|
|
- ckSource, err := r.Cookie("source") //原逻辑 暂不清楚什么情况下会有这个参数
|
|
|
- if err == nil {
|
|
|
- data["cookieSource"] = ckSource.Value
|
|
|
- }
|
|
|
- redis.Put("sso", fmt.Sprintf("p_shareData_%s", erId), data, 2*60*60) //仅供微信扫码关注使用
|
|
|
+ sessVal := sess.GetMultiple()
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ ua := "" //UA
|
|
|
+ if len(r.Header["User-Agent"]) > 0 {
|
|
|
+ ua = r.Header["User-Agent"][0]
|
|
|
+ }
|
|
|
+ data["Ros"] = util.GetOS(ua) //系统
|
|
|
+ data["Rip"] = util.GetIp(r) //ip
|
|
|
+ data["Rbrowse"] = util.GetBrowse(ua) //浏览器
|
|
|
+ data["RURL"] = r.Referer() //当前页面 请求地址
|
|
|
+ data["RModule"] = sessVal["RModule"] //模块 基本不使用
|
|
|
+ data["RActiveCode"] = sessVal["RActiveCode"] //活动代码
|
|
|
+ data["RReferer"] = sessVal["RReferer"] //referer
|
|
|
+ data["RSource"] = fx.GetVisitSource(sess) //来源
|
|
|
+ data["Rparamarea"] = sessVal["paramarea"] //标签查询 地区
|
|
|
+ data["Rparaminfotype"] = sessVal["paraminfotype"] //标签查询 信息类型
|
|
|
+ pageAction := util.InterfaceToStr(sessVal["page_action"]) //二维码 对应页面的id seo.json 根据当前页面请求地址 获取对应的配置 page_action (不够规范)
|
|
|
+ if _, err := strconv.Atoi(erId); err == nil {
|
|
|
+ pageAction = erId
|
|
|
+ }
|
|
|
+ data["action"] = pageAction
|
|
|
+ ckSource, err := r.Cookie("source") //原逻辑 暂不清楚什么情况下会有这个参数
|
|
|
+ if err == nil {
|
|
|
+ data["cookieSource"] = ckSource.Value
|
|
|
+ }
|
|
|
+ redis.Put("sso", fmt.Sprintf("p_shareData_%s", erId), data, 2*60*60) //仅供微信扫码关注使用
|
|
|
}
|