Merge branch 'dev/dev1.0' into feature/rzy/api_1.0
# Conflicts: # app/constants/common/common.go # app/constants/errorcode/error_code.go # app/http/entities/backend/order.go
This commit is contained in:
commit
fa6b385209
|
@ -4,6 +4,7 @@ import (
|
||||||
"PaymentCenter/app/constants/common"
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/data"
|
"PaymentCenter/app/data"
|
||||||
"PaymentCenter/app/http/entities"
|
"PaymentCenter/app/http/entities"
|
||||||
|
"PaymentCenter/app/http/entities/backend"
|
||||||
"PaymentCenter/app/models/ordersmodel"
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/third/paymentService"
|
||||||
|
@ -28,20 +29,59 @@ func RegisterCommand(c *command.Command) {
|
||||||
func closeOrder() {
|
func closeOrder() {
|
||||||
var now = time.Now().Format(time.DateTime)
|
var now = time.Now().Format(time.DateTime)
|
||||||
utils.Log(nil, "关闭订单", now)
|
utils.Log(nil, "关闭订单", now)
|
||||||
|
var ctx = context.Background()
|
||||||
|
orderIds := make([]int64, 0)
|
||||||
// 查询未支付的订单
|
// 查询未支付的订单
|
||||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||||
// 拼接条件
|
// 拼接条件
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Lt{"create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.CloseOrderTime))})
|
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Lt{"orders.create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.CloseOrderTime))})
|
||||||
|
// 查询订单
|
||||||
order := make([]ordersmodel.Orders, 0)
|
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
|
||||||
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
||||||
} else if total > 0 {
|
} else if len(order) > 0 {
|
||||||
orderIds := make([]int64, 0)
|
for i := range order {
|
||||||
for _, v := range order {
|
orderInfo := order[i]
|
||||||
orderIds = append(orderIds, v.Id)
|
// 往上游发送关闭订单请求
|
||||||
|
req := paymentService.OrderCloseRequest{OrderId: orderInfo.Id}
|
||||||
|
|
||||||
|
switch utils.PayType(orderInfo.ChannelType) {
|
||||||
|
case common.PAY_CHANNLE_TYPE_WECHAT:
|
||||||
|
wx := backend.WechatPayChannel{}
|
||||||
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
||||||
|
req.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
||||||
|
req.Wx = paymentService.WxPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
MchId: wx.MchId,
|
||||||
|
SerialNo: wx.SerialNo,
|
||||||
|
ApiV3Key: wx.ApiV3Key,
|
||||||
|
PrivateKey: wx.PrivateKey,
|
||||||
|
}
|
||||||
|
case common.PAY_CHANNLE_TYPE_ZFB:
|
||||||
|
ali := backend.AliPayChannel{}
|
||||||
|
req.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
||||||
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
||||||
|
req.Ali = paymentService.AliPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
PrivateKey: ali.PrivateKey,
|
||||||
|
AppPublicCert: []byte(ali.AppPublicCert),
|
||||||
|
AlipayRootCert: []byte(ali.AlipayRootCert),
|
||||||
|
AlipayPublicCert: []byte(ali.AlipayPublicCert),
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
utils.Log(nil, "关闭订单,支付渠道不支持", orderInfo.ChannelType)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 发起关闭订单请求
|
||||||
|
response := paymentService.OrderClose(ctx, req)
|
||||||
|
// 成功
|
||||||
|
if response.Code == payCommon.PAY_SUCCESS_CODE {
|
||||||
|
orderIds = append(orderIds, orderInfo.Id)
|
||||||
|
} else {
|
||||||
|
utils.Log(nil, "关闭订单,上游支付失败", response)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 修改订单状态为关闭
|
// 修改订单状态为关闭
|
||||||
cond = builder.NewCond()
|
cond = builder.NewCond()
|
||||||
|
@ -52,7 +92,7 @@ func closeOrder() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.Log(nil, "关闭订单,修改订单状态成功", "count="+strconv.Itoa(len(order)))
|
utils.Log(nil, "关闭订单,修改订单状态成功", "总数量="+strconv.Itoa(len(order)), "成功数量="+strconv.Itoa(len(orderIds)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 主动查询订单支付状态
|
// 主动查询订单支付状态
|
||||||
|
@ -64,7 +104,6 @@ func queryOrder() {
|
||||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||||
// 拼接条件
|
// 拼接条件
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
config.GetConf()
|
|
||||||
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"orders.create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.QueryOrderTime))})
|
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"orders.create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.QueryOrderTime))})
|
||||||
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
|
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
|
||||||
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
|
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
|
||||||
|
@ -90,13 +129,32 @@ func queryOrder() {
|
||||||
query := paymentService.PayOrderQueryRequest{
|
query := paymentService.PayOrderQueryRequest{
|
||||||
OrderId: orderInfo.Id,
|
OrderId: orderInfo.Id,
|
||||||
}
|
}
|
||||||
switch orderInfo.ChannelType {
|
switch utils.PayType(orderInfo.ChannelType) {
|
||||||
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
|
case common.PAY_CHANNLE_TYPE_WECHAT:
|
||||||
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.Wx)
|
wx := backend.WechatPayChannel{}
|
||||||
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
||||||
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
query.Wx = paymentService.WxPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
MchId: wx.MchId,
|
||||||
|
SerialNo: wx.SerialNo,
|
||||||
|
ApiV3Key: wx.ApiV3Key,
|
||||||
|
PrivateKey: wx.PrivateKey,
|
||||||
|
}
|
||||||
|
case common.PAY_CHANNLE_TYPE_ZFB:
|
||||||
|
ali := backend.AliPayChannel{}
|
||||||
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
||||||
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.Ali)
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
||||||
|
query.Ali = paymentService.AliPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
PrivateKey: ali.PrivateKey,
|
||||||
|
AppPublicCert: []byte(ali.AppPublicCert),
|
||||||
|
AlipayRootCert: []byte(ali.AlipayRootCert),
|
||||||
|
AlipayPublicCert: []byte(ali.AlipayPublicCert),
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
utils.Log(nil, "查询订单,支付渠道不支持", orderInfo.ChannelType)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起查询
|
// 发起查询
|
||||||
|
@ -152,11 +210,12 @@ func queryOrder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入日志
|
// 写入日志
|
||||||
|
body, _ := json.Marshal(result)
|
||||||
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||||
OrderId: orderInfo.Id,
|
OrderId: orderInfo.Id,
|
||||||
PayCallback: "",
|
PayCallback: string(body),
|
||||||
Status: 0,
|
Status: 0,
|
||||||
MerchantParam: "",
|
PayParam: "",
|
||||||
MerchantCallback: "",
|
MerchantCallback: "",
|
||||||
}
|
}
|
||||||
_, err = orderLogRepo.OrderThirdPayLogInsertOne(&log)
|
_, err = orderLogRepo.OrderThirdPayLogInsertOne(&log)
|
||||||
|
|
|
@ -4,7 +4,7 @@ const (
|
||||||
TOKEN_PRE = "player_token_"
|
TOKEN_PRE = "player_token_"
|
||||||
TOKEN_Admin = "Admin_token_"
|
TOKEN_Admin = "Admin_token_"
|
||||||
ADMIN_V1 = "/pay/admin/api/v1"
|
ADMIN_V1 = "/pay/admin/api/v1"
|
||||||
FRONT_V1 = "/api/v1"
|
FRONT_V1 = "/pay/front/api/v1"
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
PAY_CHANNEL_UNKNOWN = 0
|
||||||
|
@ -34,6 +34,16 @@ const (
|
||||||
|
|
||||||
ORDER_TYPE_PAY int32 = 1
|
ORDER_TYPE_PAY int32 = 1
|
||||||
ORDER_TYPE_REFUND int32 = 2
|
ORDER_TYPE_REFUND int32 = 2
|
||||||
|
|
||||||
|
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
|
||||||
|
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝
|
||||||
|
|
||||||
|
THIRD_ORDER_TYPE_PAY = 1 // 发起支付
|
||||||
|
THIRD_ORDER_TYPE_ORDER_QUERY = 2 // 查询订单
|
||||||
|
THIRD_ORDER_TYPE_REFUND = 3 // 发起退款
|
||||||
|
THIRD_ORDER_TYPE_REFUND_QUERY = 4 // 退款查询
|
||||||
|
THIRD_ORDER_TYPE_CLOSE = 5 // 关闭订单
|
||||||
|
THIRD_ORDER_TYPE_CALL_BACK = 6 // 支付回调
|
||||||
)
|
)
|
||||||
|
|
||||||
var PayChannelList = map[int]string{
|
var PayChannelList = map[int]string{
|
||||||
|
|
|
@ -84,6 +84,7 @@ var MsgZH = map[int]string{
|
||||||
AppDisabled: "app通道关闭",
|
AppDisabled: "app通道关闭",
|
||||||
AppIpNotAllow: "ip不在白名单内",
|
AppIpNotAllow: "ip不在白名单内",
|
||||||
AppDecryptDataDiscrepancy: "解密数据不一致",
|
AppDecryptDataDiscrepancy: "解密数据不一致",
|
||||||
|
SystemError: "系统错误",
|
||||||
|
|
||||||
AppRsaDecryptKeyNotFound: "密匙缺失,无法进行Rsa解密",
|
AppRsaDecryptKeyNotFound: "密匙缺失,无法进行Rsa解密",
|
||||||
AppRsaDecryptFail: "Rsa解密失败",
|
AppRsaDecryptFail: "Rsa解密失败",
|
||||||
|
|
|
@ -47,8 +47,8 @@ func (m *OrderRepo) OrdersBackendList(conn builder.Cond, pageFilter entities.Pag
|
||||||
}
|
}
|
||||||
repo = repo.Join("left", "app", "app.id = orders.app_id").
|
repo = repo.Join("left", "app", "app.id = orders.app_id").
|
||||||
Join("left", "merchant", "merchant.id = orders.merchant_id").
|
Join("left", "merchant", "merchant.id = orders.merchant_id").
|
||||||
Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
Join("left", "pay_channel", "pay_channel.id = orders.pay_channel_id")
|
||||||
return repo.Desc("create_time").FindAndCount(orderList)
|
return repo.Desc("orders.create_time").FindAndCount(orderList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderRepo) OrdersLeftPayChannelList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.OrdersLeftPayChannelList) error {
|
func (m *OrderRepo) OrdersLeftPayChannelList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.OrdersLeftPayChannelList) error {
|
||||||
|
@ -57,7 +57,7 @@ func (m *OrderRepo) OrdersLeftPayChannelList(conn builder.Cond, pageFilter entit
|
||||||
if pageFilter.Page > 0 {
|
if pageFilter.Page > 0 {
|
||||||
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
||||||
}
|
}
|
||||||
repo = repo.Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
repo = repo.Join("left", "pay_channel", "pay_channel.id = orders.pay_channel_id")
|
||||||
return repo.Find(orderList)
|
return repo.Find(orderList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/go-pay/gopay"
|
"github.com/go-pay/gopay"
|
||||||
"github.com/go-pay/gopay/alipay"
|
"github.com/go-pay/gopay/alipay"
|
||||||
"github.com/go-pay/gopay/wechat/v3"
|
"github.com/go-pay/gopay/wechat/v3"
|
||||||
"github.com/go-pay/xlog"
|
|
||||||
"github.com/qit-team/snow-core/log/logger"
|
"github.com/qit-team/snow-core/log/logger"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -26,16 +25,23 @@ func WxCallback(c *gin.Context) {
|
||||||
logger.Info(c, "WxCallback-回调数据payChannelId", payChannelId)
|
logger.Info(c, "WxCallback-回调数据payChannelId", payChannelId)
|
||||||
if payChannelId == "" {
|
if payChannelId == "" {
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询应用下的支付配置
|
// 查询应用下的支付配置
|
||||||
var payChannelModel paychannelmodel.PayChannel
|
var payChannelModel paychannelmodel.PayChannel
|
||||||
payChannelIdInt, _ := strconv.Atoi(payChannelId)
|
payChannelIdInt, _ := strconv.Atoi(payChannelId)
|
||||||
payChannelModel.Id = int64(payChannelIdInt)
|
payChannelModel.Id = int64(payChannelIdInt)
|
||||||
services.PayChannelGet(&payChannelModel)
|
code := services.PayChannelGet(&payChannelModel)
|
||||||
|
if code == errorcode.PayChannelNotFound {
|
||||||
|
logger.Error(c, "AliCallback-回调数据未获取到支付配置,404")
|
||||||
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
|
}
|
||||||
if payChannelModel.ChannelType != common.PAY_CHANNEL_WECHAT_H5 {
|
if payChannelModel.ChannelType != common.PAY_CHANNEL_WECHAT_H5 {
|
||||||
logger.Error(c, "WxCallback-回调数据解析支付配置错误,查询的数据不是当前渠道")
|
logger.Error(c, "WxCallback-回调数据解析支付配置错误,查询的数据不是当前渠道")
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var wxConfig paymentService.WxPay
|
var wxConfig paymentService.WxPay
|
||||||
|
@ -43,22 +49,26 @@ func WxCallback(c *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "WxCallback-回调数据解析支付配置错误", fmt.Sprintf("错误原因:%s", err.Error()))
|
logger.Error(c, "WxCallback-回调数据解析支付配置错误", fmt.Sprintf("错误原因:%s", err.Error()))
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if wxConfig.ApiV3Key == "" || wxConfig.MchId == "" || wxConfig.PrivateKey == "" || wxConfig.SerialNo == "" {
|
if wxConfig.ApiV3Key == "" || wxConfig.MchId == "" || wxConfig.PrivateKey == "" || wxConfig.SerialNo == "" {
|
||||||
logger.Error(c, "WxCallback-回调数据解析支付配置错误,解析出来的信息为空")
|
logger.Error(c, "WxCallback-回调数据解析支付配置错误,解析出来的信息为空")
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
wxConfig.AppId = payChannelModel.AppId
|
wxConfig.AppId = payChannelModel.AppId
|
||||||
|
|
||||||
notifyReq, err := wechat.V3ParseNotify(c.Request)
|
notifyReq, err := wechat.V3ParseNotify(c.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "WxCallback-回调数据验签失败", err.Error())
|
logger.Error(c, "WxCallback-回调数据验签失败", err.Error())
|
||||||
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = paymentService.WxPayCallBack(notifyReq, wxConfig)
|
err = paymentService.WxPayCallBack(notifyReq, wxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "WxCallback-回调执行失败,失败原因:", err.Error())
|
logger.Error(c, "WxCallback-回调执行失败,失败原因:", err.Error())
|
||||||
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +76,7 @@ func WxCallback(c *gin.Context) {
|
||||||
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
||||||
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
||||||
c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// AliCallback 支付宝支付回调
|
// AliCallback 支付宝支付回调
|
||||||
|
@ -75,19 +86,22 @@ func AliCallback(c *gin.Context) {
|
||||||
logger.Info(c, "AliCallback-回调数据APPID", payChannelId)
|
logger.Info(c, "AliCallback-回调数据APPID", payChannelId)
|
||||||
if payChannelId == "" {
|
if payChannelId == "" {
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
// 查询应用下的支付配置
|
// 查询应用下的支付配置
|
||||||
var payChannelModel paychannelmodel.PayChannel
|
var payChannelModel paychannelmodel.PayChannel
|
||||||
payChannelIdInt, _ := strconv.Atoi(payChannelId)
|
payChannelIdInt, _ := strconv.Atoi(payChannelId)
|
||||||
payChannelModel.Id = int64(payChannelIdInt)
|
payChannelModel.Id = int64(payChannelIdInt)
|
||||||
code := services.PayChannelGet(&payChannelModel)
|
code := services.PayChannelGet(&payChannelModel)
|
||||||
if payChannelModel.ChannelType != common.PAY_CHANNEL_ALIPAY_WEB {
|
|
||||||
logger.Error(c, "AliCallback-回调数据解析支付配置错误,查询的数据不是当前渠道")
|
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
|
||||||
}
|
|
||||||
if code == errorcode.PayChannelNotFound {
|
if code == errorcode.PayChannelNotFound {
|
||||||
logger.Error(c, "AliCallback-回调数据未获取到支付配置,404")
|
logger.Error(c, "AliCallback-回调数据未获取到支付配置,404")
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if payChannelModel.ChannelType != common.PAY_CHANNEL_ALIPAY_WEB {
|
||||||
|
logger.Error(c, "AliCallback-回调数据解析支付配置错误,查询的数据不是当前渠道")
|
||||||
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var aliConfig paymentService.AliPay
|
var aliConfig paymentService.AliPay
|
||||||
|
@ -101,10 +115,12 @@ func AliCallback(c *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "AliCallback-回调数据解析支付配置错误", fmt.Sprintf("错误原因:%s", err.Error()))
|
logger.Error(c, "AliCallback-回调数据解析支付配置错误", fmt.Sprintf("错误原因:%s", err.Error()))
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if aliConfigModel.AlipayPublicCert == "" || aliConfigModel.PrivateKey == "" || aliConfigModel.AppPublicCert == "" || aliConfigModel.AlipayRootCert == "" {
|
if aliConfigModel.AlipayPublicCert == "" || aliConfigModel.PrivateKey == "" || aliConfigModel.AppPublicCert == "" || aliConfigModel.AlipayRootCert == "" {
|
||||||
logger.Error(c, "AliCallback-回调数据解析支付配置错误,解析出来的信息为空")
|
logger.Error(c, "AliCallback-回调数据解析支付配置错误,解析出来的信息为空")
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
aliConfig.AppId = payChannelModel.AppId
|
aliConfig.AppId = payChannelModel.AppId
|
||||||
aliConfig.PrivateKey = aliConfigModel.PrivateKey
|
aliConfig.PrivateKey = aliConfigModel.PrivateKey
|
||||||
|
@ -114,14 +130,16 @@ func AliCallback(c *gin.Context) {
|
||||||
|
|
||||||
notifyReq, err := alipay.ParseNotifyToBodyMap(c.Request) // c.Request 是 gin 框架的写法
|
notifyReq, err := alipay.ParseNotifyToBodyMap(c.Request) // c.Request 是 gin 框架的写法
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Error(err)
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = paymentService.ALiCallBack(notifyReq, aliConfig)
|
err = paymentService.ALiCallBack(notifyReq, aliConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "AliCallback-回调执行失败,失败原因:", err.Error())
|
logger.Error(c, "AliCallback-回调执行失败,失败原因:", err.Error())
|
||||||
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.String(http.StatusOK, "%s", "success")
|
c.String(http.StatusOK, "%s", "success")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ import (
|
||||||
type OrderListRequest struct {
|
type OrderListRequest struct {
|
||||||
Id int64 `json:"id" form:"id"`
|
Id int64 `json:"id" form:"id"`
|
||||||
MerchantId int64 `json:"merchant_id" form:"merchant_id"`
|
MerchantId int64 `json:"merchant_id" form:"merchant_id"`
|
||||||
PayId int64 `json:"pay_id" form:"pay_id"`
|
PayChannelId int64 `json:"pay_channel_id" form:"pay_channel_id"`
|
||||||
AppId int64 `json:"app_id" form:"app_id"`
|
AppId int64 `json:"app_id" form:"app_id"`
|
||||||
MerchantOrderId string `json:"merchant_order_id" form:"merchant_order_id"`
|
OutTreadNo string `json:"out_tread_no" form:"out_tread_no"`
|
||||||
Status int `json:"status" form:"status"`
|
Status int `json:"status" form:"status"`
|
||||||
OrderType int `json:"order_type" form:"order_type"`
|
OrderType int `json:"order_type" form:"order_type"`
|
||||||
StartTime string `json:"start_time" form:"start_time"`
|
StartTime string `json:"start_time" form:"start_time"`
|
||||||
|
@ -26,9 +26,9 @@ type OrderListRequest struct {
|
||||||
type OrderList struct {
|
type OrderList struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
MerchantId int64 `json:"merchant_id"`
|
MerchantId int64 `json:"merchant_id"`
|
||||||
PayId int64 `json:"pay_id"`
|
PayChannelId int64 `json:"pay_channel_id"`
|
||||||
AppId int64 `json:"app_id"`
|
AppId int64 `json:"app_id"`
|
||||||
MerchantOrderId string `json:"merchant_order_id"`
|
OutTreadNo string `json:"out_tread_no"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
OrderType int `json:"order_type"`
|
OrderType int `json:"order_type"`
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
|
@ -54,9 +54,9 @@ func (o *OrderListRequest) ValidateRequest() (r OrderList, err error) {
|
||||||
|
|
||||||
r.Id = o.Id
|
r.Id = o.Id
|
||||||
r.MerchantId = o.MerchantId
|
r.MerchantId = o.MerchantId
|
||||||
r.PayId = o.PayId
|
r.PayChannelId = o.PayChannelId
|
||||||
r.AppId = o.AppId
|
r.AppId = o.AppId
|
||||||
r.MerchantOrderId = o.MerchantOrderId
|
r.OutTreadNo = o.OutTreadNo
|
||||||
r.Status = o.Status
|
r.Status = o.Status
|
||||||
r.OrderType = o.OrderType
|
r.OrderType = o.OrderType
|
||||||
r.PageRequest = o.PageRequest
|
r.PageRequest = o.PageRequest
|
||||||
|
@ -70,13 +70,10 @@ type OrdersResponse struct {
|
||||||
PayChannelId int64 `json:"pay_channel_id"`
|
PayChannelId int64 `json:"pay_channel_id"`
|
||||||
AppId int64 `json:"app_id"`
|
AppId int64 `json:"app_id"`
|
||||||
OutTreadNo string `json:"out_tread_no"`
|
OutTreadNo string `json:"out_tread_no"`
|
||||||
Status int32 `json:"status"`
|
Status int `json:"status"`
|
||||||
OrderType int32 `json:"order_type"`
|
OrderType int `json:"order_type"`
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
IpAddress string `json:"ip_address"`
|
PayerTotal int `json:"payer_total"`
|
||||||
MerchantRequest string `json:"merchant_request"`
|
|
||||||
MerchantResponse string `json:"merchant_response"`
|
|
||||||
OrderResponse string `json:"order_response"`
|
|
||||||
ExtJson string `json:"ext_json"`
|
ExtJson string `json:"ext_json"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
UpdateTime string `json:"update_time"`
|
UpdateTime string `json:"update_time"`
|
||||||
|
@ -94,6 +91,7 @@ func (o *OrdersResponse) ResponseFromDb(db ordersmodel.OrdersBackendList) {
|
||||||
o.Status = db.Status
|
o.Status = db.Status
|
||||||
o.OrderType = db.OrderType
|
o.OrderType = db.OrderType
|
||||||
o.Amount = db.Amount
|
o.Amount = db.Amount
|
||||||
|
o.PayerTotal = db.PayerTotal
|
||||||
o.ExtJson = db.ExtJson
|
o.ExtJson = db.ExtJson
|
||||||
o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||||
o.UpdateTime = db.UpdateTime.Format("2006-01-02 15:04:05")
|
o.UpdateTime = db.UpdateTime.Format("2006-01-02 15:04:05")
|
||||||
|
|
|
@ -17,7 +17,7 @@ type PayChannelResponse struct {
|
||||||
AppId string `json:"app_id"`
|
AppId string `json:"app_id"`
|
||||||
ExpireTime string `json:"expire_time"`
|
ExpireTime string `json:"expire_time"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
AliPayPayChannel *AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
AliPayChannel *AliPayChannel `json:"ali_pay_channel,omitempty"`
|
||||||
WechatPayChannel *WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
WechatPayChannel *WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
|
||||||
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
|
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
|
||||||
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
|
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel)
|
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ type PayChannelCreateRequest struct {
|
||||||
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
||||||
ExpireTime string `json:"expire_time"`
|
ExpireTime string `json:"expire_time"`
|
||||||
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
AliPayChannel AliPayChannel `json:"ali_pay_channel,omitempty"`
|
||||||
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ type WechatPayChannel struct {
|
||||||
PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容
|
PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliPayPayChannel struct {
|
type AliPayChannel struct {
|
||||||
PrivateKey string `json:"private_key"` // 应用私钥
|
PrivateKey string `json:"private_key"` // 应用私钥
|
||||||
AppPublicCert string `json:"app_public_cert"` // 应用公钥
|
AppPublicCert string `json:"app_public_cert"` // 应用公钥
|
||||||
AlipayRootCert string `json:"alipay_root_cert"` // 支付宝根证书
|
AlipayRootCert string `json:"alipay_root_cert"` // 支付宝根证书
|
||||||
|
@ -78,7 +78,7 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
|
||||||
b, _ := json.Marshal(p.WechatPayChannel)
|
b, _ := json.Marshal(p.WechatPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
b, _ := json.Marshal(p.AliPayPayChannel)
|
b, _ := json.Marshal(p.AliPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
default:
|
default:
|
||||||
err = errors.New("支付渠道类型错误")
|
err = errors.New("支付渠道类型错误")
|
||||||
|
@ -98,7 +98,7 @@ type PayChannelUpdateRequest struct {
|
||||||
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
||||||
ExpireTime string `json:"expire_time"`
|
ExpireTime string `json:"expire_time"`
|
||||||
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
AliPayChannel AliPayChannel `json:"ali_pay_channel,omitempty"`
|
||||||
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, e
|
||||||
b, _ := json.Marshal(p.WechatPayChannel)
|
b, _ := json.Marshal(p.WechatPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
b, _ := json.Marshal(p.AliPayPayChannel)
|
b, _ := json.Marshal(p.AliPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
default:
|
default:
|
||||||
err = errors.New("支付渠道类型错误")
|
err = errors.New("支付渠道类型错误")
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Orders struct {
|
||||||
OutTreadNo string `xorm:"'out_tread_no' varchar(50)"`
|
OutTreadNo string `xorm:"'out_tread_no' varchar(50)"`
|
||||||
OrderType int32 `xorm:"'order_type' TINYINT"`
|
OrderType int32 `xorm:"'order_type' TINYINT"`
|
||||||
Amount int `xorm:"'amount' int(11)"`
|
Amount int `xorm:"'amount' int(11)"`
|
||||||
|
PayerTotal int `xorm:"'payer_total' int(11)"`
|
||||||
ExtJson string `xorm:"'ext_json' varchar(1024)"`
|
ExtJson string `xorm:"'ext_json' varchar(1024)"`
|
||||||
Desc string `xorm:"'desc' varchar(100)"`
|
Desc string `xorm:"'desc' varchar(100)"`
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||||
|
|
|
@ -15,10 +15,11 @@ var (
|
||||||
type OrderThirdPayLog struct {
|
type OrderThirdPayLog struct {
|
||||||
Id int64
|
Id int64
|
||||||
OrderId int64 `xorm:"'order_id' bigint(20)"`
|
OrderId int64 `xorm:"'order_id' bigint(20)"`
|
||||||
PayCallback string `xorm:"'pay_callback' varchar(255)"`
|
PayCallback string `xorm:"'pay_callback' JSON"`
|
||||||
Status int `xorm:"'status' TINYINT"`
|
Status int `xorm:"'status' TINYINT"`
|
||||||
MerchantParam string `xorm:"'merchant_param' varchar(255)"`
|
PayParam string `xorm:"'pay_param' JSON"`
|
||||||
MerchantCallback string `xorm:"'merchant_callback' varchar(255)"`
|
MerchantCallback string `xorm:"'merchant_callback' JSON"`
|
||||||
|
Type int `xorm:"'type' TINYINT"`
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, t
|
||||||
if req.MerchantId > 0 {
|
if req.MerchantId > 0 {
|
||||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||||||
}
|
}
|
||||||
if req.PayId > 0 {
|
if req.PayChannelId > 0 {
|
||||||
conn = conn.And(builder.Eq{"pay_id": req.PayId})
|
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
|
||||||
}
|
}
|
||||||
if req.AppId > 0 {
|
if req.AppId > 0 {
|
||||||
conn = conn.And(builder.Eq{"app_id": req.AppId})
|
conn = conn.And(builder.Eq{"app_id": req.AppId})
|
||||||
}
|
}
|
||||||
if req.MerchantOrderId != "" {
|
if req.OutTreadNo != "" {
|
||||||
conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId})
|
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
|
||||||
}
|
}
|
||||||
if req.Status > 0 {
|
if req.Status > 0 {
|
||||||
conn = conn.And(builder.Eq{"status": req.Status})
|
conn = conn.And(builder.Eq{"status": req.Status})
|
||||||
|
|
|
@ -2,6 +2,7 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -20,12 +21,13 @@ var (
|
||||||
|
|
||||||
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
|
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
|
||||||
func AliInitClient(aliConfig AliPay) {
|
func AliInitClient(aliConfig AliPay) {
|
||||||
|
envConfig := config.GetConf()
|
||||||
aliOnce.Do(func() {
|
aliOnce.Do(func() {
|
||||||
// 初始化支付宝客户端
|
// 初始化支付宝客户端
|
||||||
// appid:应用ID
|
// appid:应用ID
|
||||||
// privateKey:应用私钥,支持PKCS1和PKCS8
|
// privateKey:应用私钥,支持PKCS1和PKCS8
|
||||||
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。
|
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。
|
||||||
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
|
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, envConfig.PayService.IsProd)
|
||||||
})
|
})
|
||||||
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
||||||
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
||||||
|
@ -72,12 +74,12 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
|
||||||
// 初始化 BodyMap
|
// 初始化 BodyMap
|
||||||
amount := float64(payOrderRequest.Amount) / 100.0
|
amount := float64(payOrderRequest.Amount) / 100.0
|
||||||
|
|
||||||
|
envConfig := config.GetConf()
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
||||||
Set("total_amount", amount).
|
Set("total_amount", amount).
|
||||||
Set("subject", payOrderRequest.Description).
|
Set("subject", payOrderRequest.Description).
|
||||||
//Set("notify_url", fmt.Sprintf(payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
|
Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
|
||||||
Set("notify_url", fmt.Sprintf(payCommon.ALI_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId))
|
|
||||||
|
|
||||||
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,8 +149,8 @@ func ALiOrderQuery(ctx context.Context, aliConfig AliPay, OrderNo string) (PayOr
|
||||||
tradeStateDesc = "未付款交易超时关闭,或支付完成后全额退款"
|
tradeStateDesc = "未付款交易超时关闭,或支付完成后全额退款"
|
||||||
}
|
}
|
||||||
|
|
||||||
amountTotal, _ := strconv.Atoi(aliRsp.Response.TotalAmount)
|
amountTotal, _ := strconv.ParseFloat(aliRsp.Response.TotalAmount, 64)
|
||||||
payerTotal, _ := strconv.Atoi(aliRsp.Response.BuyerPayAmount)
|
payerTotal, _ := strconv.ParseFloat(aliRsp.Response.BuyerPayAmount, 64)
|
||||||
// 构建数据
|
// 构建数据
|
||||||
outTradeNo, _ := strconv.Atoi(aliRsp.Response.OutTradeNo)
|
outTradeNo, _ := strconv.Atoi(aliRsp.Response.OutTradeNo)
|
||||||
return PayOrderQueryInfo{
|
return PayOrderQueryInfo{
|
||||||
|
@ -175,9 +177,10 @@ func AliRefundOrder(ctx context.Context, orderRefundRequest OrderRefundRequest)
|
||||||
return OrderRefundInfo{}, err
|
return OrderRefundInfo{}, err
|
||||||
}
|
}
|
||||||
// 请求参数
|
// 请求参数
|
||||||
|
refundAmount := float64(orderRefundRequest.RefundAmount) / 100.0
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("out_trade_no", orderRefundRequest.OrderId).
|
bm.Set("out_trade_no", orderRefundRequest.OrderId).
|
||||||
Set("refund_amount", orderRefundRequest.RefundAmount).
|
Set("refund_amount", refundAmount).
|
||||||
Set("refund_reason", orderRefundRequest.RefundReason).
|
Set("refund_reason", orderRefundRequest.RefundReason).
|
||||||
Set("out_request_no", orderRefundRequest.RefundOrderId)
|
Set("out_request_no", orderRefundRequest.RefundOrderId)
|
||||||
|
|
||||||
|
@ -191,14 +194,15 @@ func AliRefundOrder(ctx context.Context, orderRefundRequest OrderRefundRequest)
|
||||||
return OrderRefundInfo{}, err
|
return OrderRefundInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
refundFee, _ := strconv.Atoi(aliRsp.Response.RefundFee)
|
refundFee, _ := strconv.ParseFloat(aliRsp.Response.RefundFee, 64)
|
||||||
outTradeNo, _ := strconv.Atoi(aliRsp.Response.OutTradeNo)
|
outTradeNo, _ := strconv.ParseFloat(aliRsp.Response.OutTradeNo, 64)
|
||||||
return OrderRefundInfo{
|
return OrderRefundInfo{
|
||||||
OutTradeNo: int64(outTradeNo),
|
OutTradeNo: int64(outTradeNo),
|
||||||
TransactionId: aliRsp.Response.TradeNo,
|
TransactionId: aliRsp.Response.TradeNo,
|
||||||
RefundFee: int64(refundFee * 100),
|
RefundFee: int64(refundFee * 100),
|
||||||
RefundOrderId: orderRefundRequest.RefundOrderId,
|
RefundOrderId: orderRefundRequest.RefundOrderId,
|
||||||
RefundStatus: payCommon.PAY_REFUND_STATU_SUCCESS,
|
RefundStatus: payCommon.PAY_REFUND_STATU_SUCCESS,
|
||||||
|
RefundSuccessTime: aliRsp.Response.GmtRefundPay,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +232,7 @@ func AliRefundOrderQuery(ctx context.Context, orderRefundQueryRequest OrderRefun
|
||||||
}
|
}
|
||||||
return OrderRefundInfo{}, err
|
return OrderRefundInfo{}, err
|
||||||
}
|
}
|
||||||
refundFee, _ := strconv.Atoi(aliRsp.Response.RefundAmount)
|
refundFee, _ := strconv.ParseFloat(aliRsp.Response.RefundAmount, 64)
|
||||||
outTradeNo, _ := strconv.Atoi(aliRsp.Response.OutTradeNo)
|
outTradeNo, _ := strconv.Atoi(aliRsp.Response.OutTradeNo)
|
||||||
refundOrderId, _ := strconv.Atoi(aliRsp.Response.OutRequestNo)
|
refundOrderId, _ := strconv.Atoi(aliRsp.Response.OutRequestNo)
|
||||||
return OrderRefundInfo{
|
return OrderRefundInfo{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package payCommon
|
package payCommon
|
||||||
|
|
||||||
|
import "PaymentCenter/app/constants/common"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TEST_URL = ""
|
|
||||||
PROD_URL = ""
|
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
PAY_CHANNEL_UNKNOWN = 0
|
||||||
|
@ -21,10 +21,10 @@ const (
|
||||||
|
|
||||||
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
|
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
|
||||||
|
|
||||||
WX_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
||||||
WX_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
||||||
ALI_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
||||||
ALI_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
||||||
|
|
||||||
ORDER_NO_TYPE_ORDER_NO = 2
|
ORDER_NO_TYPE_ORDER_NO = 2
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package paymentService
|
package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/data"
|
||||||
|
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
||||||
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"github.com/qit-team/snow-core/log/logger"
|
"github.com/qit-team/snow-core/log/logger"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -49,7 +54,7 @@ type PayOrderResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaymentService 统一发起支付
|
// PaymentService 统一发起支付
|
||||||
func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrderResponse PayOrderResponse) {
|
func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrderResponse {
|
||||||
logger.Info(c, "PaymentService 收到支付请求", payOrderRequest)
|
logger.Info(c, "PaymentService 收到支付请求", payOrderRequest)
|
||||||
var err error
|
var err error
|
||||||
var info string
|
var info string
|
||||||
|
@ -72,11 +77,20 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrde
|
||||||
ErrorMsg: err.Error(),
|
ErrorMsg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PayOrderResponse{
|
payOrderResponse := PayOrderResponse{
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
Code: payCommon.PAY_SUCCESS_CODE,
|
||||||
ErrorMsg: "",
|
ErrorMsg: "",
|
||||||
Result: info,
|
Result: info,
|
||||||
}
|
}
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
orderId := payOrderRequest.OrderId
|
||||||
|
payCallback := info
|
||||||
|
payParam, _ := json.Marshal(payOrderRequest)
|
||||||
|
merchantCallback, _ := json.Marshal(payOrderResponse)
|
||||||
|
saveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
|
||||||
|
}()
|
||||||
|
return payOrderResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayOrderQueryRequest struct {
|
type PayOrderQueryRequest struct {
|
||||||
|
@ -125,10 +139,21 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
|
||||||
ErrorMsg: err.Error(),
|
ErrorMsg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PayOrderQueryResponse{
|
|
||||||
|
payOrderQueryResponse := PayOrderQueryResponse{
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
Code: payCommon.PAY_SUCCESS_CODE,
|
||||||
Result: info,
|
Result: info,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
orderId := payOrderQueryRequest.OrderId
|
||||||
|
payCallback, _ := json.Marshal(info)
|
||||||
|
payParam, _ := json.Marshal(payOrderQueryRequest)
|
||||||
|
merchantCallback, _ := json.Marshal(payOrderQueryResponse)
|
||||||
|
saveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||||
|
}()
|
||||||
|
return payOrderQueryResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderRefundRequest struct {
|
type OrderRefundRequest struct {
|
||||||
|
@ -179,10 +204,21 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
|
||||||
ErrorMsg: err.Error(),
|
ErrorMsg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OrderRefundResponse{
|
|
||||||
|
orderRefundResponse := OrderRefundResponse{
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
Code: payCommon.PAY_SUCCESS_CODE,
|
||||||
Result: info,
|
Result: info,
|
||||||
}
|
}
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
orderId := orderRefundRequest.OrderId
|
||||||
|
payCallback, _ := json.Marshal(info)
|
||||||
|
payParam, _ := json.Marshal(orderRefundRequest)
|
||||||
|
merchantCallback, _ := json.Marshal(orderRefundResponse)
|
||||||
|
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
|
||||||
|
}()
|
||||||
|
|
||||||
|
return orderRefundResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderRefundQueryRequest struct {
|
type OrderRefundQueryRequest struct {
|
||||||
|
@ -220,10 +256,21 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
|
||||||
ErrorMsg: err.Error(),
|
ErrorMsg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OrderRefundQueryResponse{
|
orderRefundQueryResponse := OrderRefundQueryResponse{
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
Code: payCommon.PAY_SUCCESS_CODE,
|
||||||
Result: info,
|
Result: info,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
orderId := orderRefundQueryRequest.OrderId
|
||||||
|
payCallback, _ := json.Marshal(info)
|
||||||
|
payParam, _ := json.Marshal(orderRefundQueryRequest)
|
||||||
|
merchantCallback, _ := json.Marshal(orderRefundQueryResponse)
|
||||||
|
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||||
|
}()
|
||||||
|
|
||||||
|
return orderRefundQueryResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderCloseRequest struct {
|
type OrderCloseRequest struct {
|
||||||
|
@ -266,8 +313,35 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
|
||||||
ErrorMsg: err.Error(),
|
ErrorMsg: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OrderCloseResponse{
|
orderCloseResponse := OrderCloseResponse{
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
Code: payCommon.PAY_SUCCESS_CODE,
|
||||||
Result: info,
|
Result: info,
|
||||||
}
|
}
|
||||||
|
// 记录日志
|
||||||
|
go func() {
|
||||||
|
orderId := orderCloseRequest.OrderId
|
||||||
|
payCallback, _ := json.Marshal(info)
|
||||||
|
payParam, _ := json.Marshal(orderCloseRequest)
|
||||||
|
merchantCallback, _ := json.Marshal(orderCloseResponse)
|
||||||
|
saveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
|
||||||
|
}()
|
||||||
|
|
||||||
|
return orderCloseResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
// saveLog 记录操作日志
|
||||||
|
func saveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
|
||||||
|
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
|
||||||
|
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||||
|
OrderId: orderId,
|
||||||
|
PayCallback: payCallback,
|
||||||
|
Status: 0,
|
||||||
|
PayParam: PayParam,
|
||||||
|
MerchantCallback: MerchantCallback,
|
||||||
|
Type: OType,
|
||||||
|
}
|
||||||
|
_, err := thirdRepo.OrderThirdPayLogInsertOne(&log)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -67,14 +68,14 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er
|
||||||
}
|
}
|
||||||
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
||||||
// 初始化 BodyMap
|
// 初始化 BodyMap
|
||||||
|
envConfig := config.GetConf()
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("appid", payOrderRequest.Wx.AppId).
|
bm.Set("appid", payOrderRequest.Wx.AppId).
|
||||||
Set("mchid", payOrderRequest.Wx.MchId).
|
Set("mchid", payOrderRequest.Wx.MchId).
|
||||||
Set("description", payOrderRequest.Description).
|
Set("description", payOrderRequest.Description).
|
||||||
Set("out_trade_no", payOrderRequest.OrderId).
|
Set("out_trade_no", strconv.FormatInt(payOrderRequest.OrderId, 10)).
|
||||||
Set("time_expire", expire).
|
Set("time_expire", expire).
|
||||||
//Set("notify_url", fmt.Sprintf(payCommon.WX_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
|
Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.WX_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
|
||||||
Set("notify_url", fmt.Sprintf(payCommon.WX_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId)).
|
|
||||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
bm.Set("total", payOrderRequest.Amount).
|
bm.Set("total", payOrderRequest.Amount).
|
||||||
Set("currency", "CNY")
|
Set("currency", "CNY")
|
||||||
|
@ -198,10 +199,10 @@ func WxOrderRefund(ctx context.Context, orderRefundRequest OrderRefundRequest) (
|
||||||
}
|
}
|
||||||
// 初始化 BodyMap
|
// 初始化 BodyMap
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("out_trade_no", orderRefundRequest.OrderId).
|
bm.Set("out_trade_no", strconv.FormatInt(orderRefundRequest.OrderId, 10)).
|
||||||
Set("sign_type", "MD5").
|
Set("sign_type", "MD5").
|
||||||
// 必填 退款订单号(程序员定义的)
|
// 必填 退款订单号(程序员定义的)
|
||||||
Set("out_refund_no", orderRefundRequest.RefundOrderId).
|
Set("out_refund_no", strconv.FormatInt(orderRefundRequest.RefundOrderId, 10)).
|
||||||
// 选填 退款描述
|
// 选填 退款描述
|
||||||
Set("reason", orderRefundRequest.RefundReason).
|
Set("reason", orderRefundRequest.RefundReason).
|
||||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
|
@ -297,7 +298,7 @@ func WxCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (Ord
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OrderCloseInfo{}, err
|
return OrderCloseInfo{}, err
|
||||||
}
|
}
|
||||||
wxRsp, err := wxClient.V3TransactionCloseOrder(ctx, "FY160932049419637602")
|
wxRsp, err := wxClient.V3TransactionCloseOrder(ctx, strconv.FormatInt(orderCloseRequest.OrderId, 10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OrderCloseInfo{}, err
|
return OrderCloseInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -450,3 +450,15 @@ func SliceInStr(s string, slice []string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断支付方式支付宝或者微信
|
||||||
|
func PayType(payChannel int) int {
|
||||||
|
switch payChannel {
|
||||||
|
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
|
||||||
|
return common.PAY_CHANNLE_TYPE_WECHAT
|
||||||
|
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
|
return common.PAY_CHANNLE_TYPE_ZFB
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ type Config struct {
|
||||||
AliOss AliOss `toml:"AliOss"`
|
AliOss AliOss `toml:"AliOss"`
|
||||||
AdminGate []string `toml:"AdminGate"`
|
AdminGate []string `toml:"AdminGate"`
|
||||||
CronConfig CronConfig `toml:"CronConfig"`
|
CronConfig CronConfig `toml:"CronConfig"`
|
||||||
|
PayService PayService `toml:"PayService"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliOss struct {
|
type AliOss struct {
|
||||||
|
@ -91,6 +92,11 @@ type CronConfig struct {
|
||||||
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PayService struct {
|
||||||
|
Host string `toml:"Host"`
|
||||||
|
IsProd bool `toml:"IsProd"`
|
||||||
|
}
|
||||||
|
|
||||||
func newConfig() *Config {
|
func newConfig() *Config {
|
||||||
return new(Config)
|
return new(Config)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue