面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 regels
2.2 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/alipay"
  5. mdComm "applet/app/md"
  6. "applet/app/pay/md"
  7. svcComm "applet/app/svc"
  8. "applet/app/utils"
  9. "fmt"
  10. "github.com/gin-gonic/gin"
  11. "strings"
  12. )
  13. // PrepareAlipayCode 生成支付参数
  14. func PrepareAlipayCode(c *gin.Context, p *md.AliPayPayParams) (string, error) {
  15. // 获取私钥和APPID
  16. privateKey := svcComm.SysCfgGet(c, "pay_ali_private_key")
  17. appID := svcComm.SysCfgGet(c, "pay_ali_app_id")
  18. rsa := svcComm.SysCfgGet(c, "pay_ali_key_len_type")
  19. pkcs := svcComm.SysCfgGet(c, "pay_ali_key_format_type")
  20. var paySet = &md.PayData{
  21. PayAppCertSn: svcComm.SysCfgGet(c, "pay_app_cert_sn"),
  22. PayAlipayRootCertSn: svcComm.SysCfgGet(c, "pay_alipay_root_cert_sn"),
  23. PayAlipayrsaPublicKey: svcComm.SysCfgGet(c, "pay_alipayrsa_public_key"),
  24. PayAliUseType: svcComm.SysCfgGet(c, "pay_ali_use_type"),
  25. PriKey: svcComm.SysCfgGet(c, "pay_ali_new_private_key"),
  26. }
  27. if paySet.PayAliUseType == "1" {
  28. privateKey = paySet.PriKey
  29. appID = svcComm.SysCfgGet(c, "pay_ali_new_app_id")
  30. }
  31. if privateKey == "" || appID == "" {
  32. return "", e.NewErrCode(e.ERR_ALIPAY_SETTING)
  33. }
  34. reqHost := c.Request.Host
  35. if strings.Contains(reqHost, "zhios-mall:5002") { // if is inner addr, change to outside
  36. reqHost = "api.zhiyingos.com"
  37. }
  38. notifyURL := fmt.Sprintf(md.CALLBACK_URL, reqHost, c.GetString("mid"), p.OrderType, md.ALIPAY)
  39. // switch判断类型支付 pzy
  40. platform := c.GetHeader("Platform")
  41. page_url := c.Query("page_url")
  42. var param interface{}
  43. var err error
  44. switch platform {
  45. case mdComm.PLATFORM_ALIPAY_APPLET:
  46. param, err = alipay.TradeCreate(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, paySet)
  47. case mdComm.PLATFORM_WAP:
  48. param, err = alipay.TradeWapPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, page_url, paySet)
  49. case mdComm.PLATFORM_ANDROID, mdComm.PLATFORM_IOS:
  50. param, err = alipay.TradeAppPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL, rsa, pkcs, paySet)
  51. default:
  52. return "", e.NewErrCode(e.ERR_PLATFORM)
  53. }
  54. //param, err = alipay.TradeAppPay(appID, privateKey, p.Subject, p.OrdId, p.Amount, notifyURL)
  55. if err != nil {
  56. return "", e.NewErrCode(e.ERR_ALIPAY_ORDER_ERR)
  57. }
  58. return utils.AnyToString(param), nil
  59. }