|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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
- }
|