master
huanghai 5 years ago
parent edbcbee3b4
commit e591950952

@ -32,6 +32,8 @@ KafkaAddress = server.dsmin.com:9092
# 数据汇集的地址
[dataExchange]
url = http://10.10.14.239:9009/v1/dataex/DataexSet
AuthToken = DSDataex_Token_eb4ab2fea87161dc08fa794a648584c4
SystemId = BASE_GO
host = http://10.10.14.239:9009
exchangeUrl = /v1/dataex/DataexSet
SystemAuthUrl = /v1/dataex/SystemAuth
SystemId = BASE_GO
SystemKey = 96fa57b8-ac44-11ea-bd48-f48e38f73cf7

@ -2,12 +2,14 @@ package DataExchange
import (
"bytes"
"crypto/md5"
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/ConfigUtil"
"dsBaseRpc/Utils/DbUtil"
"dsBaseRpc/Utils/FileUtil"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
@ -234,16 +236,51 @@ func UploadData() int {
return postCount
}
// 获取签名用的结构体
type authStruct struct {
AuthTime string `json:"auth_time"`
SystemId string `json:"system_id"`
SystemToken string `json:"system_token"`
}
/**
2020-07-17
*/
func PostToServer(t tableStruct, list []map[string]interface{}) bool {
//(1)计算出system_token=MD5.hash(MD5.hash(system_id+auth_time)+system_key)
var as authStruct
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))
//系统token
as.SystemToken=md5str
//(2)根据system_token换取authToken
jsonBytes, err := json.Marshal(as)
if err != nil {
fmt.Println(CommonUtil.GetCurrentTime() +err.Error())
return false
}
p := httpDo("POST", ConfigUtil.DataExchangeSystemAuthUrl, string(jsonBytes))
if !p.Success {
fmt.Println(CommonUtil.GetCurrentTime() +"获取认证签名失败!")
return false
}
//上报到Http Api--->Body--->Post
var ps postStruct
ps.DataSource = t.DataSource
ps.AuthToken = ConfigUtil.DataExchangeAuthToken
ps.AuthToken =p.Message //p.Message中记录了authToken
ps.SystemId = ConfigUtil.DataExchangeSystemId
var dsMap = make([]dataStruct, 0)
for k := range list {
@ -263,10 +300,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)

@ -158,7 +158,7 @@ func PageAreaManager(in *SysLoginpersonProto.AreaManagerArg) ([]map[string]inter
var limit = int(in.Limit)
var offset = int((in.Page - 1) * in.Limit)
//主管区域码下有哪些区域
sql := "select area_code from t_gov_area where master_code=?"
sql := "select area_code from t_gov_area where master_code=?"
list, _ := db.SQL(sql, in.AreaCode).Query().List()
areaCodes := make([]string, 0)
for i := range list {

@ -40,9 +40,11 @@ var (
KafkaAddress string
//数据汇集中心地址
DataExchangeUrl string
DataExchangeAuthToken string
DataExchangeSystemId string
DataExchangeHost string
DataExchangeUrl string
DataExchangeSystemAuthUrl string
DataExchangeSystemId string
DataExchangeSystemKey string
)
func init() {
@ -99,9 +101,11 @@ func init() {
KafkaAddress = iniParser.GetString("kafka", "KafkaAddress")
//数据汇集中心地址
DataExchangeUrl=iniParser.GetString("dataExchange","url")
DataExchangeAuthToken =iniParser.GetString("dataExchange","AuthToken")
DataExchangeSystemId =iniParser.GetString("dataExchange","SystemId")
DataExchangeHost = iniParser.GetString("dataExchange", "host")
DataExchangeUrl = DataExchangeHost + iniParser.GetString("dataExchange", "exchangeUrl")
DataExchangeSystemAuthUrl = DataExchangeHost + iniParser.GetString("dataExchange", "SystemAuthUrl")
DataExchangeSystemId = iniParser.GetString("dataExchange", "SystemId")
DataExchangeSystemKey = iniParser.GetString("dataExchange", "SystemKey")
}
type IniParser struct {

Loading…
Cancel
Save