支付模块
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.

46 lines
1.8 KiB

  1. package pay
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_alipay"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_tools.git/e"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_tools.git/utils"
  7. "fmt"
  8. "xorm.io/xorm"
  9. )
  10. //自有支付 支付宝
  11. func Alipay(eg *xorm.Engine, args map[string]string) (string, error) {
  12. args = OwnCustomAlipayConfig(eg, args)
  13. var paySet = &md.PayData{
  14. PayAppCertSn: args["pay_app_cert_sn"],
  15. PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
  16. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  17. PayAliUseType: args["pay_ali_use_type"],
  18. WxAppletFilepathUrl: args["wx_applet_filepath_url"],
  19. }
  20. if args["private_key"] == "" || args["app_id"] == "" {
  21. return "", e.NewErr(400, "请在后台正确配置支付宝")
  22. }
  23. var param interface{}
  24. var err error
  25. switch args["platform"] {
  26. case md.PLATFORM_ALIPAY_APPLET:
  27. param, err = local_alipay.TradeCreate(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], paySet)
  28. case md.PLATFORM_WAP:
  29. param, err = local_alipay.TradeWapPay(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], args["page_url"], paySet)
  30. case md.PLATFORM_ANDROID, md.PLATFORM_IOS:
  31. param, err = local_alipay.TradeAppPay(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], paySet)
  32. default:
  33. return "", e.NewErr(400, "支付平台不存在")
  34. }
  35. if err != nil {
  36. fmt.Println("支付宝错误日志")
  37. fmt.Println(param)
  38. fmt.Println(err)
  39. return "", e.NewErr(400, "支付宝订单创建失败")
  40. }
  41. return utils.AnyToString(param), nil
  42. }