Merge branch 'master' of 10.10.14.250:huanghai/dsMin

master
wubin 5 years ago
commit e83749e574

@ -71,6 +71,10 @@ type logStruct struct {
IdInt int64 `json:"id_int"`
}
//系统token
var SystemToken=""
//是否成功
var success =false
/**
*/
@ -93,7 +97,7 @@ func InitFull() {
if !FileUtil.PathExists(logName) {
//SQL内容
isql := FileUtil.ReadFileContent("./Sql/" + FullSqlDict[i].TableName + ".sql")
sql:=isql
sql := isql
var list []map[string]interface{}
//如果是组织机构表,那么需要变更一下查询的排序条件
if FullSqlDict[i].TableName == "t_base_organization" {
@ -159,11 +163,15 @@ func InitFull() {
2020-07-16
*/
func DataExchange() {
//获取系统token
success,SystemToken=getSystemToken()
if !success{
return
}
//死循环上报中
for {
//(1)组织机构上报
InitFull()
//(2)本轮上报的数量如果是0休息5秒后再继续上传
postCount := UploadData()
if postCount == 0 {
@ -238,49 +246,54 @@ func UploadData() int {
// 获取签名用的结构体
type authStruct struct {
AuthTime string `json:"auth_time"`
SystemId string `json:"system_id"`
AuthTime string `json:"auth_time"`
SystemId string `json:"system_id"`
SystemToken string `json:"system_token"`
}
/**
token
2020-07-17
*/
func PostToServer(t tableStruct, list []map[string]interface{}) bool {
2020-07-22
*/
func getSystemToken() (bool, string) {
//(1)计算出system_token=MD5.hash(MD5.hash(system_id+auth_time)+system_key)
var as authStruct
as.AuthTime=CommonUtil.GetCurrentTime()
as.SystemId=ConfigUtil.DataExchangeSystemId
as.AuthTime = CommonUtil.GetCurrentTime()
as.SystemId = ConfigUtil.DataExchangeSystemId
//计算 md5
w := md5.New()
io.WriteString(w, as.SystemId+as.AuthTime)
//将str写入到w中
md5str := fmt.Sprintf("%x", w.Sum(nil))
w = md5.New()
io.WriteString(w, md5str+ConfigUtil.DataExchangeSystemKey)
//将str写入到w中
md5str= fmt.Sprintf("%x", w.Sum(nil))
md5str = fmt.Sprintf("%x", w.Sum(nil))
//系统token
as.SystemToken=md5str
as.SystemToken = md5str
//(2)根据system_token换取authToken
jsonBytes, err := json.Marshal(as)
if err != nil {
fmt.Println(CommonUtil.GetCurrentTime() +err.Error())
return false
}
jsonBytes, _ := json.Marshal(as)
p := httpDo("POST", ConfigUtil.DataExchangeSystemAuthUrl, string(jsonBytes))
if !p.Success {
fmt.Println(CommonUtil.GetCurrentTime() +"获取认证签名失败!")
return false
fmt.Println(CommonUtil.GetCurrentTime() + "获取认证签名失败!")
return false,"获取认证签名失败!"
}
return true,p.Message
}
/**
2020-07-17
*/
func PostToServer(t tableStruct, list []map[string]interface{}) bool {
//上报到Http Api--->Body--->Post
var ps postStruct
ps.DataSource = t.DataSource
ps.AuthToken =p.Message //p.Message中记录了authToken
ps.AuthToken = SystemToken //p.Message中记录了authToken
ps.SystemId = ConfigUtil.DataExchangeSystemId
var dsMap = make([]dataStruct, 0)
for k := range list {
@ -300,10 +313,10 @@ func PostToServer(t tableStruct, list []map[string]interface{}) bool {
}
ps.Datas = dsMap
//将Struct转为json
jsonBytes, _ = json.Marshal(ps)
jsonBytes, _ := json.Marshal(ps)
msg := string(jsonBytes)
//提交到汇集中心
p = httpDo("POST", ConfigUtil.DataExchangeUrl, msg)
p := httpDo("POST", ConfigUtil.DataExchangeUrl, msg)
if !p.Success {
fmt.Println(CommonUtil.GetCurrentTime() + " 同步上报到数据汇集中心失败将休息5秒后重试错误原因" + p.Message)
time.Sleep(5 * 1e9)
@ -388,7 +401,7 @@ type ResultStruct struct {
func httpDo(method string, url string, msg string) ResultStruct {
var p ResultStruct
p.Success = false
p.Message = "上报到汇集系统失败!"
p.Message = "上报到汇集系统失败!请检查是否SystemToken是有效的或者有两个及以上客户端同时在上报。"
client := &http.Client{}
body := bytes.NewBuffer([]byte(msg))
req, err := http.NewRequest(method,

Loading…
Cancel
Save