master
kgdxpr 4 years ago
parent c9e33e2377
commit fa02e48faa

@ -3,8 +3,12 @@
<component name="ChangeListManager">
<list default="true" id="19c8c37d-a056-451c-a29d-fb612b9a3e2f" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Config/Config.ini" beforeDir="false" afterPath="$PROJECT_DIR$/Config/Config.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/CommonUtil/CommonUtil.go" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/CommonUtil/CommonUtil.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/ConfigUtil/ConfigUtil.go" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ConfigUtil/ConfigUtil.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -25,6 +29,9 @@
<component name="GoLibraries">
<option name="indexEntireGoPath" value="false" />
</component>
<component name="ProblemsViewState">
<option name="selectedIndex" value="1" />
</component>
<component name="ProjectId" id="1wHqoZ4Mc0xnzUNKevge8S7NouM" />
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="1" id="Add" />
@ -42,7 +49,7 @@
<property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
<property name="last_opened_file_path" value="H:/Go_Test/Test03" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../dsBaseWeb" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
</component>
<component name="RecentsManager">

@ -18,6 +18,30 @@ func Routers(r *gin.RouterGroup) {
rr.GET("/GetPersonInfoList", GetPersonInfoList)
rr.POST("/CreateGroup", CreateGroup)
rr.POST("/SyncRongYunUser", SyncRongYunUser)
rr.POST("/SendSystemMsg", SendSystemMsg)
}
/**
2021-09-17
*/
func SendSystemMsg(c *gin.Context) {
//发送方Id。
fromId := c.PostForm("fromId")
//接收方Id。
toId := c.PostForm("toId")
//内容
content := c.PostForm("content")
err := ImRelateDao.SendSystemMsg(fromId, toId, content)
if err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "info": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送系统成功!"})
}
/**
@ -135,11 +159,11 @@ func SaveChatRecord(c *gin.Context) {
bodyString := string(bodyJsonObj)
saveErr := ImRelateDao.SaveChatRecord("chat_record", bodyString)
if saveErr != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "info": "聊天记录保存失败!"})
c.JSON(http.StatusOK, gin.H{"success": false, "info": "保存聊天记录失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
c.JSON(http.StatusOK, gin.H{"success": true, "info": "保存聊天记录成功!"})
}
/**

@ -15,8 +15,11 @@ import (
"github.com/xormplus/xorm"
"strconv"
"strings"
"time"
)
var db = DbUtil.Engine
//人员信息结构
type Person struct {
Success bool `json:"success"`
@ -447,3 +450,159 @@ func AddGroupMember(groupId string, personList string, personIdCookie string, id
return nil
}
/**
2021-09-13
*/
func SyncRongYunUser() {
ts, inc := getRongYunSync("person")
sql := "select person_id,person_name,last_update_time from t_base_person where b_use=1 and identity_id=5 and ((last_update_time=? and person_id>?) or last_update_time>?) order by last_update_time,person_id limit 200"
res, _ := db.QueryString(sql, ts, inc, ts)
count := len(res) - 1
for i, v := range res {
personId := v["person_id"]
personName := v["person_name"]
updateTs := v["last_update_time"]
RongYunGetToken(personId, "5", personName, "")
if i == count {
updateRongYunSync("person", updateTs, personId)
}
}
// 每1分钟执行一次
time.AfterFunc(1*time.Minute, SyncRongYunUser)
}
/**
2021-09-13
*/
func SyncRongYunGroup() {
ts, inc := getRongYunSync("group")
sql := "select t1.id,t1.group_id,t2.group_name,t1.person_id,t1.identity_id,t1.last_update_time from t_base_group_member_new t1 inner join t_base_group_new t2 on t1.group_id=t2.id where t1.identity_id=5 and t1.state_id=1 and t1.b_use=1 and ((t1.last_update_time=? and t1.id>?) or t1.last_update_time>?) order by t1.last_update_time,t1.id limit 200"
res, _ := db.QueryString(sql, ts, inc, ts)
count := len(res) - 1
for i, v := range res {
personId := v["person_id"]
identityId := v["identity_id"]
groupId := v["group_id"]
groupName := v["group_name"]
updateTs := v["last_update_time"]
id := v["id"]
RongYunJoinGroup(personId, identityId, groupId, groupName)
if i == count {
updateRongYunSync("group", updateTs, id)
}
}
// 每1分钟执行一次
time.AfterFunc(1*time.Minute, SyncRongYunGroup)
}
/**
2021-09-13
*/
func RongYunJoinGroup(personId, identityId, groupId, groupName string) error {
//获取云平台配置文件中的融云AK和SK
configMap, configErr := CommonUtil.GetRongYunConfig()
if configErr != nil {
return configErr
}
ak := configMap["app_key"]
sk := configMap["app_secret"]
suffix := configMap["rong_server_name"]
rc := sdk.NewRongCloud(ak, sk)
group := []sdk.Group{sdk.Group{ID: groupId + suffix, Name: groupName}}
err := rc.GroupSync(
personId+"_"+identityId+suffix,
group,
)
return err
}
/**
ID
2021-09-13
*/
func getRongYunSync(classify string) (string, string) {
record := make(xorm.Record)
sql := "select ts,inc from t_dsmin_rongyun_sync where classify=?"
db.SQL(sql, classify).Get(&record)
ts := record["ts"].String()
inc := record["inc"].String()
return ts, inc
}
/**
ID
2021-09-13
*/
func updateRongYunSync(classify, ts, inc string) {
sql := "update t_dsmin_rongyun_sync set ts=?,inc=? where classify=?"
db.Exec(sql, ts, inc, classify)
}
/**
2021-09-17
*/
func SendSystemMsg(fromId, toId, content string) error {
req := httplib.Post(fmt.Sprintf("%s/message/system/publish.json", ConfigUtil.RongYunApiUri))
addHeader(req)
req.Param("fromUserId", fromId)
req.Param("toUserId", toId)
req.Param("objectName", "RC:TxtMsg")
req.Param("content", content)
resStr, err := req.String()
if err != nil {
return err
}
resMap := make(map[string]interface{})
errJson := json.Unmarshal([]byte(resStr), &resMap)
if errJson != nil {
return errJson
}
if resMap["code"].(float64) != 200 {
return errors.New(resMap["errorMessage"].(string))
}
return nil
}
/**
API
2021-09-17
*/
func addHeader(req *httplib.BeegoHTTPRequest) {
configMap, configErr := CommonUtil.GetRongYunConfig()
if configErr != nil {
fmt.Println("获取融云配置文件失败!")
return
}
ak := configMap["app_key"]
sk := configMap["app_secret"]
nonce := CommonUtil.GetSixRandom()
timestamp := CommonUtil.GetTimeStamp()
req.Header("RC-App-Key", ak)
req.Header("RC-Nonce", nonce)
req.Header("RC-Timestamp", timestamp)
req.Header("RC-Signature", CommonUtil.SHA1(sk+nonce+timestamp))
}

@ -61,6 +61,7 @@ path = /usr/local/dsMin/dsSzxy/files/
[rongyun]
#config_path = /usr/local/tomcat7/webapps/dsideal_yy/WEB-INF/classes/config.properties
config_path = c:/1/config.properties
api_uri = https://api-cn.ronghub.com
[videoThumb]
thumb = data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNjI5NDQ3MDA4MTUxIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDE1MTIgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC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dC
Domain: ConfigUtil.DsidealYyDomain,
})
}

@ -53,6 +53,7 @@ var (
//融云配置文件位置
RongYunConfigPath string
RongYunApiUri string
//SSDB
SSDBIp string
@ -150,6 +151,7 @@ func init() {
//融云配置文件位置
RongYunConfigPath = iniParser.GetString("rongyun", "config_path")
RongYunApiUri = iniParser.GetString("rongyun", "api_uri")
//SSDB
SSDBIp = iniParser.GetString("ssdb", "ip")

@ -49,6 +49,9 @@ func main() {
r.Use(Utils.Cors())
//参数有效性验证拦截器
r.Use(Handler.ParameterHandler())
//向融云同步数据
//go ImRelateDao.SyncRongYunUser()
//go ImRelateDao.SyncRongYunGroup()
//主路由
Router.GinRouter(r)
// 监听并在 0.0.0.0:8006 上启动服务

Loading…
Cancel
Save