通联宝支付测试
This commit is contained in:
@@ -12,29 +12,17 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"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"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||||
payCreatedAt := time.Now()
|
payCreatedAt := time.Now()
|
||||||
// param := &wxpayapi.CreateOrderParam{
|
|
||||||
// OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)),
|
|
||||||
// Body: getOrderBrief(order),
|
|
||||||
// NotifyURL: globals.TLPayNotifyURL,
|
|
||||||
// SpbillCreateIP: ctx.GetRealRemoteIP(),
|
|
||||||
// TradeType: vendorPayType2WxpayType(vendorPayType),
|
|
||||||
// TotalFee: int(order.ActualPayPrice),
|
|
||||||
|
|
||||||
// TimeStart: wxpayapi.Time2PayTime(payCreatedAt),
|
|
||||||
// // TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)),
|
|
||||||
// ProfitSharing: wxpayapi.OptYes,
|
|
||||||
// }
|
|
||||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||||
Trxamt: int(order.ActualPayPrice),
|
Trxamt: int(order.ActualPayPrice),
|
||||||
NotifyUrl: globals.TLPayNotifyURL,
|
NotifyUrl: globals.TLPayNotifyURL,
|
||||||
@@ -61,10 +49,11 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
|
|||||||
CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
|
CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
|
||||||
TotalFee: int(order.ActualPayPrice),
|
TotalFee: int(order.ActualPayPrice),
|
||||||
}
|
}
|
||||||
plainText, err := RSADecrypt([]byte(result2.PaySign))
|
plainText, err2 := RSADecrypt([]byte(result2.PaySign))
|
||||||
result2.PaySign = string(plainText)
|
result2.PaySign = string(plainText)
|
||||||
str, err := json.Marshal(result2)
|
str, err2 := json.Marshal(result2)
|
||||||
result.PayInfo = string(str)
|
result.PayInfo = string(str)
|
||||||
|
err = err2
|
||||||
}
|
}
|
||||||
return orderPay, err
|
return orderPay, err
|
||||||
}
|
}
|
||||||
@@ -92,13 +81,70 @@ func RSADecrypt(pub []byte) (plainText []byte, err error) {
|
|||||||
return plainText, err
|
return plainText, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnTLPayCallback(msg *wxpayapi.CallbackMsg) (err error) {
|
func OnTLPayCallback(call *tonglianpayapi.CallBackResult) (err error) {
|
||||||
globals.SugarLogger.Debugf("OnTLPayCallback msg:%s", utils.Format4Output(msg, true))
|
globals.SugarLogger.Debugf("OnTLPayCallback msg:%s", utils.Format4Output(call, true))
|
||||||
switch msg.MsgType {
|
switch call.TrxCode {
|
||||||
case wxpayapi.MsgTypePay:
|
case tonglianpayapi.MsgTypePay:
|
||||||
err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
|
err = onTLpayFinished(call)
|
||||||
case wxpayapi.MsgTypeRefund:
|
case tonglianpayapi.MsgTypeRefund:
|
||||||
err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
|
err = onTLpayRefund(call)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||||
|
orderPay := &model.OrderPay{
|
||||||
|
PayOrderID: call.CusorderID,
|
||||||
|
PayType: model.PayTypeTL,
|
||||||
|
}
|
||||||
|
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||||
|
db := dao.GetDB()
|
||||||
|
if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil {
|
||||||
|
orderPay.PayFinishedAt = utils.Time2Pointer(utils.Str2Time(call.PayTime))
|
||||||
|
orderPay.TransactionID = call.ChnlTrxID
|
||||||
|
orderPay.OriginalData = utils.Format4Output(call, true)
|
||||||
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
|
orderPay.Status = model.PayStatusYes
|
||||||
|
} else {
|
||||||
|
orderPay.Status = model.PayStatusFailed
|
||||||
|
}
|
||||||
|
dao.UpdateEntity(db, orderPay)
|
||||||
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
|
err = OnPayFinished(orderPay)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func onTLpayRefund(call *tonglianpayapi.CallBackResult) (err error) {
|
||||||
|
// orderPayRefund := &model.OrderPayRefund{
|
||||||
|
// RefundID: call.CusorderID,
|
||||||
|
// }
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ wxpayNotifyURL = "http://callback.test.jxc4.com/wxpay/msg/"
|
|||||||
tonglianPayAppID = "00183083"
|
tonglianPayAppID = "00183083"
|
||||||
tonglianPayKey = "18048531223"
|
tonglianPayKey = "18048531223"
|
||||||
tonglianPayCusID = "56065105499TVAH"
|
tonglianPayCusID = "56065105499TVAH"
|
||||||
tonglianPayNotifyURL = "http://callback.test.jxc4.com/tonglian/msg/"
|
tonglianPayNotifyURL = "http://callback.jxc4.com/tonglian/msg/"
|
||||||
|
|
||||||
backstageHost = "http://www.jxc4.com"
|
backstageHost = "http://www.jxc4.com"
|
||||||
wxBackstageHost = "http://wx.jxc4.com"
|
wxBackstageHost = "http://wx.jxc4.com"
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,23 +18,13 @@ type TongLianController struct {
|
|||||||
|
|
||||||
func (c *TongLianController) Msg() {
|
func (c *TongLianController) Msg() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
// msg, callbackResponse := api.TLpayAPI.GetCallbackMsg(c.Ctx.Request)
|
call, err := api.TLpayAPI.GetCallbackMsg(c.Ctx.Request)
|
||||||
// globals.SugarLogger.Debugf("tonglianapi callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil)
|
globals.SugarLogger.Debugf("tonglianapi callback callbackResponse:%s", utils.Format4Output(call, true))
|
||||||
// var err error
|
if err == nil {
|
||||||
// if callbackResponse == nil {
|
err = localjx.OnTLPayCallback(call)
|
||||||
// if msg.MsgType == wxpayapi.MsgTypeUnkown {
|
}
|
||||||
// err = fmt.Errorf("未知的通联宝支付回调类型:%d", msg.MsgType)
|
c.Data["json"] = call
|
||||||
// } else {
|
c.ServeJSON()
|
||||||
// err = localjx.OnTLPayCallback(msg)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if callbackResponse == nil {
|
|
||||||
// callbackResponse = wxpayapi.SuccessResponse
|
|
||||||
// } else if err != nil {
|
|
||||||
// callbackResponse = wxpayapi.Err2CallbackResponse(err, "")
|
|
||||||
// }
|
|
||||||
// c.Data["json"] = callbackResponse
|
|
||||||
// c.ServeJSON()
|
|
||||||
} else {
|
} else {
|
||||||
c.Abort("404")
|
c.Abort("404")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user