|
@@ -8,7 +8,7 @@ import (
|
|
|
"math/rand"
|
|
|
"os"
|
|
|
//. "gopkg.in/mgo.v2/bson"
|
|
|
- . "jfw/config"
|
|
|
+ // . "jfw/config"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"qfw/util"
|
|
@@ -34,7 +34,7 @@ var regKey *regexp.Regexp
|
|
|
var sharelock *sync.Mutex = &sync.Mutex{}
|
|
|
|
|
|
func init() {
|
|
|
- util.InitInfluxdb(util.ObjToString(Sysconfig["influxdb"]))
|
|
|
+ util.InitInfluxdb(util.ObjToString(config.Sysconfig["influxdb"]))
|
|
|
InitSSLClient("./apiclient_cert.pem", "./apiclient_key.pem", "./rootca.pem")
|
|
|
Mux = New(config.Sysconfig["apptoken"].(string), config.Sysconfig["appid"].(string), config.Sysconfig["appsecret"].(string))
|
|
|
// 注册关注事件的处理函数
|
|
@@ -672,121 +672,150 @@ func SaveAbnormal(openid string) {
|
|
|
}
|
|
|
|
|
|
//扫码事件
|
|
|
+var numCodeReg = regexp.MustCompile("^\\d+$")
|
|
|
+var qrSimpleEncrypt = &util.SimpleEncrypt{"qrcode_jywx2017"}
|
|
|
+
|
|
|
func ScanHandler(w ResponseWriter, r *Request) {
|
|
|
defer util.Catch()
|
|
|
openid := r.FromUserName
|
|
|
m, b := tools.MQFW.FindOneByField("user", `{"s_m_openid":"`+openid+`"}`, `{"_id":1,"s_headimage":1,"o_jy":1}`)
|
|
|
- log.Println("SCAN:", openid, r.EventKey, b)
|
|
|
+ //data, _ := json.Marshal(r)
|
|
|
+ //log.Println("SCAN:", openid, string(data), b)
|
|
|
if b {
|
|
|
- pccodepre := r.EventKey[0:2]
|
|
|
- user, err := Mux.GetUserInfo(openid)
|
|
|
- if *m == nil {
|
|
|
- if err != nil {
|
|
|
- log.Println(err)
|
|
|
- } else {
|
|
|
- if b, _, _ := saveUser(user, r.EventKey); b {
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
- w.ReplyText(fmt.Sprintf(config.Sysconfig["welcomemsg"].(string), url))
|
|
|
- }
|
|
|
+ if len(r.EventKey) < 11 && numCodeReg.MatchString(r.EventKey) { //原二维码逻辑
|
|
|
+ pccodepre := "0"
|
|
|
+ if len(r.EventKey) > 1 {
|
|
|
+ pccodepre = r.EventKey[0:2]
|
|
|
}
|
|
|
- } else {
|
|
|
- headimage := ""
|
|
|
- if (*m)["s_headimage"] == nil || fmt.Sprint((*m)["s_headimage"]) == "" { //
|
|
|
- redis.Put("other", "newUser-"+user.OpenId, user.HeadImageUrl, 120)
|
|
|
- headimage = downloadUserFace(user.HeadImageUrl)
|
|
|
+ user, err := Mux.GetUserInfo(openid)
|
|
|
+ if *m == nil {
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ } else {
|
|
|
+ if b, _, _ := saveUser(user, r.EventKey); b {
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
+ w.ReplyText(fmt.Sprintf(config.Sysconfig["welcomemsg"].(string), url))
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- headimage = fmt.Sprint((*m)["s_headimage"])
|
|
|
- }
|
|
|
- if pccodepre == "13" { //103pc关注项目
|
|
|
- param := new(jrpc.FollowData)
|
|
|
- param.OpenId = openid
|
|
|
- param.Server = fmt.Sprint(config.Sysconfig["webrpcport"])
|
|
|
- param.Projectname = redis.GetStr("sso", "pc_subscribe_"+r.EventKey)
|
|
|
- if param.Projectname != "" {
|
|
|
- rep := tools.MyFollow(param)
|
|
|
- if rep == "" {
|
|
|
- pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",myfollow"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_fail"]), param.Projectname, url))
|
|
|
- } else if rep == "repeat" { //重复
|
|
|
+ headimage := ""
|
|
|
+ if (*m)["s_headimage"] == nil || fmt.Sprint((*m)["s_headimage"]) == "" { //
|
|
|
+ redis.Put("other", "newUser-"+user.OpenId, user.HeadImageUrl, 120)
|
|
|
+ headimage = downloadUserFace(user.HeadImageUrl)
|
|
|
+ } else {
|
|
|
+ headimage = fmt.Sprint((*m)["s_headimage"])
|
|
|
+ }
|
|
|
+ if pccodepre == "13" { //103pc关注项目
|
|
|
+ param := new(jrpc.FollowData)
|
|
|
+ param.OpenId = openid
|
|
|
+ param.Server = fmt.Sprint(config.Sysconfig["webrpcport"])
|
|
|
+ param.Projectname = redis.GetStr("sso", "pc_subscribe_"+r.EventKey)
|
|
|
+ if param.Projectname != "" {
|
|
|
+ rep := tools.MyFollow(param)
|
|
|
+ if rep == "" {
|
|
|
+ pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",myfollow"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_fail"]), param.Projectname, url))
|
|
|
+ } else if rep == "repeat" { //重复
|
|
|
+ pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",myfollow"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_repeat"]), param.Projectname, url))
|
|
|
+ } else {
|
|
|
+ pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",pcmyfollow")) + "__" + util.EncodeArticleId2ByCheck(rep)
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_success"]), param.Projectname, url))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if pccodepre == "11" || pccodepre == "12" || pccodepre == "19" { //101pc订阅,102pc搜索关键词
|
|
|
+ pcUser, pcresult, subkey := pcSetUserKeys(*m, r.EventKey)
|
|
|
+ go tools.MQFW.Update("user", &map[string]interface{}{
|
|
|
+ "s_m_openid": openid,
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "s_headimage": headimage,
|
|
|
+ "o_jy": pcUser["o_jy"],
|
|
|
+ },
|
|
|
+ }, false, false)
|
|
|
+ if pcresult == "ok" {
|
|
|
pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",myfollow"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_repeat"]), param.Projectname, url))
|
|
|
- } else {
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["key_success"]), subkey, url))
|
|
|
+ } else if pcresult == "repeat" {
|
|
|
+ fastSubscribeText := config.Sysconfig["fastSubscribe"].(map[string]interface{})
|
|
|
+ exists := fastSubscribeText["exists"].(string)
|
|
|
+ w.ReplyText(fmt.Sprintf(exists, subkey, fastSubscribeText["skill"].(string)))
|
|
|
+ } else if pcresult == "fail" && subkey != "" {
|
|
|
pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",pcmyfollow")) + "__" + util.EncodeArticleId2ByCheck(rep)
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["project_success"]), param.Projectname, url))
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["key_fail"]), subkey, url))
|
|
|
}
|
|
|
- }
|
|
|
- } else if pccodepre == "11" || pccodepre == "12" || pccodepre == "19" { //101pc订阅,102pc搜索关键词
|
|
|
- pcUser, pcresult, subkey := pcSetUserKeys(*m, r.EventKey)
|
|
|
- go tools.MQFW.Update("user", &map[string]interface{}{
|
|
|
- "s_m_openid": openid,
|
|
|
- }, &map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "s_headimage": headimage,
|
|
|
- "o_jy": pcUser["o_jy"],
|
|
|
- },
|
|
|
- }, false, false)
|
|
|
- if pcresult == "ok" {
|
|
|
- pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["key_success"]), subkey, url))
|
|
|
- } else if pcresult == "repeat" {
|
|
|
- fastSubscribeText := config.Sysconfig["fastSubscribe"].(map[string]interface{})
|
|
|
- exists := fastSubscribeText["exists"].(string)
|
|
|
- w.ReplyText(fmt.Sprintf(exists, subkey, fastSubscribeText["skill"].(string)))
|
|
|
- } else if pcresult == "fail" && subkey != "" {
|
|
|
- pchints := config.Sysconfig["pchints"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",rssset"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["key_fail"]), subkey, url))
|
|
|
- }
|
|
|
- } else if pccodepre == "18" { //关注企业
|
|
|
- company := redis.GetStr("sso", "pc_subscribe_"+r.EventKey) //企业名称
|
|
|
- s_id := Findent(company) //查询s_id
|
|
|
- userId := FindUserId(openid) //查询userid
|
|
|
- if company != "" {
|
|
|
- if tools.MQFW.Count("jylab_followent", `{"s_userid":"`+userId+`","s_id":"`+s_id+`"}`) > 0 {
|
|
|
- //已经关注过此企业
|
|
|
- pchints := config.Sysconfig["company"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",entListFollow"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_repeat"]), company, url))
|
|
|
- } else if tools.MQFW.Count("jylab_followent", `{"s_userid":"`+userId+`"}`) >= util.IntAll(config.Sysconfig["followCompany"]) {
|
|
|
- //超过最大关注数
|
|
|
- pchints := config.Sysconfig["company"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",entListFollow"))
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_fail"]), company, url))
|
|
|
- } else {
|
|
|
- //关注成功
|
|
|
- data := make(map[string]interface{})
|
|
|
- data["s_entname"] = company
|
|
|
- data["s_userid"] = userId
|
|
|
- data["s_openid"] = openid
|
|
|
- data["i_ispush"] = 1
|
|
|
- data["l_createtime"] = time.Now().Unix()
|
|
|
- data["s_id"] = s_id
|
|
|
- if followId := tools.MQFW.Save("jylab_followent", data); len(followId) > 0 {
|
|
|
+ } else if pccodepre == "18" { //关注企业
|
|
|
+ company := redis.GetStr("sso", "pc_subscribe_"+r.EventKey) //企业名称
|
|
|
+ s_id := Findent(company) //查询s_id
|
|
|
+ userId := FindUserId(openid) //查询userid
|
|
|
+ if company != "" {
|
|
|
+ if tools.MQFW.Count("jylab_followent", `{"s_userid":"`+userId+`","s_id":"`+s_id+`"}`) > 0 {
|
|
|
+ //已经关注过此企业
|
|
|
pchints := config.Sysconfig["company"].(map[string]interface{})
|
|
|
- url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",newInfoFollow")) + "__" + company + "__" + util.EncodeArticleId2ByCheck(s_id)
|
|
|
- w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_success"]), company, url))
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",entListFollow"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_repeat"]), company, url))
|
|
|
+ } else if tools.MQFW.Count("jylab_followent", `{"s_userid":"`+userId+`"}`) >= util.IntAll(config.Sysconfig["followCompany"]) {
|
|
|
+ //超过最大关注数
|
|
|
+ pchints := config.Sysconfig["company"].(map[string]interface{})
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",entListFollow"))
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_fail"]), company, url))
|
|
|
+ } else {
|
|
|
+ //关注成功
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["s_entname"] = company
|
|
|
+ data["s_userid"] = userId
|
|
|
+ data["s_openid"] = openid
|
|
|
+ data["i_ispush"] = 1
|
|
|
+ data["l_createtime"] = time.Now().Unix()
|
|
|
+ data["s_id"] = s_id
|
|
|
+ if followId := tools.MQFW.Save("jylab_followent", data); len(followId) > 0 {
|
|
|
+ pchints := config.Sysconfig["company"].(map[string]interface{})
|
|
|
+ url := fmt.Sprintf(config.Sysconfig["proxysess"].(string), se.EncodeString(openid+","+user.UnionId+","+strconv.Itoa(int(time.Now().Unix()))+",newInfoFollow")) + "__" + company + "__" + util.EncodeArticleId2ByCheck(s_id)
|
|
|
+ w.ReplyText(fmt.Sprintf(fmt.Sprint(pchints["company_success"]), company, url))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+
|
|
|
+ go tools.MQFW.Update("user", &map[string]interface{}{
|
|
|
+ "s_m_openid": openid,
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "s_headimage": headimage,
|
|
|
+ },
|
|
|
+ }, false, false)
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ if pccodepre < "32" {
|
|
|
+ log.Println("扫描登录:", r.EventKey)
|
|
|
+ redis.Put("sso", "p_share_"+r.EventKey, openid, 600)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ key := qrSimpleEncrypt.DecodeStringByCheck(r.EventKey)
|
|
|
+ if key != "" { //"d_"存放二维码图片,"k_"存放二维码信息
|
|
|
+ qrinfo := redis.Pop("qrcode", "k_"+key) //取出并删除信息
|
|
|
+ qrmap, _ := qrinfo.(map[string]interface{})
|
|
|
+ if qrmap != nil {
|
|
|
+ event, _ := qrmap["event"].(string) //定义事件
|
|
|
+ switch event {
|
|
|
+ case "followent":
|
|
|
+ case "followproject":
|
|
|
+ case "setsearchkey":
|
|
|
+ }
|
|
|
+ action, _ := qrmap["action"].(string) //定义动作
|
|
|
+ switch action {
|
|
|
+ case "login":
|
|
|
+ }
|
|
|
|
|
|
- go tools.MQFW.Update("user", &map[string]interface{}{
|
|
|
- "s_m_openid": openid,
|
|
|
- }, &map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "s_headimage": headimage,
|
|
|
- },
|
|
|
- }, false, false)
|
|
|
+ }
|
|
|
+ //rpc回调网站,告诉网站此二维码已经使用过
|
|
|
}
|
|
|
}
|
|
|
- if pccodepre < "32" {
|
|
|
- log.Println("扫描登录:", r.EventKey)
|
|
|
- redis.Put("sso", "p_usershare_"+r.EventKey, openid, 600)
|
|
|
- }
|
|
|
} else {
|
|
|
log.Println("scan-error,mongodb-conn-error")
|
|
|
}
|
|
@@ -1128,7 +1157,7 @@ func SaveInviteLink(shareid string, myopenid string, isolduser bool) {
|
|
|
sharelock.Unlock()
|
|
|
}
|
|
|
|
|
|
-//生成永久二维码
|
|
|
+//生成永久二维码地址
|
|
|
func YjHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
param := r.RequestURI[8:]
|
|
|
if !digitreg.MatchString(param) {
|
|
@@ -1165,7 +1194,7 @@ func GetToken(w http.ResponseWriter, r *http.Request) {
|
|
|
fmt.Fprint(w, Mux.GetToken())
|
|
|
}
|
|
|
|
|
|
-//生成推广临时二维码
|
|
|
+//生成推广临时二维码地址
|
|
|
func AdvHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
param := r.RequestURI[8:]
|
|
|
if !digitreg.MatchString(param) {
|
|
@@ -1195,7 +1224,58 @@ func AdvHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
url := tmp["url"].(string)
|
|
|
w.Write([]byte(url))
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+type qrStrMsg struct {
|
|
|
+ Expire int `json:"expire_seconds"`
|
|
|
+ Name string `json:"action_name"`
|
|
|
+ Info struct {
|
|
|
+ Scene struct {
|
|
|
+ Id string `json:"scene_str"`
|
|
|
+ } `json:"scene"`
|
|
|
+ } `json:"action_info"`
|
|
|
+}
|
|
|
+
|
|
|
+//创建带str的二维码64位以内,整数最大4294967295
|
|
|
+func CreateQrcodeByStr(str string) []byte {
|
|
|
+ if len(str) > 64 {
|
|
|
+ log.Println("scene_str length too long")
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ msg := new(qrStrMsg)
|
|
|
+ msg.Expire = 2592000
|
|
|
+ msg.Name = "QR_STR_SCENE"
|
|
|
+ msg.Info.Scene.Id = str
|
|
|
+ ret, err := Mux.PostCustomMsg("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=", msg)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err.Error())
|
|
|
+ } else {
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
+ if json.Unmarshal(ret, &tmp) == nil {
|
|
|
+ url, _ := tmp["url"].(string)
|
|
|
+ r, _ := qr.Encode(url, qr.L)
|
|
|
+ if r != nil {
|
|
|
+ return r.PNG()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
|
|
|
+//地址栏生成带str的临时二维码图片
|
|
|
+func NewStrQrHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
+ r.ParseForm()
|
|
|
+ id := r.Form.Get("id")
|
|
|
+ if id != "" {
|
|
|
+ data := CreateQrcodeByStr(id)
|
|
|
+ if data != nil {
|
|
|
+ w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
+ w.Header().Set("Pragma", "no-cache")
|
|
|
+ w.Header().Set("Expires", "0")
|
|
|
+ w.Header().Set("Content-Type", "image/png")
|
|
|
+ w.Write(data)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//修改是否推送的状态
|