From 4c698967d0199bd5c1000fe93a964caaafe0648f Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Dec 2019 16:29:15 +0800 Subject: [PATCH] wxpay to wxpayapi --- business/partner/purchase/jx/localjx/wxpay.go | 34 +++++++++---------- controllers/wxpay_callback.go | 10 +++--- globals/api/api.go | 8 ++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/business/partner/purchase/jx/localjx/wxpay.go b/business/partner/purchase/jx/localjx/wxpay.go index 36ac8627e..453533def 100644 --- a/business/partner/purchase/jx/localjx/wxpay.go +++ b/business/partner/purchase/jx/localjx/wxpay.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -25,7 +25,7 @@ func getOrderBrief(order *model.GoodsOrder) string { func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) { payCreatedAt := time.Now() - param := &wxpay.CreateOrderParam{ + param := &wxpayapi.CreateOrderParam{ OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)), Body: getOrderBrief(order), NotifyURL: globals.WxpayNotifyURL, @@ -33,8 +33,8 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp TradeType: vendorPayType2WxpayType(vendorPayType), TotalFee: int(order.ActualPayPrice), - TimeStart: wxpay.Time2PayTime(payCreatedAt), - // TimeExpire: wxpay.Time2PayTime(payCreatedAt.Add(PayWaitingTime)), + TimeStart: wxpayapi.Time2PayTime(payCreatedAt), + // TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)), } if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini { param.OpenID = authInfo.GetAuthID() @@ -58,18 +58,18 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp return orderPay, err } -func OnWxPayCallback(msg *wxpay.CallbackMsg) (err error) { +func OnWxPayCallback(msg *wxpayapi.CallbackMsg) (err error) { globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true)) switch msg.MsgType { - case wxpay.MsgTypePay: - err = onWxpayFinished(msg.Data.(*wxpay.PayResultMsg)) - case wxpay.MsgTypeRefund: - err = onWxpayRefund(msg.Data.(*wxpay.RefundResultMsg)) + case wxpayapi.MsgTypePay: + err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg)) + case wxpayapi.MsgTypeRefund: + err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg)) } return err } -func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { +func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) { orderPay := &model.OrderPay{ PayOrderID: msg.OutTradeNo, PayType: model.PayTypeWX, @@ -77,16 +77,16 @@ func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { orderPay.DeletedAt = utils.DefaultTimeValue db := dao.GetDB() if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil { - orderPay.PayFinishedAt = utils.Time2Pointer(wxpay.PayTime2Time(msg.TimeEnd)) + orderPay.PayFinishedAt = utils.Time2Pointer(wxpayapi.PayTime2Time(msg.TimeEnd)) orderPay.TransactionID = msg.TransactionID orderPay.OriginalData = utils.Format4Output(msg, true) - if msg.ResultCode == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { orderPay.Status = model.PayStatusYes } else { orderPay.Status = model.PayStatusFailed } dao.UpdateEntity(db, orderPay) - if msg.ResultCode == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { err = OnPayFinished(orderPay) } } else { @@ -95,13 +95,13 @@ func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { return err } -func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) { +func onWxpayRefund(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 == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { orderPayRefund.Status = model.RefundStatusYes } else { orderPayRefund.Status = model.RefundStatusFailed @@ -127,13 +127,13 @@ func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) { } func refundOrderByWX(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) { - result, err := api.WxpayAPI.PayRefund(&wxpay.PayRefundParam{ + result, err := api.WxpayAPI.PayRefund(&wxpayapi.PayRefundParam{ OutTradeNo: orderPay.VendorOrderID, NotifyURL: globals.WxpayNotifyURL, OutRefundNo: refundID, TotalFee: orderPay.TotalFee, RefundFee: refundFee, - RefundDesc: wxpay.CData(refundDesc), + RefundDesc: wxpayapi.CData(refundDesc), }) if err == nil { orderPayRefund = &model.OrderPayRefund{ diff --git a/controllers/wxpay_callback.go b/controllers/wxpay_callback.go index 2d6d89e7d..4da448b20 100644 --- a/controllers/wxpay_callback.go +++ b/controllers/wxpay_callback.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" "git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -17,19 +17,19 @@ type WXPayController struct { func (c *WXPayController) Msg() { if c.Ctx.Input.Method() == http.MethodPost { msg, callbackResponse := api.WxpayAPI.GetCallbackMsg(c.Ctx.Request) - // globals.SugarLogger.Debugf("wxpay callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil) + // globals.SugarLogger.Debugf("wxpayapi callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil) var err error if callbackResponse == nil { - if msg.MsgType == wxpay.MsgTypeUnkown { + if msg.MsgType == wxpayapi.MsgTypeUnkown { err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType) } else { err = localjx.OnWxPayCallback(msg) } } if callbackResponse == nil { - callbackResponse = wxpay.SuccessResponse + callbackResponse = wxpayapi.SuccessResponse } else if err != nil { - callbackResponse = wxpay.Err2CallbackResponse(err, "") + callbackResponse = wxpayapi.Err2CallbackResponse(err, "") } c.Data["xml"] = callbackResponse c.ServeXML() diff --git a/globals/api/api.go b/globals/api/api.go index 9ab7e5b4c..8e180df56 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -19,7 +19,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/showapi" "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/platformapi/weixinapi" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" "git.rosy.net.cn/baseapi/platformapi/xiaowmapi" "git.rosy.net.cn/baseapi/platformapi/yilianyunapi" "git.rosy.net.cn/baseapi/platformapi/zhongwuapi" @@ -46,7 +46,7 @@ var ( WeixinMiniAPI *weixinapi.API // 小程序 WeixinMiniAPI2 *weixinapi.API // 小程序2 WeixinMiniAppID2 string - WxpayAPI *wxpay.API // 微信支付API + WxpayAPI *wxpayapi.API // 微信支付API WeixinPageAPI *weixinapi.API // 用户微信扫码登录 @@ -152,8 +152,8 @@ func Init() { } WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret")) if globals.WxpayNotifyURL != "" { - // WxpayAPI = wxpay.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID")) - WxpayAPI = wxpay.NewWithCertificate(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"), + // WxpayAPI = wxpayapi.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID")) + WxpayAPI = wxpayapi.NewWithCertificate(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"), "conf/apiclient_cert.pem", "conf/apiclient_key.pem") } AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey"))