sync: 对齐小程序 v1.0.2 生产代码并脱敏
This commit is contained in:
@@ -19,6 +19,8 @@ type appUpstreamDefaultConfig struct {
|
||||
Timeout string `json:"timeout"`
|
||||
}
|
||||
|
||||
type appDiagnosisProxyContextKey struct{}
|
||||
|
||||
type appUpstreamSimKey struct {
|
||||
ChanKey string `json:"chanKey,omitempty"`
|
||||
ICCID string `json:"iccid,omitempty"`
|
||||
@@ -39,7 +41,7 @@ type appUpstreamSimQueryItem struct {
|
||||
}
|
||||
|
||||
type appUpstreamSimQueryResponse struct {
|
||||
Code int `json:"code"`
|
||||
Code *int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data []appUpstreamSimQueryItem `json:"data"`
|
||||
}
|
||||
@@ -57,7 +59,7 @@ func queryAppCardRealtimeSessionWithKey(ctx context.Context, row *appCardQueryRo
|
||||
if err == nil {
|
||||
return session, "upstream", nil
|
||||
}
|
||||
if !appUpstreamMockFallbackEnabled(ctx) {
|
||||
if ctx.Value(appDiagnosisProxyContextKey{}) == true || !appUpstreamMockFallbackEnabled(ctx) {
|
||||
return nil, "upstream", err
|
||||
}
|
||||
g.Log().Debugf(ctx, "app card session upstream query failed, fallback to onelink mock, iccid:%s, err:%+v", appCardQueryLogIccid(row), err)
|
||||
@@ -90,6 +92,7 @@ func queryAppCardRealtimeSessionByUpstreamWithKey(ctx context.Context, simKey *a
|
||||
if err = json.Unmarshal(item.ResData, &session); err != nil {
|
||||
return nil, gerror.Wrap(err, "解析上游会话响应失败")
|
||||
}
|
||||
appNormalizeUpstreamSession(&session, item.ResData)
|
||||
if !session.isZero() {
|
||||
return &session, nil
|
||||
}
|
||||
@@ -97,6 +100,42 @@ func queryAppCardRealtimeSessionByUpstreamWithKey(ctx context.Context, simKey *a
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func appNormalizeUpstreamSession(session *appOneLinkMockSimSessionItem, raw json.RawMessage) {
|
||||
if session == nil {
|
||||
return
|
||||
}
|
||||
if session.ApnId == "" {
|
||||
session.ApnId = appDiagnosisRawString(raw, "apnId", "apn")
|
||||
}
|
||||
if session.Rat == "" {
|
||||
session.Rat = appDiagnosisRawString(raw, "rat", "accessType", "netModel")
|
||||
}
|
||||
if session.Imei == "" {
|
||||
session.Imei = appDiagnosisRawString(raw, "imei", "IMEI")
|
||||
}
|
||||
if session.Ipv4 == "" {
|
||||
session.Ipv4 = appDiagnosisRawString(raw, "ipv4", "ipv4Address", "ip")
|
||||
}
|
||||
if session.Ipv6 == "" {
|
||||
session.Ipv6 = appDiagnosisRawString(raw, "ipv6", "ipv6Address")
|
||||
}
|
||||
if session.Ipv6Prefix == "" {
|
||||
session.Ipv6Prefix = appDiagnosisRawString(raw, "ipv6Prefix")
|
||||
}
|
||||
if session.CreateTime == "" {
|
||||
session.CreateTime = appDiagnosisRawString(raw, "createTime", "startTime")
|
||||
}
|
||||
if session.Status == "" {
|
||||
session.Status = appDiagnosisRawString(raw, "status", "onlineStatus", "sessionStatus")
|
||||
}
|
||||
if session.Status == "1" && appDiagnosisRawString(raw, "onlineStatus", "sessionStatus") != "" {
|
||||
session.Status = "-1"
|
||||
}
|
||||
if session.Status == "2" {
|
||||
session.Status = "-2"
|
||||
}
|
||||
}
|
||||
|
||||
func queryAppCardRealtimeSessionByMock(ctx context.Context, row *appCardQueryRow) (*appOneLinkMockSimSessionItem, error) {
|
||||
client, err := newAppOneLinkMockClient(ctx)
|
||||
if err != nil {
|
||||
@@ -171,18 +210,29 @@ func queryAppUpstreamSimWithKey(ctx context.Context, simKey *appUpstreamSimKey,
|
||||
client.SetDiscovery(gsvc.GetRegistry())
|
||||
appSetUpstreamClientTimeout(client, timeout)
|
||||
client.SetHeader("Content-Type", "application/json")
|
||||
if ctx.Value(appDiagnosisProxyContextKey{}) == true {
|
||||
token := strings.TrimSpace(g.Cfg().MustGet(ctx, "upstream.appDiagnosisToken").String())
|
||||
if token == "" {
|
||||
return nil, gerror.New("诊断代理内部令牌未配置")
|
||||
}
|
||||
requestURL = appUpstreamURL(cfg.ClientName, "/internal/app-diagnosis"+path)
|
||||
client.SetHeader("X-App-Diagnosis-Token", token)
|
||||
}
|
||||
resp, err := client.Post(ctx, requestURL, string(body))
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "请求上游信息失败")
|
||||
}
|
||||
defer resp.Close()
|
||||
respBody := resp.ReadAll()
|
||||
if ctx.Value(appDiagnosisProxyContextKey{}) == true && resp.StatusCode == http.StatusNotFound && strings.Contains(string(respBody), "诊断通道不可用") {
|
||||
return nil, gerror.New(appDiagnosisNotIncludedMessage)
|
||||
}
|
||||
|
||||
output := appUpstreamSimQueryResponse{}
|
||||
if err = json.Unmarshal(respBody, &output); err != nil {
|
||||
return nil, gerror.Wrap(err, "解析上游响应失败")
|
||||
}
|
||||
if output.Code != 0 {
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 || output.Code == nil || *output.Code != 0 {
|
||||
message := strings.TrimSpace(output.Message)
|
||||
if message == "" {
|
||||
message = "上游查询失败"
|
||||
|
||||
Reference in New Issue
Block a user