httplib_version_serve.go 1.7 KB
package version_server

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
)

//公共短信服务模块
type HttpLibVersionServer struct {
	service_gateway.BaseServiceGateway
	baseUrL string
}

func NewHttpLibVersionServer() *HttpLibVersionServer {
	return &HttpLibVersionServer{
		BaseServiceGateway: service_gateway.BaseServiceGateway{
			ConnectTimeout:   100 * time.Second,
			ReadWriteTimeout: 30 * time.Second,
		},
		baseUrL: constant.SUPLUS_ADMIN_BASE_HOST,
	}

}

//SendSms 公共短信验证码服务 发送验证码
func (gateway HttpLibVersionServer) GetLatestVersion(rc *http.Request, param ReqLatestVersion) (*DataLatestVersion, error) {
	url := gateway.baseUrL + "/version/getLatestVersionInfo"
	method := "post"
	req := gateway.CreateRequest(url, method)
	//TODO traceID
	log.Logger.Debug("向版本管理请求数据:搜索用户列表。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("搜索版本失败:%w", err)
	}
	for k, vs := range rc.Header {
		for i := range vs {
			req.Header(k, vs[i])
		}
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取版本失败:%w", err)
	}

	fmt.Println(string(byteResult))
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析版本:%w", err)
	}
	var data DataLatestVersion
	err = gateway.GetResponseData(result, &data)
	return &data, err
}