Compare commits

..

No commits in common. "e8576d67d9c3609dc85e47f37926dd11286776c2" and "a7cf191437f7f16bb8255728efd3a75da42723d3" have entirely different histories.

14 changed files with 110 additions and 198 deletions

View File

@ -4,7 +4,6 @@ import (
"PaymentCenter/app/constants/common"
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/ordersmodel"
"PaymentCenter/app/models/orderthirdpaylogmodel"
"PaymentCenter/app/third/paymentService"
@ -29,59 +28,20 @@ func RegisterCommand(c *command.Command) {
func closeOrder() {
var now = time.Now().Format(time.DateTime)
utils.Log(nil, "关闭订单", now)
var ctx = context.Background()
orderIds := make([]int64, 0)
// 查询未支付的订单
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
// 拼接条件
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))})
// 查询订单
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
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.Orders, 0)
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
if err != nil {
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
} else if len(order) > 0 {
for i := range order {
orderInfo := order[i]
// 往上游发送关闭订单请求
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)
}
} else if total > 0 {
orderIds := make([]int64, 0)
for _, v := range order {
orderIds = append(orderIds, v.Id)
}
// 修改订单状态为关闭
cond = builder.NewCond()
@ -92,7 +52,7 @@ func closeOrder() {
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())
// 拼接条件
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))})
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
@ -129,32 +90,13 @@ func queryOrder() {
query := paymentService.PayOrderQueryRequest{
OrderId: orderInfo.Id,
}
switch utils.PayType(orderInfo.ChannelType) {
case common.PAY_CHANNLE_TYPE_WECHAT:
wx := backend.WechatPayChannel{}
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
switch 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:
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.Wx)
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
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{}
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
_ = 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
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &query.Ali)
}
// 发起查询
@ -210,10 +152,9 @@ func queryOrder() {
}
// 写入日志
body, _ := json.Marshal(result)
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderInfo.Id,
PayCallback: string(body),
PayCallback: "",
Status: 0,
MerchantParam: "",
MerchantCallback: "",

View File

@ -4,7 +4,7 @@ const (
TOKEN_PRE = "player_token_"
TOKEN_Admin = "Admin_token_"
ADMIN_V1 = "/pay/admin/api/v1"
FRONT_V1 = "/pay/front/api/v1"
FRONT_V1 = "/api/v1"
// 支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
PAY_CHANNEL_UNKNOWN = 0
@ -28,7 +28,4 @@ const (
ORDER_STATUS_PAYED = 3
ORDER_STATUS_FAILED = 4
ORDER_STATUS_CLOSE = 5
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝
)

View File

@ -57,7 +57,6 @@ var MsgZH = map[int]string{
AppNotFound: "app_id未找到",
AppDisabled: "app通道关闭",
AppIpNotAllow: "ip不在白名单内",
SystemError: "系统错误",
PayChannelNotFound: "支付方式不存在",
}
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}

View File

@ -46,8 +46,8 @@ func (m *OrderRepo) OrdersBackendList(conn builder.Cond, pageFilter entities.Pag
}
repo = repo.Join("left", "app", "app.id = orders.app_id").
Join("left", "merchant", "merchant.id = orders.merchant_id").
Join("left", "pay_channel", "pay_channel.id = orders.pay_channel_id")
return repo.Desc("orders.create_time").FindAndCount(orderList)
Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
return repo.Desc("create_time").FindAndCount(orderList)
}
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 {
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)
}

View File

@ -14,9 +14,9 @@ import (
type OrderListRequest struct {
Id int64 `json:"id" form:"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"`
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"`
OrderType int `json:"order_type" form:"order_type"`
StartTime string `json:"start_time" form:"start_time"`
@ -26,9 +26,9 @@ type OrderListRequest struct {
type OrderList struct {
Id int64 `json:"id"`
MerchantId int64 `json:"merchant_id"`
PayChannelId int64 `json:"pay_channel_id"`
PayId int64 `json:"pay_id"`
AppId int64 `json:"app_id"`
OutTreadNo string `json:"out_tread_no"`
MerchantOrderId string `json:"merchant_order_id"`
Status int `json:"status"`
OrderType int `json:"order_type"`
StartTime time.Time `json:"start_time"`
@ -54,9 +54,9 @@ func (o *OrderListRequest) ValidateRequest() (r OrderList, err error) {
r.Id = o.Id
r.MerchantId = o.MerchantId
r.PayChannelId = o.PayChannelId
r.PayId = o.PayId
r.AppId = o.AppId
r.OutTreadNo = o.OutTreadNo
r.MerchantOrderId = o.MerchantOrderId
r.Status = o.Status
r.OrderType = o.OrderType
r.PageRequest = o.PageRequest
@ -73,6 +73,10 @@ type OrdersResponse struct {
Status int `json:"status"`
OrderType int `json:"order_type"`
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"`
CreateTime string `json:"create_time"`
UpdateTime string `json:"update_time"`

View File

@ -17,7 +17,7 @@ type PayChannelResponse struct {
AppId string `json:"app_id"`
ExpireTime string `json:"expire_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"`
}
@ -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:
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
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微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
AppId string `json:"app_id" validate:"required" label:"应用appId"`
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"`
}
@ -55,7 +55,7 @@ type WechatPayChannel struct {
PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容
}
type AliPayChannel struct {
type AliPayPayChannel struct {
PrivateKey string `json:"private_key"` // 应用私钥
AppPublicCert string `json:"app_public_cert"` // 应用公钥
AlipayRootCert string `json:"alipay_root_cert"` // 支付宝根证书
@ -78,7 +78,7 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
b, _ := json.Marshal(p.WechatPayChannel)
db.ExtJson = string(b)
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)
default:
err = errors.New("支付渠道类型错误")
@ -98,7 +98,7 @@ type PayChannelUpdateRequest struct {
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
AppId string `json:"app_id" validate:"required" label:"应用appId"`
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"`
}
@ -118,7 +118,7 @@ func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, e
b, _ := json.Marshal(p.WechatPayChannel)
db.ExtJson = string(b)
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)
default:
err = errors.New("支付渠道类型错误")

View File

@ -4,7 +4,6 @@ package routes
* 配置路由
*/
import (
"PaymentCenter/app/constants/common"
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/controllers/backend"
"PaymentCenter/app/http/controllers/front"
@ -48,7 +47,7 @@ func RegisterRoute(router *gin.Engine) {
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
v1 := router.Group(common.FRONT_V1)
v1 := router.Group("/v1")
{
//回调处理
notify := v1.Group("/notify")

View File

@ -21,14 +21,14 @@ func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, t
if req.MerchantId > 0 {
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
}
if req.PayChannelId > 0 {
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
if req.PayId > 0 {
conn = conn.And(builder.Eq{"pay_id": req.PayId})
}
if req.AppId > 0 {
conn = conn.And(builder.Eq{"app_id": req.AppId})
}
if req.OutTreadNo != "" {
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
if req.MerchantOrderId != "" {
conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId})
}
if req.Status > 0 {
conn = conn.And(builder.Eq{"status": req.Status})

View File

@ -2,7 +2,6 @@ package paymentService
import (
"PaymentCenter/app/third/paymentService/payCommon"
"PaymentCenter/config"
"context"
"errors"
"fmt"
@ -21,13 +20,12 @@ var (
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
func AliInitClient(aliConfig AliPay) {
envConfig := config.GetConf()
aliOnce.Do(func() {
// 初始化支付宝客户端
// appid应用ID
// privateKey应用私钥支持PKCS1和PKCS8
// isProd是否是正式环境沙箱环境请选择新版沙箱应用。
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, envConfig.PayService.IsProd)
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
})
// 自定义配置http请求接收返回结果body大小默认 10MB
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
@ -74,12 +72,12 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
// 初始化 BodyMap
amount := float64(payOrderRequest.Amount) / 100.0
envConfig := config.GetConf()
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", payOrderRequest.OrderId).
Set("total_amount", amount).
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)
if err != nil {

View File

@ -1,8 +1,8 @@
package payCommon
import "PaymentCenter/app/constants/common"
const (
TEST_URL = ""
PROD_URL = ""
// 支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
PAY_CHANNEL_UNKNOWN = 0
@ -21,10 +21,10 @@ const (
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
WX_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
WX_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
ALI_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
ALI_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
WX_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/wx/" // 微信支付回调地址
WX_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/wx/" // 微信支付回调地址
ALI_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/ali/" // 支付宝支付回调地址
ALI_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/ali/" // 支付宝支付回调地址
ORDER_NO_TYPE_ORDER_NO = 2

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,6 @@ package paymentService
import (
"PaymentCenter/app/third/paymentService/payCommon"
"PaymentCenter/config"
"context"
"errors"
"fmt"
@ -68,14 +67,14 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er
}
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
// 初始化 BodyMap
envConfig := config.GetConf()
bm := make(gopay.BodyMap)
bm.Set("appid", payOrderRequest.Wx.AppId).
Set("mchid", payOrderRequest.Wx.MchId).
Set("description", payOrderRequest.Description).
Set("out_trade_no", payOrderRequest.OrderId).
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) {
bm.Set("total", payOrderRequest.Amount).
Set("currency", "CNY")

View File

@ -450,15 +450,3 @@ func SliceInStr(s string, slice []string) bool {
}
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
}
}

View File

@ -39,7 +39,6 @@ type Config struct {
AliOss AliOss `toml:"AliOss"`
AdminGate []string `toml:"AdminGate"`
CronConfig CronConfig `toml:"CronConfig"`
PayService PayService `toml:"PayService"`
}
type AliOss struct {
@ -92,11 +91,6 @@ type CronConfig struct {
ConcurrentNumber int `toml:"ConcurrentNumber"`
}
type PayService struct {
Host string `toml:"TestHost"`
IsProd bool `toml:"IsProd"`
}
func newConfig() *Config {
return new(Config)
}