Compare commits
No commits in common. "e8576d67d9c3609dc85e47f37926dd11286776c2" and "a7cf191437f7f16bb8255728efd3a75da42723d3" have entirely different histories.
e8576d67d9
...
a7cf191437
|
@ -4,7 +4,6 @@ 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"
|
||||||
|
@ -29,59 +28,20 @@ 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{"orders.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{"create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.CloseOrderTime))})
|
||||||
// 查询订单
|
|
||||||
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
|
order := make([]ordersmodel.Orders, 0)
|
||||||
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
|
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
||||||
} else if len(order) > 0 {
|
} else if total > 0 {
|
||||||
for i := range order {
|
orderIds := make([]int64, 0)
|
||||||
orderInfo := order[i]
|
for _, v := range order {
|
||||||
// 往上游发送关闭订单请求
|
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()
|
||||||
|
@ -92,7 +52,7 @@ func closeOrder() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.Log(nil, "关闭订单,修改订单状态成功", "总数量="+strconv.Itoa(len(order)), "成功数量="+strconv.Itoa(len(orderIds)))
|
utils.Log(nil, "关闭订单,修改订单状态成功", "count="+strconv.Itoa(len(order)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 主动查询订单支付状态
|
// 主动查询订单支付状态
|
||||||
|
@ -104,6 +64,7 @@ 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)
|
||||||
|
@ -129,32 +90,13 @@ func queryOrder() {
|
||||||
query := paymentService.PayOrderQueryRequest{
|
query := paymentService.PayOrderQueryRequest{
|
||||||
OrderId: orderInfo.Id,
|
OrderId: orderInfo.Id,
|
||||||
}
|
}
|
||||||
switch utils.PayType(orderInfo.ChannelType) {
|
switch orderInfo.ChannelType {
|
||||||
case common.PAY_CHANNLE_TYPE_WECHAT:
|
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:
|
||||||
wx := backend.WechatPayChannel{}
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.Wx)
|
||||||
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
|
||||||
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
||||||
query.Wx = paymentService.WxPay{
|
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
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), &ali)
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起查询
|
// 发起查询
|
||||||
|
@ -210,10 +152,9 @@ func queryOrder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入日志
|
// 写入日志
|
||||||
body, _ := json.Marshal(result)
|
|
||||||
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||||
OrderId: orderInfo.Id,
|
OrderId: orderInfo.Id,
|
||||||
PayCallback: string(body),
|
PayCallback: "",
|
||||||
Status: 0,
|
Status: 0,
|
||||||
MerchantParam: "",
|
MerchantParam: "",
|
||||||
MerchantCallback: "",
|
MerchantCallback: "",
|
||||||
|
|
|
@ -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 = "/pay/front/api/v1"
|
FRONT_V1 = "/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
|
||||||
|
@ -28,7 +28,4 @@ const (
|
||||||
ORDER_STATUS_PAYED = 3
|
ORDER_STATUS_PAYED = 3
|
||||||
ORDER_STATUS_FAILED = 4
|
ORDER_STATUS_FAILED = 4
|
||||||
ORDER_STATUS_CLOSE = 5
|
ORDER_STATUS_CLOSE = 5
|
||||||
|
|
||||||
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
|
|
||||||
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -57,7 +57,6 @@ var MsgZH = map[int]string{
|
||||||
AppNotFound: "app_id未找到",
|
AppNotFound: "app_id未找到",
|
||||||
AppDisabled: "app通道关闭",
|
AppDisabled: "app通道关闭",
|
||||||
AppIpNotAllow: "ip不在白名单内",
|
AppIpNotAllow: "ip不在白名单内",
|
||||||
SystemError: "系统错误",
|
|
||||||
PayChannelNotFound: "支付方式不存在",
|
PayChannelNotFound: "支付方式不存在",
|
||||||
}
|
}
|
||||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||||
|
|
|
@ -46,8 +46,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_channel_id")
|
Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
||||||
return repo.Desc("orders.create_time").FindAndCount(orderList)
|
return repo.Desc("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 {
|
||||||
|
@ -56,6 +56,6 @@ 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_channel_id")
|
repo = repo.Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
||||||
return repo.Find(orderList)
|
return repo.Find(orderList)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"`
|
||||||
PayChannelId int64 `json:"pay_channel_id" form:"pay_channel_id"`
|
PayId int64 `json:"pay_id" form:"pay_id"`
|
||||||
AppId int64 `json:"app_id" form:"app_id"`
|
AppId int64 `json:"app_id" form:"app_id"`
|
||||||
OutTreadNo string `json:"out_tread_no" form:"out_tread_no"`
|
MerchantOrderId string `json:"merchant_order_id" form:"merchant_order_id"`
|
||||||
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"`
|
||||||
PayChannelId int64 `json:"pay_channel_id"`
|
PayId int64 `json:"pay_id"`
|
||||||
AppId int64 `json:"app_id"`
|
AppId int64 `json:"app_id"`
|
||||||
OutTreadNo string `json:"out_tread_no"`
|
MerchantOrderId string `json:"merchant_order_id"`
|
||||||
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.PayChannelId = o.PayChannelId
|
r.PayId = o.PayId
|
||||||
r.AppId = o.AppId
|
r.AppId = o.AppId
|
||||||
r.OutTreadNo = o.OutTreadNo
|
r.MerchantOrderId = o.MerchantOrderId
|
||||||
r.Status = o.Status
|
r.Status = o.Status
|
||||||
r.OrderType = o.OrderType
|
r.OrderType = o.OrderType
|
||||||
r.PageRequest = o.PageRequest
|
r.PageRequest = o.PageRequest
|
||||||
|
@ -73,6 +73,10 @@ type OrdersResponse struct {
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
OrderType int `json:"order_type"`
|
OrderType int `json:"order_type"`
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
|
IpAddress string `json:"ip_address"`
|
||||||
|
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"`
|
||||||
|
|
|
@ -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"`
|
||||||
AliPayChannel *AliPayChannel `json:"ali_pay_channel,omitempty"`
|
AliPayPayChannel *AliPayPayChannel `json:"ali_pay_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.AliPayChannel)
|
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"`
|
||||||
AliPayChannel AliPayChannel `json:"ali_pay_channel,omitempty"`
|
AliPayPayChannel AliPayPayChannel `json:"ali_pay_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 AliPayChannel struct {
|
type AliPayPayChannel 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.AliPayChannel)
|
b, _ := json.Marshal(p.AliPayPayChannel)
|
||||||
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"`
|
||||||
AliPayChannel AliPayChannel `json:"ali_pay_channel,omitempty"`
|
AliPayPayChannel AliPayPayChannel `json:"ali_pay_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.AliPayChannel)
|
b, _ := json.Marshal(p.AliPayPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
default:
|
default:
|
||||||
err = errors.New("支付渠道类型错误")
|
err = errors.New("支付渠道类型错误")
|
||||||
|
|
|
@ -4,7 +4,6 @@ package routes
|
||||||
* 配置路由
|
* 配置路由
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/constants/common"
|
|
||||||
"PaymentCenter/app/http/controllers"
|
"PaymentCenter/app/http/controllers"
|
||||||
"PaymentCenter/app/http/controllers/backend"
|
"PaymentCenter/app/http/controllers/backend"
|
||||||
"PaymentCenter/app/http/controllers/front"
|
"PaymentCenter/app/http/controllers/front"
|
||||||
|
@ -48,7 +47,7 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
|
|
||||||
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
v1 := router.Group(common.FRONT_V1)
|
v1 := router.Group("/v1")
|
||||||
{
|
{
|
||||||
//回调处理
|
//回调处理
|
||||||
notify := v1.Group("/notify")
|
notify := v1.Group("/notify")
|
||||||
|
|
|
@ -21,14 +21,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.PayChannelId > 0 {
|
if req.PayId > 0 {
|
||||||
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
|
conn = conn.And(builder.Eq{"pay_id": req.PayId})
|
||||||
}
|
}
|
||||||
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.OutTreadNo != "" {
|
if req.MerchantOrderId != "" {
|
||||||
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
|
conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId})
|
||||||
}
|
}
|
||||||
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,7 +2,6 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"PaymentCenter/config"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -21,13 +20,12 @@ 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, envConfig.PayService.IsProd)
|
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
|
||||||
})
|
})
|
||||||
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
||||||
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
||||||
|
@ -74,12 +72,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(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
|
//Set("notify_url", fmt.Sprintf(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 {
|
||||||
|
|
|
@ -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 = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/wx/" // 微信支付回调地址
|
||||||
WX_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/wx/" // 微信支付回调地址
|
||||||
ALI_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
||||||
ALI_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
||||||
|
|
||||||
ORDER_NO_TYPE_ORDER_NO = 2
|
ORDER_NO_TYPE_ORDER_NO = 2
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,6 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"PaymentCenter/config"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -68,14 +67,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", payOrderRequest.OrderId).
|
||||||
Set("time_expire", expire).
|
Set("time_expire", expire).
|
||||||
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_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")
|
||||||
|
|
|
@ -450,15 +450,3 @@ 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,7 +39,6 @@ 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 {
|
||||||
|
@ -92,11 +91,6 @@ type CronConfig struct {
|
||||||
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayService struct {
|
|
||||||
Host string `toml:"TestHost"`
|
|
||||||
IsProd bool `toml:"IsProd"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func newConfig() *Config {
|
func newConfig() *Config {
|
||||||
return new(Config)
|
return new(Config)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue