feat: 继续添加充值卡充值回调

This commit is contained in:
danial
2024-09-03 21:52:44 +08:00
parent 75700be890
commit e2a6db824f
29 changed files with 156 additions and 117 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/.idea/
/.vscode/
/main.exe
/logs/

View File

@@ -1,10 +1,9 @@
appname = jhgateway
HTTPAddr = localhost
httpport = 12309
RemoteAddr = localhost
RemoteAddr = 0.0.0.0
RemotePort = 12309
runmode = dev
HTTPAddr = localhost
runmode = prod
HTTPAddr = 0.0.0.0
sessionon = true
copyrequestbody = true
@@ -22,14 +21,14 @@ separate="["emergency","alert","critical","error","warning","notice","info","deb
maxdays=10
[mysql]
dbhost = localhost
dbhost = mysql
dbport = 3306
dbuser = root
dbpasswd = 123456
dbbase = juhe_pay
dbbase = kami
[mq]
host = 127.0.0.1
host = rabbitmq
port = 61613
[mf]
@@ -42,6 +41,13 @@ query_card_url = http://test.shop.center.mf178.cn/userapi/card/order_info
key = BjI@3@N5XeU7kLP5$MppMobz$3ljek7d
[appleCard]
submit_card_url=http://test.shop.center.mf178.cn/userapi/card/submit_card
; 提交卡密接口
submit_card_url = http://kami_backend:12401/api/cardInfo/appleCard/submit
; url = https://shop.task.mf178.cn/userapi/card/submit_card
query_card_url = http://kami_backend:12401/api/cardInfo/appleCard/query
notify_url = http://kami_gateway:12309/appleCard/notify
[tMallGame]
submit_card_url=http://test.shop.center.mf178.cn/recharge/tMallGame/order/submit
notify_url=http://test.shop.center.mf178.cn/appleCard/notify
query_card_url=http://test.shop.center.mf178.cn/userapi/card/order_info

View File

@@ -4,7 +4,7 @@ ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct CGO_ENABLED=0 GOOS=linux GO
WORKDIR /build
COPY ./ /build/
COPY .. /build/
RUN go mod tidy && go build main.go
@@ -22,10 +22,9 @@ RUN echo "https://mirrors.aliyun.com/alpine/v3.18/main/" > /etc/apk/repositories
COPY --from=builder /build/main /app/
COPY --from=builder /build/conf/ /app/conf/
COPY --from=builder /build/views/ /app/views/
COPY --from=builder /build/static/ /app/static/
COPY --from=builder /build/deploy/wait-for-it.sh /app/
# 启动服务
CMD ["./main"]
CMD ["sh", "wait-for-it.sh", "-p", "mysql:3306", "-p", "rabbitmq:61613", "./main"]
EXPOSE 12309

View File

@@ -0,0 +1,17 @@
services:
gateway_kami:
build:
context: ..
dockerfile: ./deploy/Dockerfile
container_name: kami_gateway
image: kami_gateway:latest
ports:
- "12309:12309"
networks:
- 1panel-network
labels:
createdBy: Developer
networks:
1panel-network:
external: true

View File

@@ -1,5 +1,8 @@
services:
kami_gateway:
build:
context: ..
dockerfile: ./deploy/Dockerfile
container_name: kami_gateway
image: kami_gateway:$VERSION
restart:

52
deploy/wait-for-it.sh Normal file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
set -e
# 初始化变量
hosts=""
# 解析命令行参数
while [ $# -gt 0 ]; do
case $1 in
-p)
shift
if [ -z "$1" ]; then
echo "No host:port provided after -p"
exit 1
fi
hosts="$hosts $1"
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
break
;;
esac
shift
done
# 检查是否提供了主机
if [ -z "$hosts" ]; then
echo "No hosts provided. Exiting."
exit 1
fi
# 等待所有服务变得可用
for host in $hosts; do
addr=$(echo $host | cut -d':' -f1)
port=$(echo $host | cut -d':' -f2)
while ! nc -z "$addr" "$port"; do
echo "Waiting for $addr:$port..." >&2
sleep 1
done
echo "$addr:$port is available!"
done
# 执行最终命令
if [ $# -eq 0 ]; then
echo "No command provided to execute. Exiting."
exit 1
fi
exec "$@"

View File

@@ -1,22 +0,0 @@
version: '3.8'
services:
web:
build:
context: .
container_name: kami_gateway_test
image: kami_gateway_test:0.11
restart:
always
ports:
- "22309:12309"
volumes:
- /data/kami/gateway/conf/:/app/conf/
- /data/kami/gateway/logs/:/app/logs/
networks:
- 1panel-network
labels:
createdBy: Developer
networks:
1panel-network:
external: true

View File

@@ -1,7 +1,7 @@
package gateway
import (
"gateway/internal/response"
"gateway/internal/schema/response"
"gateway/internal/service"
"strings"

View File

@@ -6,7 +6,7 @@ import (
"gateway/internal/models/merchant"
"gateway/internal/models/order"
"gateway/internal/models/response"
"gateway/internal/query"
"gateway/internal/schema/query"
"gateway/internal/service"
"gateway/internal/utils"
"strconv"

View File

@@ -7,8 +7,8 @@ import (
"gateway/internal/models/order"
"gateway/internal/models/payfor"
"gateway/internal/models/road"
"gateway/internal/pay_for"
"gateway/internal/response"
"gateway/internal/schema/response"
pay_for2 "gateway/internal/service/pay_for"
"strings"
"github.com/astaxie/beego/logs"
@@ -41,7 +41,7 @@ func (c *PayForGateway) PayFor() {
payForResponse.ResultCode = "01"
payForResponse.ResultMsg = msg
} else {
payForResponse = pay_for.AutoPayFor(params, config.SELF_API)
payForResponse = pay_for2.AutoPayFor(params, config.SELF_API)
}
c.Data["json"] = payForResponse
_ = c.ServeJSON()
@@ -55,7 +55,7 @@ func (c *PayForGateway) PayForQuery() {
params["merchantOrderId"] = strings.TrimSpace(c.GetString("merchantOrderId"))
params["sign"] = strings.TrimSpace(c.GetString("sign"))
c.Data["json"] = pay_for.PayForResultQuery(params)
c.Data["json"] = pay_for2.PayForResultQuery(params)
_ = c.ServeJSON()
}
@@ -95,9 +95,9 @@ func (c *PayForGateway) SolvePayForResult() {
}
if resultType == config.PAYFOR_FAIL {
pay_for.PayForFail(p)
pay_for2.PayForFail(p)
} else if resultType == config.PAYFOR_SUCCESS {
pay_for.PayForSuccess(p)
pay_for2.PayForSuccess(p)
}
c.Ctx.WriteString(config.SUCCESS)
@@ -117,7 +117,7 @@ func (c *PayForGateway) Balance() {
balanceResponse.ResultMsg = msg
c.Data["json"] = balanceResponse
} else {
c.Data["json"] = pay_for.BalanceQuery(params)
c.Data["json"] = pay_for2.BalanceQuery(params)
}
_ = c.ServeJSON()
}

View File

@@ -12,8 +12,8 @@ import (
"gateway/internal/models/merchant_deploy"
"gateway/internal/models/order"
"gateway/internal/models/road"
"gateway/internal/request"
"gateway/internal/response"
request2 "gateway/internal/schema/request"
response2 "gateway/internal/schema/response"
"gateway/internal/service"
"gateway/internal/utils"
"strconv"
@@ -82,7 +82,6 @@ func (c *ScanController) Scan() {
// 生成订单记录
orderInfo, _, err := service.GenerateRecord(p)
if err != nil {
p.Code = -1
p.Msg = fmt.Sprintf("生成订单失败:%v", err.Error())
c.SolveFailJSON(p)
return
@@ -99,7 +98,7 @@ func (c *ScanController) Scan() {
params["statusCode"] = "00"
sign := utils.GetMD5SignMF(params, p.MerchantInfo.MerchantSecret)
c.Data["json"] = response.ScanSuccessData{
c.Data["json"] = response2.ScanSuccessData{
OrderNo: orderInfo.BankOrderId,
OrderPrice: strconv.FormatFloat(orderInfo.OrderAmount, 'f', 2, 64),
StatusCode: "00",
@@ -118,7 +117,7 @@ func (c *ScanController) Scan() {
service.SolvePayFail(orderInfo.BankOrderId, "")
logs.Error("获取上游渠道失败,请联系客服", supplierCode)
err = errors.New("获取上游渠道失败,请联系客服")
c.Data["json"] = response.CommonErr(-1, err.Error())
c.Data["json"] = response2.CommonErr(-1, err.Error())
_ = c.ServeJSON()
c.StopRun()
return
@@ -141,8 +140,8 @@ func (c *ScanController) Scan() {
}
// SolveFailJSON 处理错误的返回
func (c *ScanController) SolveFailJSON(p *response.PayBaseResp) {
scanFailJSON := new(response.ScanFailData)
func (c *ScanController) SolveFailJSON(p *response2.PayBaseResp) {
scanFailJSON := new(response2.ScanFailData)
scanFailJSON.StatusCode = "01"
scanFailJSON.PayKey = p.Params["payKey"]
scanFailJSON.Msg = p.Msg
@@ -157,32 +156,32 @@ func (c *ScanController) GetAllowedMM() {
showMMValue, err := c.GetFloat("showMMValue")
productCode := strings.TrimSpace(c.GetString("productCode"))
if payKey == "" || showMMValue == 0 || productCode == "" {
res := response.CommonErr(-1, "获取面额失败,参数缺失")
res := response2.CommonErr(-1, "获取面额失败,参数缺失")
c.Data["json"] = res
_ = c.ServeJSON()
return
}
if err != nil {
c.Data["json"] = response.CommonErr(-1, err.Error())
c.Data["json"] = response2.CommonErr(-1, err.Error())
_ = c.ServeJSON()
c.StopRun()
}
merchantInfo, err := service.GetMerchantInfoByPayKey(payKey)
if err != nil || merchantInfo.Id == 0 {
c.Data["json"] = response.CommonErr(-1, "获取面额失败,获取商户信息出错")
c.Data["json"] = response2.CommonErr(-1, "获取面额失败,获取商户信息出错")
_ = c.ServeJSON()
c.StopRun()
}
merchantDeployInfo := service.GerMerchantDeployInfoByUidAndProductCode(merchantInfo.MerchantUid, productCode)
if merchantDeployInfo.Id == 0 {
res := response.CommonErr(-1, "获取面额失败,当前通道不存在")
res := response2.CommonErr(-1, "获取面额失败,当前通道不存在")
c.Data["json"] = res
_ = c.ServeJSON()
return
}
profitMarginList, err := merchantDeployInfo.GetFactMMValue(showMMValue)
if err != nil {
c.Data["json"] = response.CommonErr(-1, err.Error())
c.Data["json"] = response2.CommonErr(-1, err.Error())
_ = c.ServeJSON()
c.StopRun()
}
@@ -209,27 +208,27 @@ func (c *ScanController) GetAllowedMM() {
}
}
logs.Info("转换后的面额数据:%+v", resData)
c.Data["json"] = response.Ok(resData)
c.Data["json"] = response2.Ok(resData)
_ = c.ServeJSON()
}
// CreateOrder 创建订单
func (c *ScanController) CreateOrder() {
createdOrder := request.CreatedOrder{}
createdOrder := request2.CreatedOrder{}
_ = c.BindJSON(&createdOrder)
valid := validation.Validation{}
b, err := valid.Valid(&createdOrder)
if err != nil {
logs.Error("创建订单错误:", err)
res := response.CommonErr(-1, "创建订单错误,参数错误")
res := response2.CommonErr(-1, "创建订单错误,参数错误")
c.Data["json"] = res
_ = c.ServeJSON()
return
}
if !b {
logs.Error("创建订单错误:", valid.Errors)
res := response.CommonErr(-1, "创建订单错误,参数验证错误")
res := response2.CommonErr(-1, "创建订单错误,参数验证错误")
c.Data["json"] = res
_ = c.ServeJSON()
return
@@ -237,13 +236,13 @@ func (c *ScanController) CreateOrder() {
merchantInfo := merchant.GetMerchantByPasskey(createdOrder.PayKey)
if merchantInfo.Id == 0 {
logs.Error("创建订单错误:", err)
res := response.CommonErr(-1, "创建订单错误")
res := response2.CommonErr(-1, "创建订单错误")
c.Data["json"] = res
_ = c.ServeJSON()
return
}
if !utils.Md5MFVerify(createdOrder.ToMap(), merchantInfo.MerchantSecret) {
res := response.CommonErr(-1, "sign验证错误")
res := response2.CommonErr(-1, "sign验证错误")
logs.Error("sign验证错误")
c.Data["json"] = res
_ = c.ServeJSON()
@@ -252,12 +251,14 @@ func (c *ScanController) CreateOrder() {
orderInfo := order.GetOrderByMerchantOrderId(createdOrder.OrderNo)
roadInfo := road.GetRoadInfoByProductCode(createdOrder.ProductCode)
if orderInfo.Id != 0 {
res := response.Ok(struct {
ProductCode string `json:"productCode"`
PaymentName string `json:"paymentName"`
res := response2.Ok(struct {
ProductCode string `json:"productCode"`
PaymentName string `json:"paymentName"`
TransactionType string `json:"TransactionType"`
}{
ProductCode: createdOrder.ProductCode,
PaymentName: roadInfo.PaymentHtml,
ProductCode: createdOrder.ProductCode,
PaymentName: roadInfo.PaymentHtml,
TransactionType: roadInfo.TransactionType,
})
c.Data["json"] = res
_ = c.ServeJSON()
@@ -265,13 +266,13 @@ func (c *ScanController) CreateOrder() {
}
roadInfo, err = service.CreateOrderInfoAndOrderProfitInfo(createdOrder, merchantInfo)
if err != nil {
res := response.CommonErr(-1, err.Error())
res := response2.CommonErr(-1, err.Error())
logs.Info("创建订单错误:", err)
c.Data["json"] = res
_ = c.ServeJSON()
return
}
res := response.Ok(struct {
res := response2.Ok(struct {
ProductCode string `json:"productCode"`
PaymentName string `json:"paymentName"`
TransactionType string `json:"TransactionType"`
@@ -285,11 +286,11 @@ func (c *ScanController) CreateOrder() {
}
func (c *ScanController) QueryAccountInfo() {
accountInfo := request.ThirdPartyAccountInfo{}
accountInfo := request2.ThirdPartyAccountInfo{}
channelName := c.Ctx.Input.Param("channel")
if channelName == "TMallGame" {
_ = c.BindJSON(&accountInfo)
err := t_mall_game.QueryTMallGameAccountInfo(context.Background())
err := t_mall_game.QueryTMallGameAccountInfo(context.Background(), request2.ThirdPartyAccountInfo{})
_ = err
}
return

View File

@@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"gateway/internal/config"
"gateway/internal/request"
"gateway/internal/schema/request"
"github.com/beego/beego/v2/client/httplib"
)

View File

@@ -7,27 +7,25 @@ import (
// 添加新的上游通道时,需要添加这里
var supplierCode2Name = map[string]string{
"KF": "快付支付",
"WEIXIN": "官方微信",
"ALIPAY": "官方支付宝",
"DAILI": "代丽支付",
"MF178": "178卡密",
"APPLE": "苹果itunes充值",
"T_MALL_GAME": "天猫店铺充值",
"MF178": "178卡密",
"APPLE": "苹果itunes充值",
"TMALLGAME": "天猫店铺充值",
}
var registerSupplier = make(map[string]supplier.PayInterface)
// 注册各种上游的支付接口
func init() {
registerSupplier["KF"] = new(KuaiFuImpl)
logs.Notice(CheckSupplierByCode("KF"))
registerSupplier["DAILI"] = new(DaiLiImpl)
logs.Notice(CheckSupplierByCode("DAILI"))
//registerSupplier["KF"] = new(KuaiFuImpl)
//logs.Notice(CheckSupplierByCode("KF"))
//registerSupplier["DAILI"] = new(DaiLiImpl)
//logs.Notice(CheckSupplierByCode("DAILI"))
registerSupplier["APPLE"] = new(AppleCardImpl)
logs.Notice(CheckSupplierByCode("APPLE"))
registerSupplier["MF178"] = new(MFCardV2Impl)
logs.Notice(CheckSupplierByCode("MF178"))
registerSupplier["TMALLGAME"] = new(TMAllGameImpl)
logs.Notice(CheckSupplierByCode("TMALLGAME"))
}
func GetPaySupplierByCode(code string) supplier.PayInterface {

View File

@@ -73,7 +73,7 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
req.Header("tokenFrom", "iframe")
response, err := req.String()
if err != nil {
logs.Error("Apple GetToken 请求失败:", err)
logs.Error("天猫店铺请求失败:", err)
return false, ""
}
logs.Info("远端请求返回数据:" + response)
@@ -109,7 +109,7 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
return false, response
}
func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supplier.ScanData {
func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
var cdata supplier.CardInfo
if roadInfo.TransactionType == string(consts.TransactionTypeRedeem) {
cdata = &supplier.RedeemCardInfo{}

View File

@@ -1,13 +1,3 @@
package agent
/***************************************************
** @Desc : This file for ...
** @Time : 2019/12/17 17:50
** @Author : yuebin
** @File : agent_profit
** @Last Modified by : yuebin
** @Last Modified time: 2019/12/17 17:50
** @Software: GoLand
****************************************************/
type AgentProfit struct{}

View File

@@ -4,17 +4,16 @@ import (
"fmt"
"gateway/internal/models/accounts"
"gateway/internal/models/agent"
merchant2 "gateway/internal/models/merchant"
"gateway/internal/models/merchant"
"gateway/internal/models/merchant_deploy"
"gateway/internal/models/notify"
"gateway/internal/models/order"
"gateway/internal/models/payfor"
"gateway/internal/models/road"
system2 "gateway/internal/models/system"
"gateway/internal/models/system"
"gateway/internal/models/user"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
_ "github.com/go-sql-driver/mysql"
)
@@ -28,19 +27,18 @@ func init() {
link := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&loc=Local&parseTime=true", dbUser, dbPassword, dbHost, dbPort, dbBase)
logs.Info("mysql init.....", link)
_ = orm.RegisterDriver("mysql", orm.DRMySQL)
_ = orm.RegisterDataBase("default", "mysql", link)
orm.RegisterModel(new(user.UserInfo),
new(system2.MenuInfo),
new(system2.SecondMenuInfo),
new(system2.PowerInfo),
new(system2.RoleInfo),
new(system2.BankCardInfo),
new(system.MenuInfo),
new(system.SecondMenuInfo),
new(system.PowerInfo),
new(system.RoleInfo),
new(system.BankCardInfo),
new(road.RoadInfo),
new(road.RoadPoolInfo),
new(agent.AgentInfo),
new(merchant2.MerchantInfo),
new(merchant.MerchantInfo),
new(merchant_deploy.MerchantDeployInfo),
new(accounts.AccountInfo),
new(accounts.AccountHistoryInfoModel),
@@ -48,7 +46,7 @@ func init() {
new(order.OrderProfitInfo),
new(order.OrderSettleInfo),
new(notify.NotifyInfo),
new(merchant2.MerchantLoadInfo),
new(merchant.MerchantLoadInfo),
new(payfor.PayforInfo),
)
}

View File

@@ -7,7 +7,7 @@ import (
"gateway/internal/entities/supplier/third_party"
"gateway/internal/models/payfor"
"gateway/internal/models/road"
"gateway/internal/pay_for"
"gateway/internal/service/pay_for"
"gateway/internal/utils"
"os"
"time"

View File

@@ -6,7 +6,7 @@ import (
"gateway/internal/config"
"gateway/internal/entities/supplier"
"gateway/internal/models/merchant"
"gateway/internal/response"
"gateway/internal/schema/response"
"github.com/beego/beego/v2/core/logs"
"strconv"
)

View File

@@ -12,7 +12,7 @@ import (
"gateway/internal/models/merchant_deploy"
"gateway/internal/models/payfor"
"gateway/internal/models/road"
"gateway/internal/response"
"gateway/internal/schema/response"
"gateway/internal/utils"
"strconv"
"strings"

View File

@@ -9,8 +9,8 @@ import (
"gateway/internal/models/merchant_deploy"
"gateway/internal/models/order"
"gateway/internal/models/road"
"gateway/internal/request"
"gateway/internal/response"
"gateway/internal/schema/request"
"gateway/internal/schema/response"
"gateway/internal/utils"
"strconv"
"time"
@@ -314,22 +314,18 @@ func GenerateRecord(c *response.PayBaseResp) (order.OrderInfo, order.OrderProfit
logs.Info("插入支付订单记录和支付利润记录成功")
return orderInfo, orderProfit, nil
}
if orderInfo.Status != config.Created {
err := errors.New("当前订单已存在,请等待处理结果或手动查询")
return orderInfo, orderProfitInfo, err
}
if !order.InsertOrderExValue(c.Params["orderNo"], c.Params["exValue"]) {
err := errors.New("订单数据插入失败")
return orderInfo, orderProfitInfo, err
}
if !order.InsertPayTime(c.Params["orderNo"]) {
err := errors.New("订单数据插入失败")
return orderInfo, orderProfitInfo, err
}
if !order.SwitchOrderAndOrderProfitStatus(c.Params["orderNo"], config.WAIT) {
err := errors.New("订单状态转换失败")
return orderInfo, orderProfitInfo, err

View File

@@ -5,8 +5,8 @@ import (
"gateway/internal/entities/notify"
_ "gateway/internal/entities/supplier/third_party"
_ "gateway/internal/models"
"gateway/internal/query"
_ "gateway/internal/routers"
query2 "gateway/internal/schema/query"
"gateway/internal/service"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
@@ -19,9 +19,9 @@ func main() {
web.BConfig.WebConfig.Session.SessionOn = true
go notify.CreateOrderNotifyConsumer()
// go pay_for.PayForInit()
go query.CreatePayForQueryConsumer()
go query2.CreatePayForQueryConsumer()
go service.OrderSettleInit()
go query.CreateSupplierOrderQueryCuConsumer()
go query2.CreateSupplierOrderQueryCuConsumer()
web.Run()
}