DengBiao преди 1 година
родител
ревизия
4896534843
променени са 2 файла, в които са добавени 28 реда и са изтрити 5 реда
  1. +2
    -2
      app/customer/hdl/hdl_pay.go
  2. +26
    -3
      app/customer/svc/svc_pay.go

+ 2
- 2
app/customer/hdl/hdl_pay.go Целия файл

@@ -49,14 +49,14 @@ func BuyPackageForWx(c *gin.Context) {
return
}
fmt.Println("req>>>>>>>>>>>>", utils.Serialize(req))
outTradeNo, prepayId, total, err := svc.BuyPackageForWx(c, req)
outTradeNo, resp, total, 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,
"prepay_id": prepayId,
"prams": resp,
"total": total,
}, nil)
return


+ 26
- 3
app/customer/svc/svc_pay.go Целия файл

@@ -15,8 +15,11 @@ import (
"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"
"io/ioutil"
"net/url"
"strconv"
"time"
)

@@ -134,7 +137,7 @@ func BuyPackageForAli(c *gin.Context, req md.BuyPackageReq) (outTradeNo, tradeNo
return
}

func BuyPackageForWx(c *gin.Context, req md.BuyPackageReq) (outTradeNo, prepayId, total string, err error) {
func BuyPackageForWx(c *gin.Context, req md.BuyPackageReq) (outTradeNo, total string, resp *jsapi2.PrepayWithRequestPaymentResponse, err error) {
user := GetUser(c)
session := db.Db.NewSession()
defer session.Close()
@@ -202,7 +205,7 @@ func BuyPackageForWx(c *gin.Context, req md.BuyPackageReq) (outTradeNo, prepayId
wxSvc := jsapi.JsapiApiService{Client: client}
sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxSpAppId, enum2.WxSpMchId, enum2.WxAppletAppId, enum2.WxMchId, enum2.WxJsapiPayNotifyUrl)

resp, _, err := wxSvc.Prepay(c,
result, _, err := wxSvc.Prepay(c,
jsapi.PrepayRequest{
SpAppid: core.String(sysCfg[enum2.WxSpAppId]),
SpMchid: core.String(sysCfg[enum2.WxSpMchId]),
@@ -256,7 +259,27 @@ func BuyPackageForWx(c *gin.Context, req md.BuyPackageReq) (outTradeNo, prepayId
return
}
session.Commit()
prepayId = *resp.PrepayId
//prepayId = *resp.PrepayId
resp = new(jsapi2.PrepayWithRequestPaymentResponse)
resp.PrepayId = result.PrepayId
resp.SignType = core.String("RSA")
appid := sysCfg[enum2.WxSpAppId]
resp.Appid = &appid
resp.TimeStamp = core.String(strconv.FormatInt(time.Now().Unix(), 10))
nonce, err := utils2.GenerateNonce()
if err != nil {
_ = session.Rollback()
return
}
resp.NonceStr = core.String(nonce)
resp.Package = core.String("prepay_id=" + *result.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 {
_ = session.Rollback()
return
}
resp.PaySign = core.String(signatureResult.Signature)
return
}



Зареждане…
Отказ
Запис