add push and fix name and faceurl

pull/103/head
Gordon 3 years ago
parent 30be5c2c48
commit fe80b7da5c

@ -122,6 +122,7 @@ push:
jpns:
appKey: 2783339cee4de379cc798fe1
masterSecret: 66e5f309e032c68cc668c28a
pushUrl: "https://api.jpush.cn/v3/push"
manager:
appManagerUid: ["openIM123456","openIM654321"]
secrets: ["openIM1","openIM2"]

@ -113,6 +113,7 @@ type config struct {
Jpns struct {
AppKey string `yaml:"appKey"`
MasterSecret string `yaml:"masterSecret"`
PushUrl string `yaml:"pushUrl"`
}
}
Manager struct {

@ -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) {

@ -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)

@ -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
}

@ -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")
}
}

@ -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

Loading…
Cancel
Save