|
|
@@ -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 |
|
|
|
} |
|
|
|
|
|
|
|