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" "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils/cache" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/pkg/errors" "time" ) //酷点 - 支付宝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) (md.KuDianPayCallbackResp, error) { var dataWx md.KuDianPayCallback var dataPay md.KuDianPayCallbackResp if err := c.ShouldBindJSON(&dataWx); err != nil { fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err) return dataPay, err } if err := json.Unmarshal([]byte(dataWx.Result), &dataPay); err != nil { fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err) return dataPay, err } zhios_pay_utils.FilePutContents("CheckAllCallbackParamsByKuDian", zhios_pay_utils.SerializeStr(dataPay)) return dataPay, nil } /** * MakePayParamsByKuDian(构造酷点支付参数[APP跳转小程序支付]) * @param url string 请求URL * @param uniqueIdentifierOne string 标识占位符-第一个 (示例: 如 masterId) * @param uniqueIdentifierTwo string 标识占位符-第二个 (示例: 如 uid) * @param appletOriginalId string 小程序原始id * @param queryParams string url上参数(示例: "&ord_id=123131313434343&state_zh=待支付&total=6.66") * @param params map 请求参数 */ func MakePayParamsByKuDian(url, uniqueIdentifierOne, uniqueIdentifierTwo, appletOriginalId, queryParams string, params map[string]interface{}) (map[string]string, error) { if params == nil { return nil, errors.New("参数解析错误") } data := md.MakePayParamsByKuDian{ RequestUrl: url, Params: params, } redisKey := fmt.Sprintf(md.WX_APP_TO_APPLET_PAY_UNIQUE_IDENTIFIER, uniqueIdentifierOne, uniqueIdentifierTwo, zhios_pay_utils.AnyToString(time.Now().UnixNano())) cache.SetJson(redisKey, data, md.WX_APP_TO_APPLET_PAY_UNIQUE_IDENTIFIER_CACHE_TIME) var r = map[string]string{} r["use_pay_method"] = "third_party" r["applet_original_id"] = appletOriginalId r["wx_url"] = md.WX_APPLET_PAY_URL + redisKey + "&" + queryParams return r, nil } func KuDianAlipayConfig(req, payConfig map[string]string) (*md.KuDianAliAppPayParams, error) { var payParams = &md.KuDianAliAppPayParams{ OutTradeNo: payConfig["ord_id"], NotifyUrl: payConfig["notify_url"], Description: payConfig["subject"], TotalAmount: payConfig["amount"], Attach: req["mid"], MustParams: struct { ShopId string `json:"shop_id"` KuDianMchId string `json:"ku_dian_mch_id"` KuDianSecretKey string `json:"ku_dian_secret_key"` }{ ShopId: payConfig["pay_third_party_id"], KuDianMchId: req["ku_dian_mch_id"], KuDianSecretKey: req["ku_dian_secret_key"], }, } if payConfig["trade_type"] != "" { payParams.TradeType = payConfig["trade_type"] } if payConfig["wap_mame"] != "" { payParams.SenceInfo.WapName = payConfig["wap_mame"] } if payConfig["return_url"] != "" { payParams.SenceInfo.ReturnUrl = payConfig["return_url"] } if payConfig["wap_url"] != "" { payParams.SenceInfo.WapUrl = payConfig["wap_url"] } if payConfig["trade_type"] != "" { payParams.TradeType = payConfig["trade_type"] } return payParams, nil } func KuDianWxConfig(req, payConfig map[string]string) (*md.KuDianWxPayParams, error) { var payParams = &md.KuDianWxPayParams{ OutTradeNo: payConfig["ord_id"], NotifyUrl: payConfig["notify_url"], Description: payConfig["subject"], TotalAmount: payConfig["amount"], AppId: req["wx_app_id"], OpenId: req["wx_open_id"], Attach: req["mid"], MustParams: struct { ShopId string `json:"shop_id"` KuDianMchId string `json:"ku_dian_mch_id"` KuDianSecretKey string `json:"ku_dian_secret_key"` }{ ShopId: payConfig["pay_third_party_id"], KuDianMchId: req["ku_dian_mch_id"], KuDianSecretKey: req["ku_dian_secret_key"], }, } return payParams, nil }