package svc import ( "applet/app/e" "applet/app/lib/alipay" mdComm "applet/app/md" "applet/app/pay/md" svcComm "applet/app/svc" "applet/app/utils" "fmt" "github.com/gin-gonic/gin" "strings" ) // PrepareAlipayCode 生成支付参数 func PrepareAlipayCode(c *gin.Context, p *md.AliPayPayParams) (string, error) { // 获取私钥和APPID privateKey := svcComm.SysCfgGet(c, "pay_ali_private_key") appID := svcComm.SysCfgGet(c, "pay_ali_app_id") rsa := svcComm.SysCfgGet(c, "pay_ali_key_len_type") pkcs := svcComm.SysCfgGet(c, "pay_ali_key_format_type") var paySet = &md.PayData{ PayAppCertSn: svcComm.SysCfgGet(c, "pay_app_cert_sn"), PayAlipayRootCertSn: svcComm.SysCfgGet(c, "pay_alipay_root_cert_sn"), PayAlipayrsaPublicKey: svcComm.SysCfgGet(c, "pay_alipayrsa_public_key"), PayAliUseType: svcComm.SysCfgGet(c, "pay_ali_use_type"), PriKey: svcComm.SysCfgGet(c, "pay_ali_new_private_key"), } if paySet.PayAliUseType == "1" { privateKey = paySet.PriKey appID = svcComm.SysCfgGet(c, "pay_ali_new_app_id") } if privateKey == "" || appID == "" { return "", e.NewErrCode(e.ERR_ALIPAY_SETTING) } reqHost := c.Request.Host if strings.Contains(reqHost, "zhios-mall:5002") { // if is inner addr, change to outside reqHost = "api.zhiyingos.com" } notifyURL := fmt.Sprintf(md.CALLBACK_URL, reqHost, c.GetString("mid"), p.OrderType, md.ALIPAY) // switch判断类型支付 pzy platform := c.GetHeader("Platform") page_url := c.Query("page_url") var param interface{} var err error switch platform { case mdComm.PLATFORM_ALIPAY_APPLET: param, err = alipay.TradeCreate(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, paySet) case mdComm.PLATFORM_WAP: param, err = alipay.TradeWapPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, page_url, paySet) case mdComm.PLATFORM_ANDROID, mdComm.PLATFORM_IOS: param, err = alipay.TradeAppPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, paySet) default: return "", e.NewErrCode(e.ERR_PLATFORM) } //param, err = alipay.TradeAppPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL) if err != nil { return "", e.NewErrCode(e.ERR_ALIPAY_ORDER_ERR) } return utils.AnyToString(param), nil }