123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package common
- import (
- "errors"
- "fmt"
- "log"
- "net/rpc"
- "strings"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
- qutil "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "k8s.io/apimachinery/pkg/util/json"
- )
- func AppPushMsg(userInfo map[string]interface{}, sth, appPushUrl, title, detail string, msgType int64, category string) error {
- if userInfo == nil {
- return fmt.Errorf("为查询到用户信息")
- }
- //限制
- //校验发送间隔
- userId := mongodb.BsonIdToSId(userInfo["_id"])
- if pushSetMap := qutil.ObjToMap(userInfo["o_pushset"]); pushSetMap != nil && len(*pushSetMap) > 0 {
- if pushKeyMap := qutil.ObjToMap((*pushSetMap)[sth]); pushKeyMap != nil && len(*pushKeyMap) > 0 {
- if qutil.Int64All((*pushKeyMap)["i_apppush"]) == 1 {
- //用户信息
- var otherPushId, jgPushId, phoneType, name, appVersion = "", "", "", "", ""
- otherPushId = qutil.ObjToString(userInfo["s_opushid"])
- jgPushId = qutil.ObjToString(userInfo["s_jpushid"])
- phoneType = qutil.ObjToString(userInfo["s_appponetype"])
- name = qutil.ObjToString(userInfo["s_name"])
- appVersion = qutil.ObjToString(userInfo["s_appversion"])
- if strings.Contains(phoneType, "iPhone") && strings.HasPrefix(appPushUrl, "/") && msgType != 10 {
- appPushUrl = appPushUrl[1:]
- }
- dt := map[string]interface{}{
- "receiveUserId": userId,
- "receiveName": name,
- "title": title,
- "content": detail,
- "msgType": "messagecenter",
- "link": appPushUrl,
- "appid": "10000",
- "menuName": "message",
- }
- //推送消息
- if appVersion > "3.0.3" {
- if sth == "o_msg_privateletter" {
- category = "私信"
- }
- if err := AppGrpcPush(dt, otherPushId, jgPushId, phoneType, appPushUrl, category); err != nil {
- return err
- }
- //redis.Put(CacheDb, userKey, 1, config.ConfigJson.WxTmplConfig.Limit.DuringMine*60)
- }
- }
- }
- }
- return nil
- }
- func AppGrpcPush(pushData map[string]interface{}, otherPushId, jgPushId, phoneType, appPushUrl, category string) error {
- menuName := "message"
- if value, ok := pushData["menuName"]; ok {
- menuName = qutil.ObjToString(value)
- }
- var repl string
- client, err := rpc.DialHTTP("tcp", config.ConfigJson.PushGrpcServer)
- if err != nil {
- log.Println(err.Error())
- return err
- }
- defer client.Close()
- // "title": "您有新的招标信息!", //标题
- // "descript": "1. 云浮市人民医院云浮市人民医院新生儿科医用设备及配套医用器具、辅助设施采购项目采购计划", //副标题
- // "descriptAppend": "\n...(共251条)",
- // "otherPushId": s_opushid, //mongodb库user表中s_opushid
- // "jgPushId": s_jpushid, //mongodb库user表中s_jpushid
- // "userId": BsonIdToSId((*u)["_id"]), //mongodb库user表中_id转string
- // "phoneType": "iPhone", //mongodb库user表中s_appponetype
- // "type": "bid", //消息类型,消息中心推送的消息使用messagecenter
- // "url": "/jyapp/free/sess/" + encrypt.SE.EncodeString("111"+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",historypush") + "__free__" + fmt.Sprint(time.Now().Unix()),
- // "menuName": "subscribe", //在哪个webview打开链接,search:搜索 subscribe:订阅 box:百宝箱 me:我的 other:新的webview message:消息
- // "redDot": "subscribe", //在哪个底部菜单显示小红点,空值则不显示小红点,search:搜索 subscribe:订阅 box:百宝箱 me:我的 message:消息
- //
- push := map[string]interface{}{
- "title": pushData["title"], //标题
- "descript": pushData["content"], //副标题
- "otherPushId": otherPushId, //mongodb库user表中s_opushid
- "jgPushId": jgPushId, //mongodb库user表中s_jpushid
- "userId": pushData["receiveUserId"], //mongodb库user表中_id转string
- "phoneType": phoneType, //mongodb库user表中s_appponetype
- "type": "messagecenter", //消息类型,消息中心推送的消息使用messagecenter
- "url": appPushUrl, //点了消息以后,跳转的链接地址,不需要带域名
- "menuName": menuName, //在哪个webview打开链接,search:搜索 subscribe:订阅 box:百宝箱 me:我的 other:新的webview 消息中心 message
- "redDot": "", //在哪个底部菜单显示小红点,空值则不显示小红点,search:搜索 subscribe:订阅 box:百宝箱 me:我的
- "category": category,
- }
- log.Println("push推送内容====", push)
- b, _ := json.Marshal(push)
- err = client.Call("Rpc.Push", b, &repl)
- if err != nil {
- log.Println(err.Error())
- return err
- }
- if repl != "y" {
- log.Println("推送失败!", repl, pushData["receiveUserId"])
- return errors.New("推送失败")
- }
- return nil
- }
|