|
- 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) (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
- }
-
- 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
- }
|