package pay import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md" zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/pkg/errors" ) //酷点 - 支付宝APP支付 func AliAppPayByKuDian(payParams *md.KuDianAliAppPayParams, isPrd bool) (string, error) { var url string if isPrd == true { url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/aliAppPay" } else { url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/aliAppPay" } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{ "data": payParams, })) bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil) if err != nil { return "", err } var result struct { Code int `json:"code"` Msg string `json:"msg"` Data map[string]string `json:"data"` } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result)) err = json.Unmarshal(bytes, &result) if err != nil { return "", err } if result.Code != 0 { return "", errors.New(result.Msg) } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"])) return result.Data["url"], nil } // 酷点 - 支付宝JsAPi支付 func AliJsApiPayByKuDian(payParams *md.KuDianAliAppPayParams, isPrd bool) (string, error) { var url string if isPrd == true { url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/aliJsApiPay" } else { url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/aliJsApiPay" } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{ "data": payParams, })) bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil) if err != nil { return "", err } var result struct { Code int `json:"code"` Msg string `json:"msg"` Data map[string]string `json:"data"` } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result)) err = json.Unmarshal(bytes, &result) if err != nil { return "", err } if result.Code != 0 { return "", errors.New(result.Msg) } zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"])) return result.Data["trade_no"], nil } // 酷点 - 微信小程序支付 func WxAppletPayByKuDian(payParams *md.KuDianWxPayParams, isPrd bool) (interface{}, error) { var url string if isPrd == true { url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/wxJsAPi" } else { url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/wxJsAPi" } zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{ "data": payParams, })) bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil) if err != nil { return nil, err } var result struct { Code int `json:"code"` Msg string `json:"msg"` Data map[string]interface{} `json:"data"` } zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(result)) err = json.Unmarshal(bytes, &result) if err != nil { return nil, err } if result.Code != 0 { return nil, errors.New(result.Msg) } zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"])) return result.Data["data"], nil } // 酷点 - 检查返回参数 func CheckAllCallbackParamsByKuDian(c *gin.Context) (interface{}, error) { var dataWx md.KuDianPayCallback if err := c.ShouldBindJSON(&dataWx); err != nil { fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err) return nil, err } var dataPay md.KuDianPayCallbackResp if err := json.Unmarshal([]byte(dataWx.Result), &dataPay); err != nil { fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err) return nil, err } zhios_pay_utils.FilePutContents("CheckAllCallbackParamsByKuDian", zhios_pay_utils.SerializeStr(dataPay)) return dataPay, nil }