diff --git a/app/customer/hdl/hdl_pay.go b/app/customer/hdl/hdl_pay.go index 0759319..ab9b492 100644 --- a/app/customer/hdl/hdl_pay.go +++ b/app/customer/hdl/hdl_pay.go @@ -9,10 +9,16 @@ import ( "applet/app/db/model" "applet/app/e" "applet/app/enum" + svc3 "applet/app/svc" "applet/app/utils" "encoding/json" "fmt" "github.com/gin-gonic/gin" + "github.com/wechatpay-apiv3/wechatpay-go/core" + "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/jsapi" + jsapi2 "github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi" + utils2 "github.com/wechatpay-apiv3/wechatpay-go/utils" + "strconv" "time" ) @@ -49,15 +55,67 @@ func BuyPackageForWx(c *gin.Context) { return } fmt.Println("req>>>>>>>>>>>>", utils.Serialize(req)) - outTradeNo, resp, total, err := svc.BuyPackageForWx(c, req) + outTradeNo, total, resp, err := svc.BuyPackageForWx(c, req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "out_trade_no": outTradeNo, - "prams": total, - "total": resp, + "prams": resp, + "total": total, + }, nil) + return +} + +func RePayBuyPackageForWx(c *gin.Context) { + prepayId := c.DefaultQuery("prepay_id", "") + centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} + centralKitchenForSchoolPackageOrd.Set("") + ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrdByPrepayId(prepayId) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if ord == nil { + e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") + return + } + + sysCfgDb := db.SysCfgDb{} + sysCfgDb.Set() + client, err := svc3.NewWxPayClient(c) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + wxSvc := jsapi.JsapiApiService{Client: client} + resp := new(jsapi2.PrepayWithRequestPaymentResponse) + sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxAppletAppId) + + resp.PrepayId = &prepayId + resp.SignType = core.String("RSA") + appid := sysCfg[enum.WxAppletAppId] + resp.Appid = &appid + resp.TimeStamp = core.String(strconv.FormatInt(time.Now().Unix(), 10)) + nonce, err := utils2.GenerateNonce() + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + resp.NonceStr = core.String(nonce) + resp.Package = core.String("prepay_id=" + prepayId) + message := fmt.Sprintf("%s\n%s\n%s\n%s\n", *resp.Appid, *resp.TimeStamp, *resp.NonceStr, *resp.Package) + signatureResult, err := wxSvc.Client.Sign(c, message) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + resp.PaySign = core.String(signatureResult.Signature) + e.OutSuc(c, map[string]interface{}{ + //"out_trade_no": ord.OutTradeNo, + "prams": resp, + //"total": ord.TradeNo, }, nil) return } diff --git a/app/db/db_central_kitchen_for_school_package_ord.go b/app/db/db_central_kitchen_for_school_package_ord.go index c056f1d..0fb2148 100644 --- a/app/db/db_central_kitchen_for_school_package_ord.go +++ b/app/db/db_central_kitchen_for_school_package_ord.go @@ -41,6 +41,18 @@ func (centralKitchenForSchoolPackageOrdDb *CentralKitchenForSchoolPackageOrd) Ge return m, nil } +func (centralKitchenForSchoolPackageOrdDb *CentralKitchenForSchoolPackageOrd) GetCentralKitchenForSchoolPackageOrdByPrepayId(prepayId string) (m *model.CentralKitchenForSchoolPackageOrd, err error) { + m = new(model.CentralKitchenForSchoolPackageOrd) + has, err := centralKitchenForSchoolPackageOrdDb.Db.Where("prepay_id =?", prepayId).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + func (centralKitchenForSchoolPackageOrdDb *CentralKitchenForSchoolPackageOrd) CentralKitchenForSchoolPackageOrdInsert(m *model.CentralKitchenForSchoolPackageOrd) (int, error) { _, err := centralKitchenForSchoolPackageOrdDb.Db.InsertOne(m) if err != nil { diff --git a/app/router/customer_router.go b/app/router/customer_router.go index b2da9f7..df9e7fa 100644 --- a/app/router/customer_router.go +++ b/app/router/customer_router.go @@ -68,6 +68,7 @@ func rPay(r *gin.RouterGroup) { r.Use(mw.Auth) //检测登录状态 r.POST("/buyPackage", hdl.BuyPackage) // 购买套餐 r.POST("/buyPackageForWx", hdl.BuyPackageForWx) // 购买套餐(微信) + r.GET("/rePayBuyPackageForWx", hdl.RePayBuyPackageForWx) // 重新支付购买套餐(微信) r.GET("/ordState", hdl.OrdState) // 查看订单支付状态 r.POST("/nursingHomeBuyPackage", hdl.NursingHomeBuyPackage) // 购买套餐 r.GET("/nursingHomeOrdState", hdl.NursingHomeOrdState) // 查看订单支付状态