wxpay to wxpayapi

This commit is contained in:
gazebo
2019-12-19 16:29:15 +08:00
parent 850c35c9d9
commit 4c698967d0
3 changed files with 26 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "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/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" "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) { func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) {
payCreatedAt := time.Now() payCreatedAt := time.Now()
param := &wxpay.CreateOrderParam{ param := &wxpayapi.CreateOrderParam{
OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)), OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)),
Body: getOrderBrief(order), Body: getOrderBrief(order),
NotifyURL: globals.WxpayNotifyURL, NotifyURL: globals.WxpayNotifyURL,
@@ -33,8 +33,8 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
TradeType: vendorPayType2WxpayType(vendorPayType), TradeType: vendorPayType2WxpayType(vendorPayType),
TotalFee: int(order.ActualPayPrice), TotalFee: int(order.ActualPayPrice),
TimeStart: wxpay.Time2PayTime(payCreatedAt), TimeStart: wxpayapi.Time2PayTime(payCreatedAt),
// TimeExpire: wxpay.Time2PayTime(payCreatedAt.Add(PayWaitingTime)), // TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)),
} }
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini { if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
param.OpenID = authInfo.GetAuthID() param.OpenID = authInfo.GetAuthID()
@@ -58,18 +58,18 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
return orderPay, err 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)) globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true))
switch msg.MsgType { switch msg.MsgType {
case wxpay.MsgTypePay: case wxpayapi.MsgTypePay:
err = onWxpayFinished(msg.Data.(*wxpay.PayResultMsg)) err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
case wxpay.MsgTypeRefund: case wxpayapi.MsgTypeRefund:
err = onWxpayRefund(msg.Data.(*wxpay.RefundResultMsg)) err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
} }
return err return err
} }
func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) {
orderPay := &model.OrderPay{ orderPay := &model.OrderPay{
PayOrderID: msg.OutTradeNo, PayOrderID: msg.OutTradeNo,
PayType: model.PayTypeWX, PayType: model.PayTypeWX,
@@ -77,16 +77,16 @@ func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) {
orderPay.DeletedAt = utils.DefaultTimeValue orderPay.DeletedAt = utils.DefaultTimeValue
db := dao.GetDB() db := dao.GetDB()
if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil { 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.TransactionID = msg.TransactionID
orderPay.OriginalData = utils.Format4Output(msg, true) orderPay.OriginalData = utils.Format4Output(msg, true)
if msg.ResultCode == wxpay.ResponseCodeSuccess { if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
orderPay.Status = model.PayStatusYes orderPay.Status = model.PayStatusYes
} else { } else {
orderPay.Status = model.PayStatusFailed orderPay.Status = model.PayStatusFailed
} }
dao.UpdateEntity(db, orderPay) dao.UpdateEntity(db, orderPay)
if msg.ResultCode == wxpay.ResponseCodeSuccess { if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
err = OnPayFinished(orderPay) err = OnPayFinished(orderPay)
} }
} else { } else {
@@ -95,13 +95,13 @@ func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) {
return err return err
} }
func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) { func onWxpayRefund(msg *wxpayapi.RefundResultMsg) (err error) {
orderPayRefund := &model.OrderPayRefund{ orderPayRefund := &model.OrderPayRefund{
RefundID: msg.ReqInfoObj.OutRefundNo, RefundID: msg.ReqInfoObj.OutRefundNo,
} }
db := dao.GetDB() db := dao.GetDB()
if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil { if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
if msg.ResultCode == wxpay.ResponseCodeSuccess { if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
orderPayRefund.Status = model.RefundStatusYes orderPayRefund.Status = model.RefundStatusYes
} else { } else {
orderPayRefund.Status = model.RefundStatusFailed 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) { 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, OutTradeNo: orderPay.VendorOrderID,
NotifyURL: globals.WxpayNotifyURL, NotifyURL: globals.WxpayNotifyURL,
OutRefundNo: refundID, OutRefundNo: refundID,
TotalFee: orderPay.TotalFee, TotalFee: orderPay.TotalFee,
RefundFee: refundFee, RefundFee: refundFee,
RefundDesc: wxpay.CData(refundDesc), RefundDesc: wxpayapi.CData(refundDesc),
}) })
if err == nil { if err == nil {
orderPayRefund = &model.OrderPayRefund{ orderPayRefund = &model.OrderPayRefund{

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"net/http" "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/business/partner/purchase/jx/localjx"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego" "github.com/astaxie/beego"
@@ -17,19 +17,19 @@ type WXPayController struct {
func (c *WXPayController) Msg() { func (c *WXPayController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost { if c.Ctx.Input.Method() == http.MethodPost {
msg, callbackResponse := api.WxpayAPI.GetCallbackMsg(c.Ctx.Request) 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 var err error
if callbackResponse == nil { if callbackResponse == nil {
if msg.MsgType == wxpay.MsgTypeUnkown { if msg.MsgType == wxpayapi.MsgTypeUnkown {
err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType) err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType)
} else { } else {
err = localjx.OnWxPayCallback(msg) err = localjx.OnWxPayCallback(msg)
} }
} }
if callbackResponse == nil { if callbackResponse == nil {
callbackResponse = wxpay.SuccessResponse callbackResponse = wxpayapi.SuccessResponse
} else if err != nil { } else if err != nil {
callbackResponse = wxpay.Err2CallbackResponse(err, "") callbackResponse = wxpayapi.Err2CallbackResponse(err, "")
} }
c.Data["xml"] = callbackResponse c.Data["xml"] = callbackResponse
c.ServeXML() c.ServeXML()

View File

@@ -19,7 +19,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/showapi" "git.rosy.net.cn/baseapi/platformapi/showapi"
"git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/baseapi/platformapi/weixinapi" "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/xiaowmapi"
"git.rosy.net.cn/baseapi/platformapi/yilianyunapi" "git.rosy.net.cn/baseapi/platformapi/yilianyunapi"
"git.rosy.net.cn/baseapi/platformapi/zhongwuapi" "git.rosy.net.cn/baseapi/platformapi/zhongwuapi"
@@ -46,7 +46,7 @@ var (
WeixinMiniAPI *weixinapi.API // 小程序 WeixinMiniAPI *weixinapi.API // 小程序
WeixinMiniAPI2 *weixinapi.API // 小程序2 WeixinMiniAPI2 *weixinapi.API // 小程序2
WeixinMiniAppID2 string WeixinMiniAppID2 string
WxpayAPI *wxpay.API // 微信支付API WxpayAPI *wxpayapi.API // 微信支付API
WeixinPageAPI *weixinapi.API // 用户微信扫码登录 WeixinPageAPI *weixinapi.API // 用户微信扫码登录
@@ -152,8 +152,8 @@ func Init() {
} }
WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret")) WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret"))
if globals.WxpayNotifyURL != "" { if globals.WxpayNotifyURL != "" {
// WxpayAPI = wxpay.New(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 = wxpay.NewWithCertificate(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") "conf/apiclient_cert.pem", "conf/apiclient_key.pem")
} }
AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey")) AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey"))