diff --git a/config/config.yaml b/config/config.yaml index 8277fe038..4a53e1958 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -122,6 +122,7 @@ push: jpns: appKey: 2783339cee4de379cc798fe1 masterSecret: 66e5f309e032c68cc668c28a + pushUrl: "https://api.jpush.cn/v3/push" manager: appManagerUid: ["openIM123456","openIM654321"] secrets: ["openIM1","openIM2"] diff --git a/src/common/config/config.go b/src/common/config/config.go index 1022f56c9..6aa28cfd4 100644 --- a/src/common/config/config.go +++ b/src/common/config/config.go @@ -113,6 +113,7 @@ type config struct { Jpns struct { AppKey string `yaml:"appKey"` MasterSecret string `yaml:"masterSecret"` + PushUrl string `yaml:"pushUrl"` } } Manager struct { diff --git a/src/msg_gateway/gate/logic.go b/src/msg_gateway/gate/logic.go index 389a38a19..cbadadc53 100644 --- a/src/msg_gateway/gate/logic.go +++ b/src/msg_gateway/gate/logic.go @@ -213,27 +213,30 @@ func (ws *WServer) sendMsgResp(conn *UserConn, m *Req, pb *pbChat.UserSendMsgRes } func (ws *WServer) sendMsgReq(conn *UserConn, m *Req, sendTime int64) { - log.InfoByKv("Ws call success to sendMsgReq", m.OperationID, "Parameters", m) + log.InfoByKv("Ws call success to sendMsgReq start", m.OperationID, "Parameters") reply := new(pbChat.UserSendMsgResp) isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg) if isPass { data := pData.(pbWs.UserSendMsgReq) pbData := pbChat.UserSendMsgReq{ - ReqIdentifier: m.ReqIdentifier, - Token: m.Token, - SendID: m.SendID, - OperationID: m.OperationID, - PlatformID: data.PlatformID, - SessionType: data.SessionType, - MsgFrom: data.MsgFrom, - ContentType: data.ContentType, - RecvID: data.RecvID, - ForceList: data.ForceList, - Content: data.Content, - Options: utils.MapIntToJsonString(data.Options), - ClientMsgID: data.ClientMsgID, - SendTime: sendTime, + ReqIdentifier: m.ReqIdentifier, + Token: m.Token, + SendID: m.SendID, + OperationID: m.OperationID, + PlatformID: data.PlatformID, + SessionType: data.SessionType, + MsgFrom: data.MsgFrom, + ContentType: data.ContentType, + RecvID: data.RecvID, + ForceList: data.ForceList, + SenderNickName: data.SenderNickName, + SenderFaceURL: data.SenderFaceURL, + Content: data.Content, + Options: utils.MapIntToJsonString(data.Options), + ClientMsgID: data.ClientMsgID, + SendTime: sendTime, } + log.NewInfo(m.OperationID, "Ws call success to sendMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, data) time := utils.GetCurrentTimestampBySecond() etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) client := pbChat.NewChatClient(etcdConn) @@ -265,7 +268,7 @@ func (ws *WServer) sendMsg(conn *UserConn, mReply interface{}) { } err = ws.writeMsg(conn, websocket.BinaryMessage, b.Bytes()) if err != nil { - log.ErrorByKv("WS WriteMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err, "mReply", mReply) + log.NewError(mReply.(Resp).OperationID, mReply.(Resp).ReqIdentifier, mReply.(Resp).ErrCode, mReply.(Resp).ErrMsg, "WS WriteMsg error", conn.RemoteAddr().String(), ws.getUserUid(conn), err.Error()) } } func (ws *WServer) sendErrMsg(conn *UserConn, errCode int32, errMsg string, reqIdentifier int32, msgIncr string, operationID string) { diff --git a/src/push/jpush/common/JGPlatform.go b/src/push/jpush/common/JGPlatform.go index 6fd129675..e2e858cf4 100644 --- a/src/push/jpush/common/JGPlatform.go +++ b/src/push/jpush/common/JGPlatform.go @@ -5,10 +5,6 @@ import ( "fmt" ) -const ( - PushUrl = "https://api.jpush.cn/v3/push" -) - func GetAuthorization(Appkey string, MasterSecret string) string { str := fmt.Sprintf("%s:%s", Appkey, MasterSecret) buf := []byte(str) diff --git a/src/push/jpush/push.go b/src/push/jpush/push.go index 144b940d4..f1e7972f0 100644 --- a/src/push/jpush/push.go +++ b/src/push/jpush/push.go @@ -9,10 +9,13 @@ import ( "net/http" ) -func JGAccountListPush(accounts []string, jsonCustomContent string, Platform string) (*http.Response, error) { +type JPushResp struct { +} + +func JGAccountListPush(accounts []string, jsonCustomContent string, platform string) (*http.Response, error) { var pf requestBody.Platform - _ = pf.SetAndroid() + _ = pf.SetPlatform(platform) var au requestBody.Audience au.SetAlias(accounts) var no requestBody.Notification @@ -32,7 +35,7 @@ func JGAccountListPush(accounts []string, jsonCustomContent string, Platform str client := &http.Client{} - req, err := http.NewRequest("POST", common.PushUrl, bytes.NewBuffer(con)) + req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con)) if err != nil { return nil, err } diff --git a/src/push/jpush/requestBody/platform.go b/src/push/jpush/requestBody/platform.go index 1d871064e..5fe33ea43 100644 --- a/src/push/jpush/requestBody/platform.go +++ b/src/push/jpush/requestBody/platform.go @@ -1,6 +1,9 @@ package requestBody -import "errors" +import ( + "Open_IM/src/utils" + "errors" +) const ( ANDROID = "android" @@ -48,10 +51,14 @@ func (p *Platform) Set(os string) error { return nil } -func (p *Platform) setPlatform(platform string) { +func (p *Platform) SetPlatform(platform string) error { switch platform { - case ANDROID: - p.SetAndroid() + case utils.AndroidPlatformStr: + return p.SetAndroid() + case utils.IOSPlatformStr: + return p.SetIOS() + default: + return errors.New("platform err") } } diff --git a/src/push/logic/push_to_client.go b/src/push/logic/push_to_client.go index 855c21d89..2dd2b74e2 100644 --- a/src/push/logic/push_to_client.go +++ b/src/push/logic/push_to_client.go @@ -17,7 +17,6 @@ import ( rpcChat "Open_IM/src/rpc/chat/chat" "Open_IM/src/utils" "context" - "encoding/json" "strings" ) @@ -60,31 +59,32 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { } if isShouldOfflinePush { //Use offline push messaging - var UIDList []string - UIDList = append(UIDList, sendPbData.RecvID) - customContent := EChatContent{ - SessionType: int(sendPbData.SessionType), - From: sendPbData.SendID, - To: sendPbData.RecvID, - Seq: sendPbData.RecvSeq, - } - bCustomContent, _ := json.Marshal(customContent) - - jsonCustomContent := string(bCustomContent) - switch sendPbData.ContentType { - case constant.Text: - IOSAccountListPush(UIDList, sendPbData.SenderNickName, sendPbData.Content, jsonCustomContent) - case constant.Picture: - IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Picture], jsonCustomContent) - case constant.Voice: - IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Voice], jsonCustomContent) - case constant.Video: - IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Video], jsonCustomContent) - case constant.File: - IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.File], jsonCustomContent) - default: - - } + //var UIDList []string + //UIDList = append(UIDList, sendPbData.RecvID) + //customContent := EChatContent{ + // SessionType: int(sendPbData.SessionType), + // From: sendPbData.SendID, + // To: sendPbData.RecvID, + // Seq: sendPbData.RecvSeq, + //} + //bCustomContent, _ := json.Marshal(customContent) + // + //jsonCustomContent := string(bCustomContent) + //switch sendPbData.ContentType { + //case constant.Text: + // IOSAccountListPush(UIDList, sendPbData.SenderNickName, sendPbData.Content, jsonCustomContent) + //case constant.Picture: + // IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Picture], jsonCustomContent) + //case constant.Voice: + // IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Voice], jsonCustomContent) + //case constant.Video: + // IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.Video], jsonCustomContent) + //case constant.File: + // IOSAccountListPush(UIDList, sendPbData.SenderNickName, constant.ContentType2PushContent[constant.File], jsonCustomContent) + //default: + // + //} + //push.JGAccountListPush(UIDList,jsonCustomContent,utils.PlatformIDToName(t)) } else { isShouldOfflinePush = true