package pay import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_alipay" local_wxpay "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_wechat" "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" "fmt" "github.com/iGoogle-ink/gopay" "github.com/iGoogle-ink/gopay/wechat" "github.com/pkg/errors" ) /** 自有支付 支付宝 req 传参 ord_id //订单号 amount //总金额 subject //描述 order_type //订单类型 notify_url //自有支付回调地址 platform //平台 由前端header传来的 pay_app_cert_sn //应用公钥证书 值 pay_alipayrsa_public_key //支付宝公钥证书 值 pay_ali_use_type //支付宝选择版本 0旧版 1新版 private_key //支付宝商户私钥 数据库字段 旧版 pay_ali_private_key 新版 pay_ali_new_private_key app_id //支付宝appId 数据库字段 旧版 pay_ali_app_id 新版 pay_ali_new_app_id rsa //支付宝密钥长度 旧版使用 数据库字段 pay_ali_key_len_type pkcs //支付宝密钥格式 旧版使用 数据库字段 pay_ali_key_format_type page_url //支付宝wap支付成功跳转链接 */ func AlipayCofing(args map[string]string) *md.PayData { var paySet = &md.PayData{ PayAppCertSn: args["pay_app_cert_sn"], PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"], PayAliUseType: args["pay_ali_use_type"], } return paySet } func AlipayApp(args map[string]string) (string, error) { paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } 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) if err != nil { fmt.Println("支付宝错误日志") fmt.Println(param) fmt.Println(err) return "", errors.New("支付宝订单创建失败") } return zhios_pay_utils.AnyToString(param), nil } func AlipayPc(args map[string]string) (string, error) { paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } param, err := local_alipay.TradeAppPc(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], args["page_url"], paySet) if err != nil { fmt.Println("支付宝错误日志") fmt.Println(param) fmt.Println(err) return "", errors.New("支付宝订单创建失败") } return zhios_pay_utils.AnyToString(param), nil } func AlipayWap(args map[string]string) (string, error) { paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } 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) if err != nil { fmt.Println("支付宝错误日志") fmt.Println(param) fmt.Println(err) return "", errors.New("支付宝订单创建失败") } return zhios_pay_utils.AnyToString(param), nil } func AlipayApplet(args map[string]string) (string, error) { paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } 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) if err != nil { fmt.Println("支付宝错误日志") fmt.Println(param) fmt.Println(err) return "", errors.New("支付宝订单创建失败") } return zhios_pay_utils.AnyToString(param), nil } // 微信app支付v2 func WxAppPay(params map[string]string) (map[string]string, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, err := local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) return r, err } // 微信H5支付v2 func WxH5Pay(params map[string]string) (map[string]string, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) return r, err } func WxPcPay(params map[string]string) (map[string]string, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, err := local_wxpay.TradePcPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["product_id"]) return r, err } // 微信小程序v2 func WxMiniProgPay(params map[string]string) (map[string]string, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) if params["third_party_wechat_openid"] == "" { return nil, errors.New("请先授权微信") } r, err := local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) return r, err } // 微信JSAPI支付 func WxAppJSAPIPay(params map[string]string) (map[string]string, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) if params["third_party_wechat_openid"] == "" { return nil, errors.New("请先授权微信") } r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) return r, err } func WxAppRefund(params map[string]string) (*wechat.RefundResponse, gopay.BodyMap, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, r1, err := local_wxpay.TradeAppRefund(client, params["subject"], params["transaction_id"], params["out_refund_no"], params["total_fee"], params["amount"], params["p12_str"], params["notify_url"]) return r, r1, err } func WxAppRefundQuery(params map[string]string) (*wechat.QueryRefundResponse, gopay.BodyMap, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, r1, err := local_wxpay.TradeAppRefundQuery(client, params["transaction_id"]) return r, r1, err } func WxShowQuery(params map[string]string) (*wechat.QueryOrderResponse, gopay.BodyMap, error) { client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) r, r1, err := local_wxpay.TradeShowQuery(client, params["transaction_id"]) return r, r1, err }