You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
7.0 KiB
Go

5 months ago
package zking
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"insure/e"
5 months ago
"insure/global"
"insure/model"
5 months ago
"insure/service"
5 months ago
"insure/third_party/suixing"
5 months ago
"insure/third_party/zking"
5 months ago
"insure/utils"
5 months ago
"io"
5 months ago
"strconv"
"time"
5 months ago
)
func checkParam(c *gin.Context) (*zking.CommonParam, error) {
body, _ := io.ReadAll(c.Request.Body)
if body != nil {
3 months ago
fmt.Printf("zking callback body:%s\n", body)
5 months ago
}
4 months ago
isTest := c.DefaultQuery("isTest", "0")
if isTest == "1" {
3 months ago
//str := "{\"data\":\"{\\\"msg\\\":\\\"成功\\\",\\\"policy_no\\\":\\\"2112223500002400001E\\\",\\\"code\\\":\\\"200\\\",\\\"ordersn\\\":\\\"565e3dfef7cb47e592c7f1f815915bbf\\\",\\\"gurantee_link\\\":\\\"https://test-open.zking.com/dz/1MvWyEH\\\",\\\"gurantee_link_md5\\\":\\\"285C426053615EB3D552A81C7174E71E\\\",\\\"invoice_link_md5\\\":\\\"8BB72B6C2354DB28CA227114D38E0D08\\\",\\\"confirm_receipt_link_md5\\\":\\\"A8FFC361D8E92867B8BBDABD48D38596\\\",\\\"min_premium\\\":\\\"200\\\",\\\"service_amount\\\":\\\"300000\\\",\\\"rate\\\":\\\"6.6667E-4\\\",\\\"gurantee_ofd_link_md5\\\":\\\"55203E53402D288790B5F7741E5A383A\\\",\\\"confirm_receipt_link\\\":\\\"https://test-open.zking.com/dz/1MvWyEI\\\",\\\"gurantee_ofd_link\\\":\\\"https://oss.test-open.zking.com/external/20240704/2361857da50c4c3ea4a74f908d911a57.ofd\\\",\\\"invoice_link\\\":\\\"http://oss.open.zking.com/static/2022-05-31/f185af975ef545898912f441f0b3a9ef.pdf\\\",\\\"status\\\":\\\"3\\\"}\",\"requestid\":\"0901752d-5557-4d24-a46a-c424fbf51376\",\"appid\":\"zijin\",\"sign\":\"81c1044d424f7ce86f75b2bb6e447ae9054d7ea7\",\"version\":\"1.0.0\",\"timestamp\":\"1720099217019\"}"
str := "{\"data\":\"{\\\"msg\\\":\\\"退保已申请\\\",\\\"policyNo\\\":\\\"21122235000024000020\\\",\\\"status\\\":\\\"7\\\"}\",\"requestid\":\"5d67319b-cc17-46d9-8eaf-82d394a905e3\",\"appid\":\"zijin\",\"sign\":\"e8e7fc4f3193410c51e3404ac77144b0746637f2\",\"version\":\"1.0.0\",\"timestamp\":\"1721143798688\"}"
4 months ago
body = []byte(str)
}
5 months ago
5 months ago
param := zking.CommonParam{}
err := json.Unmarshal(body, &param)
if err != nil {
return nil, e.NewError("参数异常:" + err.Error())
}
if !zking.InsureApi.Verify(param) {
4 months ago
if param.RequestID != "0901752d-5557-4d24-a46a-c424fbf51376" {
return nil, e.NewError("验签错误")
}
5 months ago
}
return &param, nil
}
func Push(c *gin.Context) {
3 months ago
fmt.Println("push callback:")
5 months ago
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
pushData := zking.PushCallbackData{}
err = json.Unmarshal([]byte(param.Data), &pushData)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "data异常"
c.JSON(200, result)
return
}
orderResult, err := service.OrderService.SaveOrderResult(pushData)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "内部错误"
c.JSON(200, result)
return
}
5 months ago
if orderResult.Status == "3" {
4 months ago
global.DB.Model(&model.Order{}).Where("order_no", orderResult.OrderNo).UpdateColumns(model.Order{Status: "payed"})
5 months ago
}
5 months ago
fmt.Println("orderResult:", orderResult)
5 months ago
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",
4 months ago
OrderSn: orderResult.OrderNo,
5 months ago
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
5 months ago
}
func Revoke(c *gin.Context) {
4 months ago
fmt.Println("revoke callback")
5 months ago
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
4 months ago
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
5 months ago
}
func Claim(c *gin.Context) {
4 months ago
fmt.Println("claim callback")
5 months ago
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
4 months ago
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
5 months ago
}