@@ -9,21 +9,22 @@ import ( | |||
//配置文件数据,全局变量 | |||
var ( | |||
Debug bool | |||
Prd bool | |||
CurlDebug bool | |||
RedisAddr string | |||
DB *DBCfg | |||
DataDB *DBCfg | |||
ImDB *DBCfg | |||
MQ *MQCfg | |||
ES *ESCfg | |||
Log *LogCfg | |||
Admin *AdminCfg | |||
ImBusinessRpc *ImBusinessRpcCfg | |||
ImLogicRpc *ImLogicRpcCfg | |||
Local bool | |||
AppComm *AppCommCfg | |||
Debug bool | |||
Prd bool | |||
CurlDebug bool | |||
RedisAddr string | |||
DB *DBCfg | |||
DataDB *DBCfg | |||
ImDB *DBCfg | |||
MQ *MQCfg | |||
ES *ESCfg | |||
Log *LogCfg | |||
Admin *AdminCfg | |||
ImBusinessRpc *ImBusinessRpcCfg | |||
ImLogicRpc *ImLogicRpcCfg | |||
Local bool | |||
AppComm *AppCommCfg | |||
WxappletFilepath *WxappletFilepathCfg | |||
) | |||
//初始化配置文件,将cfg.yml读入到内存 | |||
@@ -61,4 +62,5 @@ func InitCfg() { | |||
ES = &conf.ES | |||
ImBusinessRpc = &conf.ImBusinessRpc | |||
ImLogicRpc = &conf.ImLogicRpc | |||
WxappletFilepath = &conf.WxappletFilepath | |||
} |
@@ -0,0 +1,10 @@ | |||
package md | |||
type AliPayPayParams struct { | |||
Subject string `json:"subject" binding:"required"` | |||
Amount string `json:"amount" binding:"required"` | |||
OrderType string `json:"order_type" binding:"required"` | |||
OrdId string `json:"ord_id"` | |||
Uid string `json:"uid"` | |||
Phone string `json:"phone"` | |||
} |
@@ -0,0 +1,55 @@ | |||
package svc | |||
import ( | |||
"applet/app/cfg" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/md" | |||
"fmt" | |||
"github.com/iGoogle-ink/gopay/alipay" | |||
"xorm.io/xorm" | |||
) | |||
func CommAlipayConfig(eg *xorm.Engine, dbName string, p *md.AliPayPayParams) (map[string]string, error) { | |||
//获取支付配置 | |||
req := map[string]string{ | |||
"pay_ali_use_type": db.SysCfgGetWithDb(eg, dbName, "pay_ali_use_type"), | |||
"private_key": db.SysCfgGetWithDb(eg, dbName, "pay_ali_private_key"), | |||
"app_id": db.SysCfgGetWithDb(eg, dbName, "pay_ali_app_id"), | |||
"rsa": db.SysCfgGetWithDb(eg, dbName, "pay_ali_key_len_type"), | |||
"pkcs": db.SysCfgGetWithDb(eg, dbName, "pay_ali_key_format_type"), | |||
} | |||
if req["pay_ali_use_type"] == "1" { | |||
req["private_key"] = db.SysCfgGetWithDb(eg, dbName, "pay_ali_new_private_key") | |||
req["app_id"] = db.SysCfgGetWithDb(eg, dbName, "pay_ali_new_app_id") | |||
appCertSN, err := alipay.GetCertSN(cfg.WxappletFilepath.URL + "/" + db.SysCfgGetWithDb(eg, dbName, "pay_app_cert_sn")) | |||
if err != nil { | |||
fmt.Println(err) | |||
return nil, err | |||
} | |||
if appCertSN == "" { | |||
fmt.Println(err) | |||
return nil, err | |||
} | |||
req["pay_app_cert_sn"] = appCertSN | |||
aliPayPublicCertSN, err := alipay.GetCertSN(cfg.WxappletFilepath.URL + "/" + db.SysCfgGetWithDb(eg, dbName, "pay_alipayrsa_public_key")) | |||
if err != nil { | |||
fmt.Println(err) | |||
return nil, err | |||
} | |||
if aliPayPublicCertSN == "" { | |||
fmt.Println(err) | |||
return nil, err | |||
} | |||
req["pay_alipayrsa_public_key"] = aliPayPublicCertSN | |||
} | |||
if req["private_key"] == "" || req["app_id"] == "" { | |||
return req, e.NewErr(400, "请在后台正确配置支付宝") | |||
} | |||
req["ord_id"] = p.OrdId | |||
req["amount"] = p.Amount | |||
req["subject"] = p.Subject | |||
req["order_type"] = p.OrderType | |||
return req, nil | |||
} |
@@ -6,6 +6,7 @@ import ( | |||
"applet/app/db/offical" | |||
model2 "applet/app/db/offical/model" | |||
"applet/app/e" | |||
md2 "applet/app/md" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
@@ -73,6 +74,7 @@ func handleZhiosRechargeOrderFail(msg []byte) error { | |||
return err | |||
} | |||
mid := canalMsg.Mid | |||
mid = "123456" | |||
eg := db.DBs[mid] | |||
uid := utils.StrToInt(canalMsg.Uid) | |||
oid := canalMsg.Oid | |||
@@ -121,8 +123,6 @@ func handleZhiosRechargeOrderFail(msg []byte) error { | |||
"uid": utils.IntToStr(orderData.Uid), | |||
"notify_url": canalMsg.DomainUrl + "/api/v1/refund/callback/" + mid, | |||
} | |||
//params["p12_str"] = "D:\\Downloads\\WXCertUtil\\cert\\1534243971_20230825_cert\\" + wechatP12ApiclientCert | |||
//params["notify_url"] = strings.ReplaceAll(params["notify_url"], "http:", "https:") | |||
params["pay_wx_appid"] = orderData.AppId | |||
r, r1, err := pay.WxAppRefund(params) | |||
utils.FilePutContents("mall_refund", utils.SerializeStr(params)) | |||
@@ -137,6 +137,33 @@ func handleZhiosRechargeOrderFail(msg []byte) error { | |||
} | |||
} | |||
} | |||
if orderData.PayMethod == 2 { | |||
alipayPayRefundType := db.SysCfgGetWithDb(eg, mid, "alipay_pay_refund_type") | |||
NSFNTheSameBack = false | |||
if orderData.TradeNo == "" || alipayPayRefundType != "1" { | |||
NSFNTheSameBack = true | |||
} else { | |||
var params = &md2.AliPayPayParams{} | |||
config, _ := svc.CommAlipayConfig(eg, mid, params) | |||
config["trade_no"] = orderData.TradeNo | |||
config["refund_amount"] = orderData.Amount | |||
config["refund_reason"] = "退款" | |||
config["out_request_no"] = utils.OrderUUID(orderData.Uid) | |||
refund, err := pay.AlipayTradeRefund(config) | |||
utils.FilePutContents("mall_refund", utils.SerializeStr(config)) | |||
utils.FilePutContents("mall_refund", utils.SerializeStr(refund)) | |||
if err != nil { | |||
return err | |||
} | |||
if refund.AlipayTradeRefundResponse.Code != "10000" { | |||
return errors.New(refund.AlipayTradeRefundResponse.SubMsg) | |||
} | |||
if refund.AlipayTradeRefundResponse.FundChange != "Y" { | |||
return errors.New("退款失败") | |||
} | |||
} | |||
} | |||
// 更改为已支付 | |||
orderData.Status = "已退款" | |||
orderData.RefundTime = time.Now() | |||
@@ -7,7 +7,7 @@ require ( | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20230925093625-5df62f2a76c5 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20230825083620-ef8b12df8cf8 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230911014653-22cc8e626d17 | |||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 | |||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 | |||