Bläddra i källkod

修改值时剑鱼立即推送

renzheng 9 år sedan
förälder
incheckning
cf14b487e2

+ 1 - 0
core/src/config.json

@@ -29,6 +29,7 @@
     "chatServer": "127.0.0.1:83",
     "chatRpc": "127.0.0.1:88",
 	"creditRpc":"127.0.0.1:8765",
+	"pushRpc":"127.0.0.1:8766",
 	"domainName":"http://www.qimingxing.info"
 
 }

+ 1 - 0
core/src/qfw/coreconfig/SysConfig.go

@@ -22,6 +22,7 @@ type config struct {
 	MailFailureTime int         `json:"mailFailureTime"`
 	ChatServer      string      `json:"chatServer"`
 	ChatRpc         string      `json:"chatRpc"`
+	PushRpc         string      `json:"pushRpc"`
 	ElasticPoolSize int         `json:"elasticPoolSize"`
 	DomainName      string      `json:"domainName"`
 }

+ 23 - 0
core/src/qfw/mobile/wxmenu.go

@@ -5,12 +5,14 @@ import (
 	"fmt"
 	"log"
 	"math/rand"
+	"net/rpc"
 	"qfw/coreconfig"
 	"qfw/coreutil"
 	"qfw/util"
 	"qfw/util/credit"
 	"qfw/util/mongodb"
 	"qfw/util/redis"
+	qrpc "qfw/util/rpc"
 	"runtime"
 	"time"
 )
@@ -134,6 +136,7 @@ func (m *Mobile) SwordfishPay() error {
 					i_credit := util.IntAll(user["i_credit"])
 					if i_credit > 0 {
 						isPay := map[string]interface{}{}
+						mapPush := map[string]string{}
 						for _, v := range types {
 							util.Try(func() {
 								obj_typei := user["o_msgset"].(map[string]interface{})[v]
@@ -157,6 +160,7 @@ func (m *Mobile) SwordfishPay() error {
 								}
 								if b_newopen { //进行扣费操作
 									isPay[v] = v
+									mapPush[v] = util.If(v == "bid", "中标", "招标").(string)
 								}
 							}, func(e interface{}) {
 								log.Println(e)
@@ -168,6 +172,25 @@ func (m *Mobile) SwordfishPay() error {
 								//先扣分,然后更新,然后返回结果
 								res["credit"] = i_credit
 								res["oprstatus"] = true
+								//初次提交积分时
+								//加上剑鱼是否推送过的逻辑判断
+								util.Try(func() {
+									//对用户进行推送
+									var repl int
+									clent, errs := rpc.DialHTTP("tcp", coreconfig.SysConfig.PushRpc)
+									defer clent.Close()
+									rpcData := qrpc.PushData{
+										Mopenid:  m.GetSession("s_m_openid").(string),
+										PushType: mapPush,
+									}
+									go clent.Call("PushInfo.PushMsg", &rpcData, &repl)
+									if errs == nil {
+										//修改剑鱼占位值
+
+									}
+								}, func(e interface{}) {
+									log.Println("给用户摄推送出错", e)
+								})
 							}
 						} else {
 							res["credit"] = i_credit

+ 1 - 2
core/src/timetask.json

@@ -1,2 +1 @@
-{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-18 14:14:51"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-18 14:14:51"}},"marketisstart":true,"marketrate":300}
-
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-18 16:22:55"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-18 16:22:55"}},"marketisstart":true,"marketrate":300}

+ 1 - 65
push/src/config.json

@@ -1,65 +1 @@
-{
-    "bid": {
-        "interval": 60,
-        "lastpushtime": "2015-10-10 10:10:10"
-    },
-    "bidStartTime": "2015-12-17 14:10:11",
-    "bidTitle": "亲!剑鱼为您速报最新鲜的中标信息啦",
-    "bidViewDomain": "192.168.3.132",
-    "bidrStartTime": "2015-12-30 17:27:31",
-    "durationMinutes": 1,
-    "fixPush": "oJULtwzXo6EFV1Ah-XeyRBimXGM8",
-    "mail_bid": "\u003cdiv\u003e%s\u003c/div\u003e,想了解更多信息,请访问http://www.qimingxing.info。",
-    "maxPushSize": 50,
-    "mgoAddr": "192.168.3.18:27080",
-    "mgoSize": 10,
-    "province": {
-        "上海": 9,
-        "云南": 25,
-        "内蒙古": 5,
-        "北京": 1,
-        "台湾": 32,
-        "吉林": 7,
-        "四川": 13,
-        "天津": 2,
-        "宁夏": 30,
-        "安徽": 12,
-        "山东": 15,
-        "山西": 4,
-        "广东": 19,
-        "广西": 20,
-        "新疆": 31,
-        "江苏": 10,
-        "江西": 14,
-        "河北": 3,
-        "河南": 16,
-        "浙江": 11,
-        "海南": 21,
-        "湖北": 17,
-        "湖南": 18,
-        "澳门": 34,
-        "甘肃": 28,
-        "福建": 13,
-        "西藏": 26,
-        "贵州": 24,
-        "辽宁": 6,
-        "重庆": 22,
-        "陕西": 27,
-        "青海": 29,
-        "香港": 33,
-        "黑龙江": 8
-    },
-    "pushInfoScopeDays": 1,
-    "rpcPort": 8766,
-    "smtpAddr": "smtp.exmail.qq.com",
-    "smtpFromUser": "企明星",
-    "smtpPort": 465,
-    "smtpPwd": "qy123456",
-    "smtpUser": "qyfw@topnet.net.cn",
-    "tenderStartTime": "2015-12-17 14:10:11",
-    "tenderTitle": "亲!剑鱼为您速报最新鲜的招标信息啦",
-    "tenderrStartTime": "2015-12-30 17:27:29",
-    "weixinRpcServer": "127.0.0.1:82",
-    "weixin_bid": "\u003cdiv\u003e%s最新招标信息\u003c/div\u003e\u003cdiv\u003e%s\u003c/div\u003e",
-    "wxRpcRemark": "请到网站个人中心查看详细."
-}
+{"bid":{"interval":60,"lastpushtime":"2015-10-10 10:10:10"},"bidStartTime":"2015-12-30 17:28:48","bidTitle":"亲!剑鱼为您速报最新鲜的中标信息啦","bidViewDomain":"192.168.3.132","durationMinutes":10,"fixPush":"oJULtwzXo6EFV1Ah-XeyRBimXGM8","mail_bid":"\u003cdiv\u003e%s\u003c/div\u003e,想了解更多信息,请访问http://www.qimingxing.info。","maxPushSize":50,"mgoAddr":"192.168.3.18:27080","mgoSize":10,"province":{"上海":9,"云南":25,"内蒙古":5,"北京":1,"台湾":32,"吉林":7,"四川":13,"天津":2,"宁夏":30,"安徽":12,"山东":15,"山西":4,"广东":19,"广西":20,"新疆":31,"江苏":10,"江西":14,"河北":3,"河南":16,"浙江":11,"海南":21,"湖北":17,"湖南":18,"澳门":34,"甘肃":28,"福建":13,"西藏":26,"贵州":24,"辽宁":6,"重庆":22,"陕西":27,"青海":29,"香港":33,"黑龙江":8},"pushInfoScopeDays":30,"rpcPort":"8766","smtpAddr":"smtp.exmail.qq.com","smtpFromUser":"企明星","smtpPort":465,"smtpPwd":"qy123456","smtpUser":"qyfw@topnet.net.cn","tenderStartTime":"2015-12-30 17:28:48","tenderTitle":"亲!剑鱼为您速报最新鲜的招标信息啦","weixinRpcServer":"127.0.0.1:82","weixin_bid":"\u003cdiv\u003e%s最新招标信息\u003c/div\u003e\u003cdiv\u003e%s\u003c/div\u003e","wxRpcRemark":"请到网站个人中心查看详细."}

+ 25 - 0
push/src/qfw/push/bid/bid_test.go

@@ -4,9 +4,11 @@ import (
 	"fmt"
 	"log"
 	"math/rand"
+	"net/rpc"
 	"qfw/push"
 	"qfw/util"
 	"qfw/util/mongodb"
+	qrpc "qfw/util/rpc"
 	"strings"
 	"testing"
 	"time"
@@ -57,3 +59,26 @@ func Test_1(t *testing.T) {
 	a2 := push.GetChoiceCode(strings.Split("北京,河南,广东,山西,新疆", ",")...)
 	log.Println(a1, a2, a1&a2)
 }
+
+func Test_rpc(t *testing.T) {
+	log.Println("----------")
+	for i := 0; i < 30; i++ {
+		dd := qrpc.PushData{
+			Mopenid: "oJULtwzXo6EFV1Ah-XeyRBimXGM8",
+			PushType: map[string]string{
+				"tender": "招标",
+				"bid":    "中标",
+			},
+		}
+		var repl int
+		clent, _ := rpc.DialHTTP("tcp", "127.0.0.1:8766")
+		clent.Call("PushInfo.PushMsg", &dd, &repl)
+
+		log.Println(repl)
+		clent.Close()
+		time.Sleep(10 * time.Millisecond)
+	}
+
+	c := make(chan bool, 1)
+	<-c
+}

+ 9 - 9
push/src/qfw/push/dopush/dopush.go

@@ -40,7 +40,7 @@ func (p *Pjob) DoPush(mopenid, stime string, opr int, ltime int64) bool {
 	*p.Cache = push.InitCache(p.Stype, mopenid)
 	p.CreateUserInterestWord()
 	EachAllBidInfo(p.Stype, "["+p.StypeName+"信息]", p.StypeName, ltime, p.MaxPushSize, p.Dfa, p.Cache, opr)
-	return false
+	return true
 }
 
 //遍历数据并执行推送操作
@@ -99,18 +99,18 @@ L1:
 	}
 	now := time.Now()
 	if pushType == 1 && returnLastTime != nil {
-		push.PushConfig[stype+"rStartTime"] = util.FormatDateWithObj(&returnLastTime, util.Date_Full_Layout)
+		push.PushConfig[stype+"StartTime"] = util.FormatDateWithObj(&returnLastTime, util.Date_Full_Layout)
 	}
 	for k, v := range *(userMap) {
 		kk := *k
 		vv := *v
 		time.Sleep(50 * time.Millisecond)
-		go Send(&kk, &vv, now, TITLEA, ShortTitle, MaxPushSize)
+		go Send(&kk, &vv, now, TITLEA, ShortTitle, stype, MaxPushSize)
 	}
 }
 
 //全局推送功能
-func Send(k *push.MemberInterest, v *list.List, now time.Time, TITLEA, ShortTitle string, MaxPushSize int) {
+func Send(k *push.MemberInterest, v *list.List, now time.Time, TITLEA, ShortTitle, stype string, MaxPushSize int) {
 	defer func() {
 		if r := recover(); r != nil {
 			log.Println("[E]", r)
@@ -170,13 +170,13 @@ func Send(k *push.MemberInterest, v *list.List, now time.Time, TITLEA, ShortTitl
 
 	//3、发送微信
 	if len(k.Openid) > 0 {
-		SendWeixin(k, TITLE, ShortTitle, str, "", now, WXTitle, publishTimes)
+		SendWeixin(k, TITLE, ShortTitle, str, stype, now, WXTitle, publishTimes)
 	}
 
 }
 
 //推送微信
-func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, wxstr string, now time.Time, WXTitle string, publishTimes map[string]interface{}) {
+func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, stype string, now time.Time, WXTitle string, publishTimes map[string]interface{}) {
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("发送微信[E]", r)
@@ -192,7 +192,7 @@ func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, wxstr string, no
 		"s_province":    k.Province,
 		"a_interest":    k.Interest,
 		"s_content":     str,
-		"s_type":        "tender",
+		"s_type":        stype,
 		"a_publishtime": publishTimes,
 		"i_size":        len(publishTimes),
 	}
@@ -208,10 +208,10 @@ func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, wxstr string, no
 		wxDate = time.Now().Local().Add(time.Duration(-n2) * time.Second).Add(time.Duration(-n1*24) * time.Hour).Format(util.Date_Full_Layout)
 	}
 
-	wxstr = "\n点击下方“详情”查看详细信息。\n以上" + ShortTitle + "信息,是剑鱼根据关键字“" + strings.Join(k.Interest, ";") + "”奋力查找并推送,如不合您心意,请猛戳企明星菜单“会员服务—剑鱼”进行修改。"
+	wxstr := "\n点击下方“详情”查看详细信息。\n以上" + ShortTitle + "信息,是剑鱼根据关键字“" + strings.Join(k.Interest, ";") + "”奋力查找并推送,如不合您心意,请猛戳企明星菜单“会员服务—剑鱼”进行修改。"
 	push.SendWinXin(&qrpc.NotifyMsg{
 		Openid:  k.Openid,
-		Title:   push.PushConfig["tenderTitle"].(string),
+		Title:   push.PushConfig[stype+"Title"].(string),
 		Remark:  wxstr,
 		Detail:  WXTitle,
 		Date:    wxDate,

+ 8 - 1
push/src/qfw/push/rpcpush/rpcpush.go

@@ -2,6 +2,7 @@ package rpcpush
 
 import (
 	"fmt"
+	"log"
 	"qfw/push/bid"
 	"qfw/push/dopush"
 	qrpc "qfw/util/rpc"
@@ -14,6 +15,7 @@ type PushInfo struct {
 var PushInfoScopeDays int
 
 func (p *PushInfo) PushMsg(data *qrpc.PushData, Reply *int) error {
+	log.Println("dddddddd", data)
 	for k, v := range data.PushType {
 		//昨天到今天的数据
 		pj := dopush.Pjob{
@@ -23,7 +25,12 @@ func (p *PushInfo) PushMsg(data *qrpc.PushData, Reply *int) error {
 		}
 		now := time.Now()
 		tom := time.Date(now.Year(), now.Month(), now.Day()-PushInfoScopeDays, 0, 0, 0, 0, time.Local)
-		pj.DoPush(data.Mopenid, fmt.Sprintf("%d days", PushInfoScopeDays), 2, tom.Unix())
+		b := pj.DoPush(data.Mopenid, fmt.Sprintf("%d days", PushInfoScopeDays), 2, tom.Unix())
+		if b {
+			*Reply = 1
+		} else {
+			*Reply = 0
+		}
 	}
 	return nil
 }

+ 4 - 1
push/src/qfw/push/weixincall.go

@@ -6,9 +6,10 @@ import (
 	"net/rpc"
 	"qfw/util"
 	qrpc "qfw/util/rpc"
+	"time"
 )
 
-var wxpool chan bool = make(chan bool, 50)
+var wxpool chan bool = make(chan bool, 30)
 
 //微信远程调用,实现模板发送消息
 func SendWinXin(p *qrpc.NotifyMsg) {
@@ -18,6 +19,7 @@ func SendWinXin(p *qrpc.NotifyMsg) {
 	}()
 	util.Try(func() {
 		client, err := rpc.DialHTTP("tcp", PushConfig["weixinRpcServer"].(string))
+		defer client.Close()
 		if err != nil {
 			log.Println(err.Error())
 			return
@@ -28,4 +30,5 @@ func SendWinXin(p *qrpc.NotifyMsg) {
 			log.Println(err.Error())
 		}
 	}, func(e interface{}) {})
+	time.Sleep(10 * time.Millisecond)
 }