feat: 继续添加充值卡充值回调
This commit is contained in:
26
internal/entities/supplier/third_party/apple.go
vendored
26
internal/entities/supplier/third_party/apple.go
vendored
@@ -65,7 +65,6 @@ func (c *AppleCardImpl) verifyCardNo(cardNo string) bool {
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, string) {
|
||||
|
||||
cfg := config.Config{}
|
||||
params := make(map[string]string)
|
||||
|
||||
@@ -183,8 +182,6 @@ func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) PayNotify() {
|
||||
params := make(map[string]string)
|
||||
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
@@ -205,27 +202,20 @@ func (c *AppleCardImpl) PayNotify() {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
|
||||
params["order_id"] = strings.TrimSpace(c.GetString("order_id"))
|
||||
params["amount"] = strings.TrimSpace(c.GetString("amount")) // 时间戳
|
||||
params["timestamp"] = strings.TrimSpace(c.GetString("timestamp"))
|
||||
params["status"] = strings.TrimSpace(c.GetString("status"))
|
||||
params["sign"] = strings.TrimSpace(c.GetString("sign"))
|
||||
params["remark"] = strings.TrimSpace(c.GetString("remark"))
|
||||
params := map[string]string{
|
||||
"order_id": strings.TrimSpace(c.GetString("order_id")),
|
||||
"amount": strings.TrimSpace(c.GetString("amount")), // 时间戳
|
||||
"timestamp": strings.TrimSpace(c.GetString("timestamp")),
|
||||
"status": strings.TrimSpace(c.GetString("status")),
|
||||
"sign": strings.TrimSpace(c.GetString("sign")),
|
||||
"remark": strings.TrimSpace(c.GetString("remark")),
|
||||
}
|
||||
tmpSign := utils.TmpEncrypt(attach + params["order_id"] + params["timestamp"])
|
||||
if tmpSign != params["sign"] {
|
||||
logs.Error("【APPLE】回调签名错误,签名=", params["sign"], "计算签名=", tmpSign)
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
// 实际支付金额
|
||||
//factAmount, err := strconv.ParseFloat(params["amount"], 64)
|
||||
//if err != nil {
|
||||
// logs.Error("【APPLE】回调金额格式化失败,金额=", params["amount"], c.GetString("amount"))
|
||||
// logs.Error("【APPLE】回调金额格式化失败,金额=", err)
|
||||
// orderInfo.FactAmount = 0
|
||||
//}
|
||||
//orderInfo.FactAmount = factAmount
|
||||
orderInfo.BankTransId = params["order_id"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/consts"
|
||||
"gateway/internal/entities/supplier"
|
||||
@@ -31,56 +27,53 @@ type TMAllGameImpl struct {
|
||||
web.Controller
|
||||
}
|
||||
|
||||
// TMallGameStatus 充值编码
|
||||
type TMallGameStatus int
|
||||
|
||||
const (
|
||||
TMallGameFail TMallGameStatus = 0 // 充值失败
|
||||
TMallGameSuccess TMallGameStatus = 1 // 充值成功
|
||||
)
|
||||
|
||||
func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, orderInfo order.OrderInfo) (bool, string) {
|
||||
appKey := gojson.Json(jsonStr).Get("appKey").Tostring()
|
||||
appSecret := gojson.Json(jsonStr).Get("appSecret").Tostring()
|
||||
goodsSku := gojson.Json(jsonStr).Get("goodsSku").Tostring()
|
||||
if appKey == "" || appSecret == "" {
|
||||
return false, ""
|
||||
if _, ok := cardInfo.(*supplier.RedeemCardInfo); ok {
|
||||
return false, "传输数据格式错误"
|
||||
}
|
||||
cfg := config.Config{}
|
||||
params := map[string]string{
|
||||
"app_key": appKey,
|
||||
"goods_sku": goodsSku,
|
||||
"face_val": cardInfo.GetFaceType(), // 提交面值
|
||||
"callback_url": cfg.GetMfNotifyUrl(), // 回调地址
|
||||
"attach": orderInfo.BankOrderId, // 附带参数
|
||||
"timestamp": strconv.FormatInt(time.Now().Unix(), 10),
|
||||
"third_order_id": orderInfo.BankOrderId,
|
||||
}
|
||||
if redeemCardInfo, ok := cardInfo.(*supplier.RedeemCardInfo); ok {
|
||||
if cardInfo.GetRecoveryType() == "8" {
|
||||
params["card_no"] = redeemCardInfo.CardNo // 卡号
|
||||
}
|
||||
var err error
|
||||
params["card_pwd"], err = c.kMEncrypt(redeemCardInfo.Data, appSecret) // 卡密
|
||||
if err != nil {
|
||||
return false, "加密失败"
|
||||
}
|
||||
}
|
||||
if rechargeCardInfo, ok := cardInfo.(*supplier.RechargeCardInfo); ok {
|
||||
params["accountNumber"] = rechargeCardInfo.AccountNumber // 卡号
|
||||
}
|
||||
sign := utils.GetMD5SignMF(params, appSecret)
|
||||
params["sign"] = sign
|
||||
url, err := cfg.GetMFCardSubmitUrl()
|
||||
var err error
|
||||
|
||||
info := cardInfo.(*supplier.RechargeCardInfo)
|
||||
notifyUrl, err := cfg.GetTMallGameNotifyUrl()
|
||||
if err != nil {
|
||||
return false, ""
|
||||
return false, "获取回调地址失败"
|
||||
}
|
||||
params := map[string]string{
|
||||
"accountNumber": info.AccountNumber,
|
||||
"account": strconv.FormatFloat(orderInfo.OrderAmount, 'f', 2, 64),
|
||||
"merchantOrder": orderInfo.BankOrderId,
|
||||
"callbackUrl": notifyUrl,
|
||||
"timestamp": strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
params["sign"] = utils.TmpEncrypt(params["merchantOrder"] + params["accountNumber"] + params["timestamp"])
|
||||
|
||||
url, err := cfg.GetTMallGameSubmitUrl()
|
||||
if err != nil {
|
||||
return false, "获取天猫充值地址失败!"
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
logs.Error("Apple GetToken 请求失败:", err)
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
@@ -89,28 +82,31 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Stime float64 `json:"stime"`
|
||||
Etime float64 `json:"etime"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
Cards []interface{} `json:"cards"`
|
||||
ErrorData []struct {
|
||||
Msg string `json:"msg"`
|
||||
Data string `json:"data"`
|
||||
} `json:"error_data"`
|
||||
Status TMallGameStatus `json:"status"`
|
||||
Message string `json:"message"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if gojson.Json(response).Get("code").Tostring() != "0" {
|
||||
var resData AutoGenerated
|
||||
_ = json.Unmarshal([]byte(response), &resData)
|
||||
errorMsg := ""
|
||||
if len(resData.Data.ErrorData) > 0 {
|
||||
errorMsg = resData.Data.ErrorData[0].Msg
|
||||
}
|
||||
return false, fmt.Sprintf("错误原因:%s,具体原因:%s", resData.Message, errorMsg)
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
return true, response
|
||||
|
||||
if resData.Code != 0 {
|
||||
logs.Error("充值错误", resData.Message)
|
||||
return false, resData.Message
|
||||
}
|
||||
switch resData.Data.Status {
|
||||
case TMallGameFail:
|
||||
return false, "充值失败"
|
||||
case TMallGameSuccess:
|
||||
return true, "等待兑换"
|
||||
}
|
||||
return false, response
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supplier.ScanData {
|
||||
@@ -154,88 +150,59 @@ func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
|
||||
return scanData
|
||||
}
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *TMAllGameImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
plaintext := utils.PadType(kf)
|
||||
iv := "0102030405060708"
|
||||
mode := cipher.NewCBCEncrypter(block, []byte(iv))
|
||||
mode.CryptBlocks(plaintext, plaintext)
|
||||
return base64.StdEncoding.EncodeToString(plaintext), nil
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) PayNotify() {
|
||||
logs.Info("消息回调成功!!!")
|
||||
params := make(map[string]string)
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(strings.TrimSpace(c.GetString("merchantOrder"))) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【MF178】回调的订单号不存在,订单号=", attach)
|
||||
c.StopRun()
|
||||
logs.Error("【TMALLGAME】回调的订单号不存在,订单号=", strings.TrimSpace(c.GetString("merchantOrder")))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【MF178】支付通道已经关系或者删除,不进行回调")
|
||||
c.StopRun()
|
||||
logs.Error("【TMALLGAME】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
c.StopRun()
|
||||
logs.Error("【TMALLGAME】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
paySecretGroup, err := sonic.GetFromString(roadInfo.Params)
|
||||
if err != nil {
|
||||
logs.Error("获取蜜蜂秘钥失败", merchantUid)
|
||||
c.StopRun()
|
||||
params := map[string]string{
|
||||
"orderId": strings.TrimSpace(c.GetString("orderId")),
|
||||
"merchantOrder": strings.TrimSpace(c.GetString("merchantOrder")),
|
||||
"timestamp": strings.TrimSpace(c.GetString("timestamp")),
|
||||
"status": strings.TrimSpace(c.GetString("status")),
|
||||
"remark": strings.TrimSpace(c.GetString("remark")),
|
||||
"amount": strings.TrimSpace(c.GetString("amount")),
|
||||
"sign": strings.TrimSpace(c.GetString("sign")),
|
||||
}
|
||||
tmpSign := utils.TmpEncrypt(strings.TrimSpace(c.GetString("merchantOrder")) + params["orderId"] + params["timestamp"])
|
||||
if tmpSign != params["sign"] {
|
||||
logs.Error("【TMALLGAME】回调签名错误,签名=", params["sign"], "计算签名=", tmpSign)
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
paySecret, _ := paySecretGroup.Get("appSecret").String()
|
||||
params["order_id"] = strings.TrimSpace(c.GetString("order_id"))
|
||||
params["third_order_id"] = strings.TrimSpace(c.GetString("third_order_id")) // 时间戳
|
||||
params["card_no"] = strings.TrimSpace(c.GetString("card_no")) // 卡号
|
||||
params["card_pwd"] = strings.TrimSpace(c.GetString("card_pwd")) // 时间戳
|
||||
params["face_val"] = strings.TrimSpace(c.GetString("face_val")) // 提交面额
|
||||
params["amount"] = strings.TrimSpace(c.GetString("amount")) // 实际面额
|
||||
params["discount"] = strings.TrimSpace(c.GetString("discount")) // 折扣
|
||||
params["remark"] = strings.TrimSpace(c.GetString("remark")) // 备注
|
||||
params["attach"] = attach // 附加备注
|
||||
params["timestamp"] = strings.TrimSpace(c.GetString("timestamp")) // 时间戳
|
||||
params["status"] = strings.TrimSpace(c.GetString("status")) // 状态
|
||||
// 对参数进行验签
|
||||
tmpSign := utils.GetMD5SignMF(params, paySecret)
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
params["sign"] = sign // 签名
|
||||
if tmpSign != sign {
|
||||
logs.Error("【MF178】回调签名异常,回调失败")
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
// 实际支付金额
|
||||
factAmount, err := strconv.ParseFloat(params["amount"], 64)
|
||||
if err != nil {
|
||||
orderInfo.FactAmount = 0
|
||||
}
|
||||
if params["status"] == "8" { // 失败
|
||||
logs.Info("【MF178】回调失败,订单信息", params)
|
||||
if !service.SolvePayFail(params["order_id"], "") {
|
||||
logs.Error("solve order fail fail")
|
||||
}
|
||||
} else if params["status"] == "9" && factAmount == orderInfo.FactAmount {
|
||||
orderInfo.BankTransId = params["orderId"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
service.SolvePaySuccess(params["order_id"], factAmount, params["order_id"])
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["orderId"])
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(orderInfo.BankOrderId, "")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
}
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
order.InsertCardReturnData(orderInfo.MerchantOrderId, params["remark"])
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
|
||||
@@ -26,4 +26,5 @@ func init() {
|
||||
|
||||
web.Router("/mfcard/notifyV2", &third_party.MFCardV2Impl{}, "*:PayNotify")
|
||||
web.Router("/appleCard/notify", &third_party.AppleCardImpl{}, "*:PayNotify")
|
||||
web.Router("/tMallGame/notify", &third_party.TMAllGameImpl{}, "*:PayNotify")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user