|
@@ -29,7 +29,7 @@ import (
|
|
|
|
|
|
var Mux *Weixin
|
|
var Mux *Weixin
|
|
|
|
|
|
-//锁
|
|
|
|
|
|
+// 锁
|
|
var sharelock *sync.Mutex = &sync.Mutex{}
|
|
var sharelock *sync.Mutex = &sync.Mutex{}
|
|
|
|
|
|
/*扫码锁,目前发现android手机,扫码的时候有时会请求两个,不是微信回调两次,
|
|
/*扫码锁,目前发现android手机,扫码的时候有时会请求两个,不是微信回调两次,
|
|
@@ -86,7 +86,7 @@ func init() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//微信菜单 click;点击菜单 回复文案;
|
|
|
|
|
|
+// 微信菜单 click;点击菜单 回复文案;
|
|
var menuClickReplyTextMap map[string]string
|
|
var menuClickReplyTextMap map[string]string
|
|
|
|
|
|
func MenuClickHandler(w ResponseWriter, r *Request) {
|
|
func MenuClickHandler(w ResponseWriter, r *Request) {
|
|
@@ -131,7 +131,7 @@ func MenuClickHandler(w ResponseWriter, r *Request) {
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
|
|
|
|
-//客服消息处理
|
|
|
|
|
|
+// 客服消息处理
|
|
func MsgTxtHandler(w ResponseWriter, r *Request) {
|
|
func MsgTxtHandler(w ResponseWriter, r *Request) {
|
|
log.Println("所有指令", r.FromUserName, r.Content) //测试信息
|
|
log.Println("所有指令", r.FromUserName, r.Content) //测试信息
|
|
now := time.Now()
|
|
now := time.Now()
|
|
@@ -208,7 +208,7 @@ func MsgTxtHandler(w ResponseWriter, r *Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//保存用户
|
|
|
|
|
|
+// 保存用户
|
|
func saveUser(u *UserInfo, source, pre, RSource, CSource string) (bool, string, string) {
|
|
func saveUser(u *UserInfo, source, pre, RSource, CSource string) (bool, string, string) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
isJyopUser := strings.HasPrefix(source, "Jyop")
|
|
isJyopUser := strings.HasPrefix(source, "Jyop")
|
|
@@ -497,7 +497,7 @@ func saveUser(u *UserInfo, source, pre, RSource, CSource string) (bool, string,
|
|
return fg, pcresult, subkey
|
|
return fg, pcresult, subkey
|
|
}
|
|
}
|
|
|
|
|
|
-//关注事件处理
|
|
|
|
|
|
+// 关注事件处理
|
|
var loginWxPool = make(chan bool, 1)
|
|
var loginWxPool = make(chan bool, 1)
|
|
|
|
|
|
func Subscribe(w ResponseWriter, r *Request) {
|
|
func Subscribe(w ResponseWriter, r *Request) {
|
|
@@ -690,7 +690,6 @@ func Subscribe(w ResponseWriter, r *Request) {
|
|
go saveSubscribe(openid, r.Event, r.EventKey, 1)
|
|
go saveSubscribe(openid, r.Event, r.EventKey, 1)
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func saveUserLog(shareId, openid, activeName string, shareflag bool) {
|
|
func saveUserLog(shareId, openid, activeName string, shareflag bool) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
date := time.Now()
|
|
date := time.Now()
|
|
@@ -751,7 +750,7 @@ func saveUserLog(shareId, openid, activeName string, shareflag bool) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//扫码事件
|
|
|
|
|
|
+// 扫码事件
|
|
var numCodeReg = regexp.MustCompile("^\\d+$")
|
|
var numCodeReg = regexp.MustCompile("^\\d+$")
|
|
|
|
|
|
func ScanHandler(w ResponseWriter, r *Request) {
|
|
func ScanHandler(w ResponseWriter, r *Request) {
|
|
@@ -940,7 +939,7 @@ func WxBind(code, openId string, w ResponseWriter, newUnionId string) bool {
|
|
}
|
|
}
|
|
bindOpenId := util.ObjToString((*bindData)["s_m_openid"])
|
|
bindOpenId := util.ObjToString((*bindData)["s_m_openid"])
|
|
bindUnionid := util.ObjToString((*bindData)["s_unionid"])
|
|
bindUnionid := util.ObjToString((*bindData)["s_unionid"])
|
|
- bindPhone := util.ObjToString((*bindData)["s_m_phone"])
|
|
|
|
|
|
+ bindPhone := util.ObjToString((*bindData)["s_phone"])
|
|
if bindPhone == "" {
|
|
if bindPhone == "" {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -1032,7 +1031,7 @@ func WxBind(code, openId string, w ResponseWriter, newUnionId string) bool {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
-//根据公司名称查询s_id
|
|
|
|
|
|
+// 根据公司名称查询s_id
|
|
func Findent(entname string) string {
|
|
func Findent(entname string) string {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
tem, ok := tools.MQFW.FindOneByField("winner", `{"name":"`+entname+`"}`, `{"_id":1}`)
|
|
tem, ok := tools.MQFW.FindOneByField("winner", `{"name":"`+entname+`"}`, `{"_id":1}`)
|
|
@@ -1050,7 +1049,7 @@ func Findent(entname string) string {
|
|
return winnerid
|
|
return winnerid
|
|
}
|
|
}
|
|
|
|
|
|
-//通过openid查userid
|
|
|
|
|
|
+// 通过openid查userid
|
|
func FindUserId(openid string) string {
|
|
func FindUserId(openid string) string {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
userId := ""
|
|
userId := ""
|
|
@@ -1061,7 +1060,7 @@ func FindUserId(openid string) string {
|
|
return userId
|
|
return userId
|
|
}
|
|
}
|
|
|
|
|
|
-//取消关注事件
|
|
|
|
|
|
+// 取消关注事件
|
|
func UnSubscribe(w ResponseWriter, r *Request) {
|
|
func UnSubscribe(w ResponseWriter, r *Request) {
|
|
saveEvenLog(r)
|
|
saveEvenLog(r)
|
|
openid := r.FromUserName
|
|
openid := r.FromUserName
|
|
@@ -1121,7 +1120,6 @@ func updatePushSet(openid string) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func updateUserLog(openid string) {
|
|
func updateUserLog(openid string) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
if openid == "" {
|
|
if openid == "" {
|
|
@@ -1147,7 +1145,6 @@ func updateUserLog(openid string) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func getMonth(mon string) int {
|
|
func getMonth(mon string) int {
|
|
month := map[string]int{
|
|
month := map[string]int{
|
|
"January": 1, "February": 2,
|
|
"January": 1, "February": 2,
|
|
@@ -1160,7 +1157,6 @@ func getMonth(mon string) int {
|
|
return month[mon]
|
|
return month[mon]
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func saveSubscribe(openid, stype, stypekey string, image int) {
|
|
func saveSubscribe(openid, stype, stypekey string, image int) {
|
|
if image == 0 {
|
|
if image == 0 {
|
|
tools.MQFW.Save("jy_subscribe", &map[string]interface{}{
|
|
tools.MQFW.Save("jy_subscribe", &map[string]interface{}{
|
|
@@ -1183,7 +1179,7 @@ func saveSubscribe(openid, stype, stypekey string, image int) {
|
|
|
|
|
|
var digitreg *regexp.Regexp = regexp.MustCompile("^\\d+$")
|
|
var digitreg *regexp.Regexp = regexp.MustCompile("^\\d+$")
|
|
|
|
|
|
-//生成推广临时二维码
|
|
|
|
|
|
+// 生成推广临时二维码
|
|
func TmpCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
func TmpCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
param := r.RequestURI[12:]
|
|
param := r.RequestURI[12:]
|
|
if !digitreg.MatchString(param) {
|
|
if !digitreg.MatchString(param) {
|
|
@@ -1221,7 +1217,7 @@ func TmpCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//web check user
|
|
|
|
|
|
+// web check user
|
|
var checkFlag = 1
|
|
var checkFlag = 1
|
|
|
|
|
|
func WebCheckUser(w http.ResponseWriter, r *http.Request) {
|
|
func WebCheckUser(w http.ResponseWriter, r *http.Request) {
|
|
@@ -1242,7 +1238,7 @@ func WebCheckUser(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//生成永久二维码
|
|
|
|
|
|
+// 生成永久二维码
|
|
func LimitCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
func LimitCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
param := r.RequestURI[14:]
|
|
param := r.RequestURI[14:]
|
|
val, err := strconv.Atoi(param)
|
|
val, err := strconv.Atoi(param)
|
|
@@ -1257,7 +1253,7 @@ func LimitCodeHandle(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//保存用户邀请关系
|
|
|
|
|
|
+// 保存用户邀请关系
|
|
func SaveInviteLink(shareid string, myopenid string, isolduser bool) {
|
|
func SaveInviteLink(shareid string, myopenid string, isolduser bool) {
|
|
sharelock.Lock()
|
|
sharelock.Lock()
|
|
//对于老用户的处理
|
|
//对于老用户的处理
|
|
@@ -1293,7 +1289,7 @@ func SaveInviteLink(shareid string, myopenid string, isolduser bool) {
|
|
sharelock.Unlock()
|
|
sharelock.Unlock()
|
|
}
|
|
}
|
|
|
|
|
|
-//生成永久二维码地址
|
|
|
|
|
|
+// 生成永久二维码地址
|
|
func YjHandle(w http.ResponseWriter, r *http.Request) {
|
|
func YjHandle(w http.ResponseWriter, r *http.Request) {
|
|
param := r.RequestURI[8:]
|
|
param := r.RequestURI[8:]
|
|
if !digitreg.MatchString(param) {
|
|
if !digitreg.MatchString(param) {
|
|
@@ -1324,7 +1320,7 @@ func YjHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//生成永久二维码地址(str)
|
|
|
|
|
|
+// 生成永久二维码地址(str)
|
|
func YjStrHandle(w http.ResponseWriter, r *http.Request) {
|
|
func YjStrHandle(w http.ResponseWriter, r *http.Request) {
|
|
param := r.RequestURI[11:]
|
|
param := r.RequestURI[11:]
|
|
if param != "" {
|
|
if param != "" {
|
|
@@ -1351,19 +1347,19 @@ func YjStrHandle(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//获取AccessToken
|
|
|
|
|
|
+// 获取AccessToken
|
|
func GetToken(w http.ResponseWriter, r *http.Request) {
|
|
func GetToken(w http.ResponseWriter, r *http.Request) {
|
|
v, _ := Mux.GetToken()
|
|
v, _ := Mux.GetToken()
|
|
fmt.Fprint(w, v)
|
|
fmt.Fprint(w, v)
|
|
}
|
|
}
|
|
|
|
|
|
-//获取Ticket
|
|
|
|
|
|
+// 获取Ticket
|
|
func GetTicket(w http.ResponseWriter, r *http.Request) {
|
|
func GetTicket(w http.ResponseWriter, r *http.Request) {
|
|
v, _ := Mux.GetTicket()
|
|
v, _ := Mux.GetTicket()
|
|
fmt.Fprint(w, v)
|
|
fmt.Fprint(w, v)
|
|
}
|
|
}
|
|
|
|
|
|
-//生成推广临时二维码地址
|
|
|
|
|
|
+// 生成推广临时二维码地址
|
|
func AdvHandle(w http.ResponseWriter, r *http.Request) {
|
|
func AdvHandle(w http.ResponseWriter, r *http.Request) {
|
|
param := r.RequestURI[8:]
|
|
param := r.RequestURI[8:]
|
|
if !digitreg.MatchString(param) {
|
|
if !digitreg.MatchString(param) {
|
|
@@ -1405,7 +1401,7 @@ type qrStrMsg struct {
|
|
} `json:"action_info"`
|
|
} `json:"action_info"`
|
|
}
|
|
}
|
|
|
|
|
|
-//创建带str的二维码64位以内,整数最大4294967295
|
|
|
|
|
|
+// 创建带str的二维码64位以内,整数最大4294967295
|
|
func CreateQrcodeByStr(str string) []byte {
|
|
func CreateQrcodeByStr(str string) []byte {
|
|
if len(str) > 64 {
|
|
if len(str) > 64 {
|
|
log.Println("scene_str length too long")
|
|
log.Println("scene_str length too long")
|
|
@@ -1431,7 +1427,7 @@ func CreateQrcodeByStr(str string) []byte {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-//地址栏生成带str的临时二维码图片
|
|
|
|
|
|
+// 地址栏生成带str的临时二维码图片
|
|
func NewStrQrHandle(w http.ResponseWriter, r *http.Request) {
|
|
func NewStrQrHandle(w http.ResponseWriter, r *http.Request) {
|
|
r.ParseForm()
|
|
r.ParseForm()
|
|
id := r.Form.Get("id")
|
|
id := r.Form.Get("id")
|
|
@@ -1447,7 +1443,7 @@ func NewStrQrHandle(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//修改是否推送的状态
|
|
|
|
|
|
+// 修改是否推送的状态
|
|
func updateIsPush(openid string, status int) {
|
|
func updateIsPush(openid string, status int) {
|
|
tools.MQFW.Update("user", map[string]interface{}{"s_m_openid": openid, "s_unionid": map[string]interface{}{"$ne": openid}}, map[string]interface{}{
|
|
tools.MQFW.Update("user", map[string]interface{}{"s_m_openid": openid, "s_unionid": map[string]interface{}{"$ne": openid}}, map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
@@ -1466,7 +1462,7 @@ func updateIsPush(openid string, status int) {
|
|
}, false, true)
|
|
}, false, true)
|
|
}
|
|
}
|
|
|
|
|
|
-//过滤重复调用
|
|
|
|
|
|
+// 过滤重复调用
|
|
func isRepeatCall(openId string, createTime int) bool {
|
|
func isRepeatCall(openId string, createTime int) bool {
|
|
key := fmt.Sprintf("wxRepeatScan_%s", openId)
|
|
key := fmt.Sprintf("wxRepeatScan_%s", openId)
|
|
v := redis.Incr("other", key)
|
|
v := redis.Incr("other", key)
|
|
@@ -1480,7 +1476,7 @@ func isRepeatCall(openId string, createTime int) bool {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
-//记录固定码的扫码日志
|
|
|
|
|
|
+// 记录固定码的扫码日志
|
|
func saveFixedCode(openid, t, code string) {
|
|
func saveFixedCode(openid, t, code string) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
if !numCodeReg.MatchString(code) {
|
|
if !numCodeReg.MatchString(code) {
|