diff --git a/business/auth2/authprovider/douyin/tiktop_mini.go b/business/auth2/authprovider/douyin/tiktop_mini.go index 0be0039ab..bc75903b9 100644 --- a/business/auth2/authprovider/douyin/tiktop_mini.go +++ b/business/auth2/authprovider/douyin/tiktop_mini.go @@ -31,7 +31,7 @@ func init() { func (a *TiktopMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) { globals.SugarLogger.Debugf("toktok mini VerifySecret jsCode:%s", code) - sessionInfo, err := api.TiktokApi.GetTiktokToken2(code) + sessionInfo, err := api.TiktokApi.GetTiktokOauth(code) if err == nil { sessionKey := sessionInfo.Data.SessionKey sessionInfo.Data.SessionKey = "" diff --git a/business/model/order.go b/business/model/order.go index d7a784c81..5dce03772 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -13,6 +13,7 @@ const ( const ( PayTypeWX = 1 // 微信支付 PayTypeTL = 2 // 通联宝支付 + PayTypeTicTok = 3 // 抖音支付 PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡) PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 84da7c777..70b09e180 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -329,6 +329,11 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } + case model.PayTypeTicTok: + if orderPay, err = pay4OrderByTT(ctx, order, vendorPayType); err == nil && orderPay != nil { + dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) + err = dao.CreateEntity(dao.GetDB(), orderPay) + } default: err = fmt.Errorf("支付方式:%d当前不支持", payType) } diff --git a/business/partner/purchase/jx/localjx/tiktokPay.go b/business/partner/purchase/jx/localjx/tiktokPay.go new file mode 100644 index 000000000..20dc4dba4 --- /dev/null +++ b/business/partner/purchase/jx/localjx/tiktokPay.go @@ -0,0 +1,143 @@ +package localjx + +import ( + "fmt" + "git.rosy.net.cn/baseapi/platformapi/tiktok" + "time" + + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/globals/api" +) + +func getOrderBriefTt(order *model.GoodsOrder) string { + return fmt.Sprintf("%s等共%d件商品", order.Skus[0].SkuName, order.GoodsCount) +} + +func pay4OrderByTT(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) { + param := &tiktok.TickTokCreateOrder{ + AppID: api.TiktokApi.GetAppID(), + OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), + TotalAmount: int(order.ActualPayPrice), + Subject: "蔬菜/水果/日用品", + Body: getOrderBriefTt(order), + ValidTime: 600, + CpExtra: "msg", + NotifyURL: globals.TictokpayNotifyURL, + } + + ttOrderId, orderToken, err := api.TiktokApi.CreateOrderByTicktock(param) + if err == nil { + orderPay = &model.OrderPay{ + PayOrderID: ttOrderId, // 抖音订单id + PayType: model.PayTypeTicTok, + VendorPayType: vendorPayType, + + VendorOrderID: order.VendorOrderID, + VendorID: order.VendorID, + Status: 0, + PayCreatedAt: time.Now(), + PrepayID: "", + CodeURL: orderToken, // 抖音支付token + TotalFee: int(order.ActualPayPrice), + } + } + return orderPay, err +} + +func OnTTPayCallback(msg *wxpayapi.CallbackMsg) (err error) { + globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true)) + switch msg.MsgType { + case wxpayapi.MsgTypePay: + err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg)) + case wxpayapi.MsgTypeRefund: + err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg)) + } + return err +} + +func onTTPayFinished(msg *wxpayapi.PayResultMsg) (err error) { + orderPay := &model.OrderPay{ + PayOrderID: msg.OutTradeNo, + PayType: model.PayTypeWX, + } + orderPay.DeletedAt = utils.DefaultTimeValue + db := dao.GetDB() + if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil { + orderPay.PayFinishedAt = utils.Time2Pointer(wxpayapi.PayTime2Time(msg.TimeEnd)) + orderPay.TransactionID = msg.TransactionID + orderPay.OriginalData = utils.Format4Output(msg, true) + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { + orderPay.Status = model.PayStatusYes + } else { + orderPay.Status = model.PayStatusFailed + } + dao.UpdateEntity(db, orderPay) + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { + err = OnPayFinished(orderPay) + } + } else { + globals.SugarLogger.Debugf("onWxpayFinished msg:%s, err:%v", utils.Format4Output(msg, true), err) + } + return err +} + +func onTTPayRefund(msg *wxpayapi.RefundResultMsg) (err error) { + orderPayRefund := &model.OrderPayRefund{ + RefundID: msg.ReqInfoObj.OutRefundNo, + } + db := dao.GetDB() + if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { + orderPayRefund.Status = model.RefundStatusYes + } else { + orderPayRefund.Status = model.RefundStatusFailed + } + orderPayRefund.OriginalData = utils.Format4Output(msg, true) + dao.UpdateEntity(db, orderPayRefund) + } else if dao.IsNoRowsError(err) { + globals.SugarLogger.Warnf("收到异常的退款事件, msg:%s", utils.Format4Output(msg, true)) + } + + orderPay := &model.OrderPay{ + VendorOrderID: orderPayRefund.VendorOrderID, + VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(orderPayRefund.VendorOrderID), + PayType: model.PayTypeWX, + Status: model.PayStatusYes, + } + orderPay.DeletedAt = utils.DefaultTimeValue + if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "Status", "DeletedAt"); err == nil { + orderPay.Status = model.PayStatusRefund + dao.UpdateEntity(db, orderPay) + } + return err +} + +func refundOrderByTT(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) { + result, err := api.WxpayAPI.PayRefund(&wxpayapi.PayRefundParam{ + OutTradeNo: orderPay.VendorOrderID, + NotifyURL: globals.WxpayNotifyURL, + OutRefundNo: refundID, + TotalFee: orderPay.TotalFee, + RefundFee: refundFee, + RefundDesc: wxpayapi.CData(refundDesc), + }) + if err == nil { + orderPayRefund = &model.OrderPayRefund{ + RefundID: refundID, + VendorRefundID: result.RefundID, + VendorOrderID: orderPay.VendorOrderID, + VendorID: orderPay.VendorID, + Status: model.RefundStatusNo, + TransactionID: orderPay.TransactionID, + RefundFee: orderPay.TotalFee, + RefundCreatedAt: time.Now(), + } + } + return orderPayRefund, err +} diff --git a/conf/app.conf b/conf/app.conf index 3d58af18a..5224e90b8 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -68,6 +68,9 @@ wxpayAppKey = "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD" wxpayAppMchID = "1390686702" wxpayNotifyURL = "http://callback.test.jxc4.com/wxpay/msg/" +# 抖音支付回调地址 +tiktokNotifyUrl = "http://callback.test.jxc4.com/ttpay/msg/" + qywxID = "ww9a156bfa070e1857" qywxSecret = "q6H6WFV-c7gyyfBaxLxilIzeJv_mGk1CXtPqUR5qm4E" @@ -283,6 +286,9 @@ aliUpcAppCode = "00a6eefba0204d3fa310ac0ee7a6fc54" wxpayNotifyURL = "http://callback.jxc4.com/wxpay/msg/" +# 抖音支付回调地址 +tiktokNotifyUrl = "http://callback.test.jxc4.com/ttpay/msg/" + tonglianPayAppID = "00183083" tonglianPayKey = "18048531223" tonglianPayCusID = "56065105499TVAH" @@ -379,6 +385,9 @@ weixinAppSecretPrint = "ff4128908947cfb71002f74599c0dbf9" wxpayNotifyURL = "http://callback-jxgy.jxc4.com/wxpay/msg/" +# 抖音支付回调地址 +tiktokNotifyUrl = "http://callback.test.jxc4.com/ttpay/msg/" + tonglianPayAppID = "00183083" tonglianPayKey = "18048531223" tonglianPayCusID = "56065105499TVAH" @@ -564,6 +573,9 @@ aliUpcAppCode = "00a6eefba0204d3fa310ac0ee7a6fc54" wxpayNotifyURL = "http://callback.beta.jxc4.com/wxpay/msg/" +# 抖音支付回调地址 +tiktokNotifyUrl = "http://callback.test.jxc4.com/ttpay/msg/" + tonglianPayAppID = "00183083" tonglianPayKey = "18048531223" tonglianPayCusID = "56065105499TVAH" diff --git a/globals/globals.go b/globals/globals.go index 6914e1405..c8da93ebf 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -61,9 +61,10 @@ var ( EnableWXAuth2 bool DisableWXAuth1 bool - WxpayNotifyURL string - TLPayNotifyURL string - FnNotifyURL string + WxpayNotifyURL string + TLPayNotifyURL string + FnNotifyURL string + TictokpayNotifyURL string JdOrgCode string Jd2OrgCode string @@ -158,6 +159,8 @@ func Init() { JdydOrgCode = web.AppConfig.DefaultString("jdydOrgCode", "") JdLoginName = web.AppConfig.DefaultString("jdLoginName", "") IsAddEvent = web.AppConfig.DefaultBool("addEvent", false) + TictokpayNotifyURL = web.AppConfig.DefaultString("tiktokNotifyUrl", "") + IsStoreSkuAct = !IsProductEnv() MtwmCode = web.AppConfig.DefaultString("mtwmAppID", "")