wxpay to wxpayapi
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user