diff --git a/api/zking/index.go b/api/zking/index.go index 1599a54..cc12956 100644 --- a/api/zking/index.go +++ b/api/zking/index.go @@ -5,9 +5,15 @@ import ( "fmt" "github.com/gin-gonic/gin" "insure/e" + "insure/global" + "insure/model" "insure/service" + "insure/third_party/suixing" "insure/third_party/zking" + "insure/utils" "io" + "strconv" + "time" ) func checkParam(c *gin.Context) (*zking.CommonParam, error) { @@ -16,6 +22,9 @@ func checkParam(c *gin.Context) (*zking.CommonParam, error) { fmt.Printf("push body:%s\n", body) } + //str := "{\"data\":\"{\\\"msg\\\":\\\"成功\\\",\\\"policy_no\\\":\\\"2112223500002400001E\\\",\\\"code\\\":\\\"200\\\",\\\"ordersn\\\":\\\"2024070111083101\\\",\\\"gurantee_link\\\":\\\"https://test-open.zking.com/dz/1MvWxAw\\\",\\\"gurantee_link_md5\\\":\\\"D82B6EFE638F65A5C2057A16C90A9104\\\",\\\"invoice_link_md5\\\":\\\"8BB72B6C2354DB28CA227114D38E0D08\\\",\\\"confirm_receipt_link_md5\\\":\\\"BAF26A27C6DCC4FE502E667837293E12\\\",\\\"min_premium\\\":\\\"200\\\",\\\"service_amount\\\":\\\"300000\\\",\\\"rate\\\":\\\"6.6667E-4\\\",\\\"gurantee_ofd_link_md5\\\":\\\"02677B39A0B6C929DA4C5DE3D0FBC7B0\\\",\\\"confirm_receipt_link\\\":\\\"https://test-open.zking.com/dz/1MvWxAx\\\",\\\"gurantee_ofd_link\\\":\\\"https://oss.test-open.zking.com/external/20240703/d2e7e15dbeab43a6a82d3e95d0d909ca.ofd\\\",\\\"invoice_link\\\":\\\"http://oss.open.zking.com/static/2022-05-31/f185af975ef545898912f441f0b3a9ef.pdf\\\",\\\"status\\\":\\\"3\\\"}\",\"requestid\":\"96f3e266-4aad-499a-9dea-53594326a494\",\"appid\":\"zijin\",\"sign\":\"24e2d53f042f2e5e49367c9915b084415bf0e176\",\"version\":\"1.0.0\",\"timestamp\":\"1720020609675\"}" + //body = []byte(str) + param := zking.CommonParam{} err := json.Unmarshal(body, ¶m) if err != nil { @@ -62,7 +71,41 @@ func Push(c *gin.Context) { c.JSON(200, result) return } + + if orderResult.Status == "3" { + global.DB.Model(&model.Order{}).Where("order_sn", orderResult.OrderSn).UpdateColumns(model.Order{Status: "payed"}) + } + fmt.Println("orderResult:", orderResult) + callbackParam := suixing.CreateCallbackParam{} + 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.CreateCallbackData{ + DataType: "1", + OrderSn: pushData.OrderSn, + PolicyNo: pushData.PolicyNo, + MinPremium: pushData.MinPremium, + Rate: pushData.Rate, + Status: pushData.Status, + ServiceAmount: pushData.ServiceAmount, + GuranteeLink: pushData.GuranteeLink, + GuranteeLinkMd5: pushData.GuranteeLinkMd5, + GuranteeOfdLink: pushData.GuranteeOfdLink, + GuranteeOfdLinkMd5: pushData.GuranteeOfdLinkMd5, + InvoiceLink: pushData.InvoiceLink, + InvoiceLinkMd5: pushData.InvoiceLinkMd5, + ConfirmReceiptLink: pushData.ConfirmReceiptLink, + ConfirmReceiptLinkMd5: pushData.ConfirmReceiptLinkMd5, + Remark: pushData.Remark, + } + callbackParam.Data = callbackData + callbackRet, err := suixing.SuixingApi.CreateOrderCallback(callbackParam) + fmt.Println(callbackRet) + + c.JSON(200, result) + return } func Revoke(c *gin.Context) { diff --git a/conf/config.yaml b/conf/config.yaml index f15bd09..3a6f044 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -25,7 +25,7 @@ zking: app-id: "zijin" app-secret: "25CCFF96DC3E106F33E0D8C0B61126B0" suixing: - base-url: "https://test-open.zking.com" + base-url: "https://dzbhtest.enjoy5191.com:15064" # app-id: "2024060132098212" # app-secret: "N1xsd0sPxoWxUYb6" app-id: "zijin" diff --git a/insure b/insure index 214e7f3..c8dccf6 100755 Binary files a/insure and b/insure differ diff --git a/model/claim.go b/model/claim.go new file mode 100644 index 0000000..c6b8739 --- /dev/null +++ b/model/claim.go @@ -0,0 +1,40 @@ +package model + +import ( + "encoding/json" + "time" +) + +type Claim struct { + ID int + PolicyNo string + BankName string + AccountName string + ContactName string + ContactPhone string + FileList string + BankCardNum string + BackPremium string + Reason string + Status string + Msg string + CreatedAt time.Time + UpdatedAt time.Time `json:"-"` +} + +func (Claim) TableName() string { + return "claim" +} + +func (a Claim) MarshalJSON() ([]byte, error) { + type Alias Claim + return json.Marshal(&struct { + CreatedAt string + UpdatedAt string + *Alias + }{ + CreatedAt: a.CreatedAt.Format("2006-01-02 15:04:05"), + UpdatedAt: a.UpdatedAt.Format("2006-01-02 15:04:05"), + Alias: (*Alias)(&a), + }) +} diff --git a/model/revoke.go b/model/revoke.go new file mode 100644 index 0000000..187175e --- /dev/null +++ b/model/revoke.go @@ -0,0 +1,40 @@ +package model + +import ( + "encoding/json" + "time" +) + +type Revoke struct { + ID int + PolicyNo string + BankName string + AccountName string + ContactName string + ContactPhone string + FileList string + BankCardNum string + BackPremium string + Reason string + Status string + Msg string + CreatedAt time.Time + UpdatedAt time.Time `json:"-"` +} + +func (Revoke) TableName() string { + return "revoke" +} + +func (a Revoke) MarshalJSON() ([]byte, error) { + type Alias Revoke + return json.Marshal(&struct { + CreatedAt string + UpdatedAt string + *Alias + }{ + CreatedAt: a.CreatedAt.Format("2006-01-02 15:04:05"), + UpdatedAt: a.UpdatedAt.Format("2006-01-02 15:04:05"), + Alias: (*Alias)(&a), + }) +} diff --git a/service/order_service.go b/service/order_service.go index f57c9e6..28e6cb6 100644 --- a/service/order_service.go +++ b/service/order_service.go @@ -363,6 +363,126 @@ func (s *orderService) PostToZking(orderSn string) (*zking.Result, error) { return result, nil } +func (s *orderService) ZkingClaim(claim model.Claim) (*zking.Result, error) { + var fileList []map[string]string + err := json.Unmarshal([]byte(claim.FileList), &fileList) + if err != nil { + return nil, err + } + createData := suixing.ClaimData{ + PolicyNo: claim.PolicyNo, + BankName: claim.BankName, + AccountName: claim.AccountName, + ContactName: claim.ContactName, + ContactPhone: claim.ContactPhone, + FileList: fileList, + BankCardNum: claim.BankCardNum, + BackPremium: claim.BackPremium, + Reason: claim.Reason, + } + data, _ := json.Marshal(createData) + + param := zking.CommonParam{ + AppID: global.Config.Zking.AppID, + RequestID: utils.GenerateNo("requestId"), + Timestamp: strconv.Itoa(int(time.Now().Unix())), + Version: "1.0.0", + Data: string(data), + } + result, err := zking.InsureApi.SuixingClaim(param) + if err != nil { + return nil, err + } + if result.Code != "200" { + return nil, e.NewError(result.Msg) + } + return result, nil +} + +func (s *orderService) saveRevoke(param suixing.RevokeParam) (*model.Revoke, error) { + fileList, err := json.Marshal(param.Data.FileList) + if err != nil { + return nil, err + } + revoke := model.Revoke{} + revoke.PolicyNo = param.Data.PolicyNo + revoke.BankName = param.Data.BankName + revoke.AccountName = param.Data.AccountName + revoke.ContactName = param.Data.ContactName + revoke.ContactPhone = param.Data.ContactPhone + revoke.FileList = string(fileList) + revoke.BankCardNum = param.Data.BankCardNum + revoke.BackPremium = param.Data.BackPremium + revoke.Reason = param.Data.Reason + + err = global.DB.Save(&revoke).Error + + if err != nil { + return nil, err + } + return &revoke, nil +} + +func (s *orderService) ZkingRevoke(revoke model.Revoke) (*zking.Result, error) { + var fileList []map[string]string + err := json.Unmarshal([]byte(revoke.FileList), &fileList) + if err != nil { + return nil, err + } + createData := suixing.ClaimData{ + PolicyNo: revoke.PolicyNo, + BankName: revoke.BankName, + AccountName: revoke.AccountName, + ContactName: revoke.ContactName, + ContactPhone: revoke.ContactPhone, + FileList: fileList, + BankCardNum: revoke.BankCardNum, + BackPremium: revoke.BackPremium, + Reason: revoke.Reason, + } + data, _ := json.Marshal(createData) + + param := zking.CommonParam{ + AppID: global.Config.Zking.AppID, + RequestID: utils.GenerateNo("requestId"), + Timestamp: strconv.Itoa(int(time.Now().Unix())), + Version: "1.0.0", + Data: string(data), + } + result, err := zking.InsureApi.SuixingClaim(param) + if err != nil { + return nil, err + } + if result.Code != "200" { + return nil, e.NewError(result.Msg) + } + return result, nil +} + +func (s *orderService) SaveClaim(param suixing.ClaimParam) (*model.Claim, error) { + fileList, err := json.Marshal(param.Data.FileList) + if err != nil { + return nil, err + } + claim := model.Claim{} + claim.PolicyNo = param.Data.PolicyNo + claim.BankName = param.Data.BankName + claim.AccountName = param.Data.AccountName + claim.ContactName = param.Data.ContactName + claim.ContactPhone = param.Data.ContactPhone + claim.FileList = string(fileList) + claim.BankCardNum = param.Data.BankCardNum + claim.BackPremium = param.Data.BackPremium + claim.Reason = param.Data.Reason + + err = global.DB.Save(&claim).Error + + if err != nil { + return nil, err + } + return &claim, nil +} + func (s *orderService) GetOrderResultByToken(token string) (*model.OrderResult, error) { order := model.Order{} err := global.DB. @@ -535,6 +655,11 @@ func (s *orderService) SaveOrderResult(data zking.PushCallbackData) (*model.Orde } orderResult := model.OrderResult{} + err = global.DB.Where("order_sn", data.OrderSn).First(&orderResult).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return nil, err + } + orderResult.OrderSn = data.OrderSn orderResult.PolicyNo = data.PolicyNo orderResult.Status = data.Status diff --git a/static/sign.pdf b/static/sign.pdf new file mode 100644 index 0000000..e2861eb Binary files /dev/null and b/static/sign.pdf differ diff --git a/third_party/suixing/api.go b/third_party/suixing/api.go index 9dd9ce0..8f2bc54 100644 --- a/third_party/suixing/api.go +++ b/third_party/suixing/api.go @@ -3,6 +3,7 @@ package suixing import ( "encoding/json" "fmt" + "github.com/tidwall/gjson" "insure/e" "insure/global" "insure/utils" @@ -17,12 +18,18 @@ var SuixingApi suixingApi = suixingApi{} type suixingApi struct { } -func (api *suixingApi) CreateOrderCallback(param CommonParam) (*Result, error) { - err := api.Sign(¶m, "") +func (api *suixingApi) CreateOrderCallback(param CreateCallbackParam) (*Result, error) { + paramBytes, err := json.Marshal(param) if err != nil { return nil, err } - res, err := api.post("", param) + dataRet := gjson.Get(string(paramBytes), "data") + + err = api.Sign(¶m.CommonParam, dataRet.String()) + if err != nil { + return nil, err + } + res, err := api.post("/CallBack/pushGuarantee", param) if err != nil { return nil, err } @@ -37,7 +44,6 @@ func (api *suixingApi) CreateOrderCallback(param CommonParam) (*Result, error) { func (api *suixingApi) Sign(param *CommonParam, data string) error { //vals, err := utils.StructToURLValues(param) fmt.Println("data: " + data) - data = "{\"user\":{\"unitname\":\"湖南弘湘建设工程管理有限公司\",\"insurances_start\":\"\",\"username\":\"投标企业4\",\"server_amount\":\"200.000\",\"bank_name\":\"中国建设银行\",\"userid\":\"5987c1944b0931216ce8526f\",\"beiandiqu_code\":\"x00004\",\"unitid\":\"5993a8144b09311cacb51e12\",\"bank_card_num\":\"6217001820001592123\",\"buinessNo\":[],\"mobile\":\"15605914788\",\"bank_user_name\":\"湖南弘湘建设工程管理有限公司\",\"fileList\":[],\"guarantee_type\":\"0\",\"rate\":\"\",\"policy_period_type\":\"\",\"unit_qual\":\"\",\"insurances_end\":\"\"},\"project\":{\"amount\":\"300000.00\",\"bulid_price\":\"3424257\",\"plan_date\":\"108(日历天)\",\"district\":\"350100\",\"city\":\"350100\",\"valid_period\":\"23\",\"name\":\"住建-测试项目\",\"province\":\"350000\",\"bulid_place\":\"23412\",\"tender_notice_url\":\"http://192.168.118.171:7702/views/pages/entp-view.html?type=tp&tpId=66027a207109b83d96aa86eb&flag=false&foId=66027a207109b83d96aa86eb\",\"createtime\":\"2024-03-26 15:41:37\",\"tender_project_type\":\"A99\",\"bzj_etime\":\"2027-06-18 11:12:03\",\"bd_name\":\"标段1\",\"start_date\":\"2027-06-15 11:12:03\",\"bzj_stime\":\"2024-06-18 11:12:03\",\"tender_file_url\":\"https://filetest.enjoy5191.com:15064/File/GetQiniuContent?appId=test_ebid_szj&key=%E4%BD%8F%E5%BB%BA-%E5%8D%8E%E5%AE%89%E4%BF%9D%E9%99%A9%E4%BF%9D%E6%B6%B5%E6%B5%81%E7%A8%8B%E9%AA%8C%E8%AF%81-RNM20240326_%E6%8B%9B%E6%A0%87%E6%96%87%E4%BB%B6_20240326154137.zip\",\"tender_file_url_md5\":\"d72fa88274c9449252a172afe832124e\",\"bdid\":\"42370bf371e74bb984aef56718520a81\",\"premium\":\"300.00000\",\"project_approval_no\":\"234234\",\"tpid\":\"345\"},\"applicant\":{\"applicant_name\":\"湖南弘湘建设工程管理有限公司\",\"city\":\"福州\",\"license_files\":[\"https://filetest.enjoy5191.com:15064/file/getcontent/6115d42094ce671bd8ff8e4f.png\"],\"province\":\"福建\",\"com_tel_num\":\"18888888866\",\"address\":\"高新科技园创业大厦25楼随行软件有限公司(星网锐捷)66\",\"legal_name\":\"法定代表人姓名166\",\"credit_vld\":\"2023-09-01\",\"credit_code\":\"91350206M00019WY2P\",\"com_tel_area\":\"\",\"legal_num\":\"62040320240328205X\",\"email\":\"743203624@qq.com\",\"bzj_way\":\"BAOXIAN_BAOHAN\",\"contact_mobile\":\"15605914788\",\"district\":\"闽候\",\"contact_name\":\"李一一\"},\"assured\":{\"assured_name\":\"345\",\"agency\":\"345\",\"district\":\"\",\"city\":\"-\",\"province\":\"\",\"com_tel_num\":\"1323423423\",\"address\":\"12312\",\"credit_vld\":\"\",\"credit_code\":\"123123123\",\"com_tel_area\":\"\",\"tender_bank_account\":\"-\",\"tender_bank_openbank\":\"-\",\"contact_mobile\":\"1323423423\",\"contact_name\":\"23234\",\"tender_account_name\":\"-\"}}" vals := url.Values{} vals.Set("appid", global.Config.Suixing.AppID) vals.Set("requestid", param.RequestID) diff --git a/third_party/suixing/claim_data.go b/third_party/suixing/claim_data.go new file mode 100644 index 0000000..9bdcc76 --- /dev/null +++ b/third_party/suixing/claim_data.go @@ -0,0 +1,13 @@ +package suixing + +type ClaimData struct { + PolicyNo string `json:"policyNo" form:"policyNo"` + BankName string `json:"bankName" form:"bankName"` + AccountName string `json:"accountName" form:"accountName"` + ContactName string `json:"contactName" form:"contactName"` + ContactPhone string `json:"contactPhone" form:"contactPhone"` + FileList []map[string]string `json:"fileList" form:"fileList"` + BankCardNum string `json:"bankCardNum" form:"bankCardNum"` + BackPremium string `json:"backPremium" form:"backPremium"` + Reason string `json:"reason" form:"reason"` +} diff --git a/third_party/suixing/claim_param.go b/third_party/suixing/claim_param.go new file mode 100644 index 0000000..e3d2aa7 --- /dev/null +++ b/third_party/suixing/claim_param.go @@ -0,0 +1,6 @@ +package suixing + +type ClaimParam struct { + CommonParam + Data ClaimData `json:"data" form:"data"` +} diff --git a/third_party/suixing/callback_data.go b/third_party/suixing/create_callback_data.go similarity index 97% rename from third_party/suixing/callback_data.go rename to third_party/suixing/create_callback_data.go index 81cf072..0be6ba4 100644 --- a/third_party/suixing/callback_data.go +++ b/third_party/suixing/create_callback_data.go @@ -1,6 +1,6 @@ package suixing -type CallbackData struct { +type CreateCallbackData struct { DataType string `json:"data_type" form:"data_type"` OrderSn string `json:"ordersn" form:"ordersn"` PolicyNo string `json:"policy_no" form:"policy_no"` diff --git a/third_party/suixing/create_callback_param.go b/third_party/suixing/create_callback_param.go new file mode 100644 index 0000000..ae0da17 --- /dev/null +++ b/third_party/suixing/create_callback_param.go @@ -0,0 +1,6 @@ +package suixing + +type CreateCallbackParam struct { + CommonParam + Data CreateCallbackData `json:"data" form:"data"` +} diff --git a/third_party/suixing/revoke_data.go b/third_party/suixing/revoke_data.go new file mode 100644 index 0000000..6808797 --- /dev/null +++ b/third_party/suixing/revoke_data.go @@ -0,0 +1,13 @@ +package suixing + +type RevokeData struct { + PolicyNo string `json:"policyNo" form:"policyNo"` + BankName string `json:"bankName" form:"bankName"` + AccountName string `json:"accountName" form:"accountName"` + ContactName string `json:"contactName" form:"contactName"` + ContactPhone string `json:"contactPhone" form:"contactPhone"` + FileList []map[string]string `json:"fileList" form:"fileList"` + BankCardNum string `json:"bankCardNum" form:"bankCardNum"` + BackPremium string `json:"backPremium" form:"backPremium"` + Reason string `json:"reason" form:"reason"` +} diff --git a/third_party/suixing/revoke_param.go b/third_party/suixing/revoke_param.go new file mode 100644 index 0000000..39d5dd5 --- /dev/null +++ b/third_party/suixing/revoke_param.go @@ -0,0 +1,6 @@ +package suixing + +type RevokeParam struct { + CommonParam + Data RevokeData `json:"data" form:"data"` +} diff --git a/third_party/zking/api.go b/third_party/zking/api.go index 74d2dcc..d9ca17b 100644 --- a/third_party/zking/api.go +++ b/third_party/zking/api.go @@ -35,6 +35,40 @@ func (api *insureApi) SuixingCreate(param CommonParam) (*Result, error) { return &result, nil } +func (api *insureApi) SuixingRevoke(param CommonParam) (*Result, error) { + err := api.Sign(¶m) + if err != nil { + return nil, err + } + res, err := api.post("/api/v1/insurance/public/suiXing/surrend", 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 *insureApi) SuixingClaim(param CommonParam) (*Result, error) { + err := api.Sign(¶m) + if err != nil { + return nil, err + } + res, err := api.post("/api/v1/insurance/public/suiXing/claim", 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 *insureApi) Sign(param *CommonParam) error { //vals, err := utils.StructToURLValues(param) data, err := json.Marshal(param) diff --git a/third_party/zking/push_callback_data.go b/third_party/zking/push_callback_data.go index ee59d6a..6b2347a 100644 --- a/third_party/zking/push_callback_data.go +++ b/third_party/zking/push_callback_data.go @@ -3,7 +3,7 @@ package zking type PushCallbackData struct { DataType string `json:"data_type" form:"data_type"` OrderSn string `json:"ordersn" form:"ordersn"` - PolicyNo string `json:"policyNo" form:"policyNo"` + PolicyNo string `json:"policy_no" form:"policy_no"` MinPremium string `json:"min_premium" form:"min_premium"` Rate string `json:"rate" form:"rate"` Status string `json:"status" form:"status"` // 3 已出单,其他状态待定