|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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"
- "github.com/pkg/errors"
- "github.com/syyongx/php2go"
- "strings"
- )
-
- //自有支付 支付宝
- func Alipay(req map[string]string) (interface{}, error) {
- var paySet = &md.PayData{
- PayAppCertSn: req["pay_app_cert_sn"],
- PayAlipayRootCertSn: req["pay_alipay_root_cert_sn"],
- PayAlipayrsaPublicKey: req["pay_alipayrsa_public_key"],
- PayAliUseType: req["pay_ali_use_type"],
- WxAppletFilepathUrl: req["wx_applet_filepath_url"],
- }
- if req["private_key"] == "" || req["app_id"] == "" {
- return "", errors.New("请在后台正确配置支付宝")
- }
- prd := false
- if req["cfg_prd"] == "1" {
- prd = true
- }
- var param interface{}
- var err error
- switch req["platform"] {
- case md.PLATFORM_ALIPAY_APPLET:
- param, err = local_alipay.TradeCreate(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet)
- case md.PLATFORM_WAP:
- if req["pay_type"] == "self" {
- param, err = local_alipay.TradeCreate(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet)
- } else if req["pay_type"] == "thirdParty" {
- var actualPayMethod string
- payConfigs := map[string]string{
- "ord_id": req["ord_id"],
- "notify_url": req["kudian_notify_url"],
- "subject": req["subject"],
- "amount": req["amount"],
- "pay_third_party_id": req["pay_third_party_id"],
- "user_id": req["user_id"],
- }
- if strings.Contains(req["browser"], "ali_pay_browser") && req["user_id"] != "" { //判断是否在支付宝内浏览器打开
- actualPayMethod = "JSPAI"
- payConfigs["trade_type"] = actualPayMethod
- } else {
- actualPayMethod = "H5"
- payConfigs["trade_type"] = actualPayMethod
- payConfigs["wap_mame"] = "支付"
- payConfigs["return_url"] = ""
- payConfigs["wap_url"] = req["wap_url"]
- }
- payParams := &md.KuDianAliAppPayParams{}
- payParams, err = KuDianAlipayConfig(req, payConfigs)
- if err != nil {
- return nil, err
- }
- var r string
-
- r, err = AliJsApiPayByKuDian(payParams, prd)
- if err != nil {
- return nil, err
- }
- if actualPayMethod == "H5" {
- r = php2go.URLEncode(r)
- }
- usePayMethod := "third_party"
- return map[string]string{
- "params": r,
-
- "actual_pay_method": actualPayMethod,
- "use_pay_method": usePayMethod,
- "orderId": req["ord_id"],
- }, nil
- }
- case md.PLATFORM_ANDROID, md.PLATFORM_IOS:
- if req["pay_type"] == "self" {
- param, err = local_alipay.TradeAppPay(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet)
- } else if req["pay_type"] == "thirdParty" {
- payConfigs := map[string]string{
- "ord_id": req["ord_id"],
- "notify_url": req["kudian_notify_url"],
- "subject": req["subject"],
- "amount": req["amount"],
- "pay_third_party_id": req["pay_third_party_id"],
- }
- payParams := &md.KuDianAliAppPayParams{}
- payParams, err = KuDianAlipayConfig(req, payConfigs)
- if err != nil {
- return nil, err
- }
- var r string
- r, err = AliAppPayByKuDian(payParams, prd)
- if err != nil {
- return nil, err
- }
- r = php2go.URLEncode(r)
- usePayMethod := "third_party"
- return map[string]string{
- "params": r,
- "use_pay_method": usePayMethod,
- "orderId": req["ord_id"],
- }, nil
- }
- default:
- return "", errors.New("渠道不存在")
- }
- if err != nil {
- return "", err
- }
- return param, nil
- }
-
- //自有支付 微信支付
- func WxPay(params map[string]string) (interface{}, error) {
- var r interface{}
- var err error
- prd := false
- if params["cfg_prd"] == "1" {
- prd = true
- }
- client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
- switch params["platform"] {
- case md.PLATFORM_WX_APPLET:
- if params["pay_type"] == "self" { //自有支付
- r, err = local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
- } else if params["pay_type"] == "thirdParty" {
- payConfigs := map[string]string{
- "ord_id": params["ord_id"],
- "notify_url": params["ku_dian_notify_url"],
- "subject": params["subject"],
- "amount": params["amount"],
- "pay_third_party_id": params["pay_third_party_id"],
- }
- payParams := &md.KuDianWxPayParams{}
- payParams, err = KuDianWxConfig(params, payConfigs)
- if err != nil {
- return nil, err
- }
- r, err = WxAppletPayByKuDian(payParams, prd)
- r = map[string]interface{}{
- "params": r,
- "orderId": params["ord_id"],
- }
- }
- case md.PLATFORM_WAP:
- if strings.Contains(params["browser"], "wx_pay_browser") {
- r, err = local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
-
- } else {
- r, err = local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
- }
- case md.PLATFORM_ANDROID, md.PLATFORM_IOS, md.PLATFORM_JSAPI:
- r, err = local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
- default:
- return nil, errors.New("渠道不存在")
- }
- if err != nil {
- return nil, err
- }
- return r, nil
-
- }
|