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