56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package tysk
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"gitea.cdlsxd.cn/self-tools/l_request"
|
|
"gitea.cdlsxd.cn/self-tools/tysk/constant"
|
|
"gitea.cdlsxd.cn/self-tools/tysk/entity"
|
|
"gitea.cdlsxd.cn/self-tools/tysk/pkg"
|
|
)
|
|
|
|
func (g *Tysk) handleRequest(Action constant.RequestCode, requestData map[string]interface{}, result interface{}) (err error) {
|
|
reqData := pkg.XmlRequest{
|
|
Action: Action,
|
|
UserName: g.UserName,
|
|
ExtraFields: requestData,
|
|
}
|
|
gbkXML, err := reqData.MarshalToXML()
|
|
if err != nil {
|
|
return
|
|
}
|
|
req := l_request.Request{
|
|
Method: "POST",
|
|
Url: g.getRequestUrl(),
|
|
Xml: gbkXML,
|
|
}
|
|
response, err := req.Send()
|
|
if err != nil {
|
|
return
|
|
}
|
|
resByte, err := pkg.XMLToByte(response.Text)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var commonResponse entity.RespCommon
|
|
err = json.Unmarshal(resByte, &commonResponse)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if commonResponse.Status != string(constant.Success) {
|
|
return fmt.Errorf("请求失败,错误码:%s,错误信息:%s", commonResponse.Status, commonResponse.FailReason)
|
|
}
|
|
|
|
return json.Unmarshal(resByte, result)
|
|
}
|
|
|
|
func (g *Tysk) getRequestUrl() string {
|
|
switch g.Env {
|
|
case "dev":
|
|
return "http://127.0.0.1:6789"
|
|
default:
|
|
return ""
|
|
}
|
|
|
|
}
|