diff --git a/api/zking/index.go b/api/zking/index.go index 238c4d0..6999085 100644 --- a/api/zking/index.go +++ b/api/zking/index.go @@ -131,7 +131,35 @@ func Revoke(c *gin.Context) { return } - fmt.Println(param) + revokeData := zking.RevokeCallbackData{} + err = json.Unmarshal([]byte(param.Data), &revokeData) + if err != nil { + fmt.Println(err.Error()) + result["code"] = 201 + result["msg"] = "data异常" + c.JSON(200, result) + return + } + + global.DB.Model(&model.Revoke{}).Where("policy_no", revokeData.PolicyNo).UpdateColumns(model.Revoke{Status: revokeData.Status, Msg: revokeData.Msg}) + fmt.Println("revokeData", revokeData) + + callbackParam := suixing.RevokeCallbackParam{} + callbackParam.AppID = global.Config.Suixing.AppID + callbackParam.RequestID = utils.GenerateNo("requestId") + callbackParam.Version = "1.0.0" + callbackParam.Timestamp = strconv.Itoa(int(time.Now().Unix())) + callbackData := suixing.RevokeCallbackData{ + PolicyNo: revokeData.PolicyNo, + Msg: revokeData.Msg, + Status: revokeData.Status, + } + callbackParam.Data = callbackData + callbackRet, err := suixing.SuixingApi.RevokeCallback(callbackParam) + fmt.Println(callbackRet) + + c.JSON(200, result) + return } func Claim(c *gin.Context) { @@ -152,4 +180,34 @@ func Claim(c *gin.Context) { return } fmt.Println(param) + + claimData := zking.ClaimCallbackData{} + err = json.Unmarshal([]byte(param.Data), &claimData) + if err != nil { + fmt.Println(err.Error()) + result["code"] = 201 + result["msg"] = "data异常" + c.JSON(200, result) + return + } + + global.DB.Model(&model.Claim{}).Where("policy_no", claimData.PolicyNo).UpdateColumns(model.Claim{Status: claimData.Status, Msg: claimData.Msg}) + fmt.Println("claimData", claimData) + + callbackParam := suixing.ClaimCallbackParam{} + callbackParam.AppID = global.Config.Suixing.AppID + callbackParam.RequestID = utils.GenerateNo("requestId") + callbackParam.Version = "1.0.0" + callbackParam.Timestamp = strconv.Itoa(int(time.Now().Unix())) + callbackData := suixing.ClaimCallbackData{ + PolicyNo: claimData.PolicyNo, + Msg: claimData.Msg, + Status: claimData.Status, + } + callbackParam.Data = callbackData + callbackRet, err := suixing.SuixingApi.ClaimCallback(callbackParam) + fmt.Println(callbackRet) + + c.JSON(200, result) + return } diff --git a/third_party/suixing/api.go b/third_party/suixing/api.go index 8f2bc54..5026aa3 100644 --- a/third_party/suixing/api.go +++ b/third_party/suixing/api.go @@ -41,6 +41,52 @@ func (api *suixingApi) CreateOrderCallback(param CreateCallbackParam) (*Result, return &result, nil } +func (api *suixingApi) ClaimCallback(param ClaimCallbackParam) (*Result, error) { + paramBytes, err := json.Marshal(param) + if err != nil { + return nil, err + } + dataRet := gjson.Get(string(paramBytes), "data") + + err = api.Sign(¶m.CommonParam, dataRet.String()) + if err != nil { + return nil, err + } + res, err := api.post("/CallBack/claimGuarantee", param) + if err != nil { + return nil, err + } + result := Result{} + err = json.Unmarshal(res, &result) + if err != nil { + return nil, err + } + return &result, nil +} + +func (api *suixingApi) RevokeCallback(param RevokeCallbackParam) (*Result, error) { + paramBytes, err := json.Marshal(param) + if err != nil { + return nil, err + } + dataRet := gjson.Get(string(paramBytes), "data") + + err = api.Sign(¶m.CommonParam, dataRet.String()) + if err != nil { + return nil, err + } + res, err := api.post("/CallBack/revokeGuarantee", param) + if err != nil { + return nil, err + } + result := Result{} + err = json.Unmarshal(res, &result) + if err != nil { + return nil, err + } + return &result, nil +} + func (api *suixingApi) Sign(param *CommonParam, data string) error { //vals, err := utils.StructToURLValues(param) fmt.Println("data: " + data) diff --git a/third_party/suixing/claim_callback_data.go b/third_party/suixing/claim_callback_data.go new file mode 100644 index 0000000..85ab996 --- /dev/null +++ b/third_party/suixing/claim_callback_data.go @@ -0,0 +1,7 @@ +package suixing + +type ClaimCallbackData struct { + PolicyNo string `json:"policyNo" form:"policyNo"` + Status string `json:"status" form:"status"` + Msg string `json:"msg" form:"msg"` +} diff --git a/third_party/suixing/claim_callback_param.go b/third_party/suixing/claim_callback_param.go new file mode 100644 index 0000000..37bcaa6 --- /dev/null +++ b/third_party/suixing/claim_callback_param.go @@ -0,0 +1,6 @@ +package suixing + +type ClaimCallbackParam struct { + CommonParam + Data ClaimCallbackData `json:"data" form:"data"` +} diff --git a/third_party/suixing/revoke_callback_data.go b/third_party/suixing/revoke_callback_data.go new file mode 100644 index 0000000..2a9f1cc --- /dev/null +++ b/third_party/suixing/revoke_callback_data.go @@ -0,0 +1,7 @@ +package suixing + +type RevokeCallbackData struct { + PolicyNo string `json:"policyNo" form:"policyNo"` + Status string `json:"status" form:"status"` + Msg string `json:"msg" form:"msg"` +} diff --git a/third_party/suixing/revoke_callback_param.go b/third_party/suixing/revoke_callback_param.go new file mode 100644 index 0000000..078df9f --- /dev/null +++ b/third_party/suixing/revoke_callback_param.go @@ -0,0 +1,6 @@ +package suixing + +type RevokeCallbackParam struct { + CommonParam + Data RevokeCallbackData `json:"data" form:"data"` +}