sprepurchase
This commit is contained in:
parent
7b13120c48
commit
978cc5fd91
@ -188,6 +188,115 @@ func (this *InGameApi) PayDone(c *gin.Context) {
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *InGameApi) ServerPrePurchase(c *gin.Context) {
|
||||
req := struct {
|
||||
AccountId string `binding:"required" json:"account_id"`
|
||||
SessionId string `binding:"required" json:"session_id"`
|
||||
UserIp string `binding:"required" json:"user_ip"`
|
||||
Sign string `binding:"required" json:"sign"`
|
||||
SigData string `binding:"required" json:"sig_data"`
|
||||
}{}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
f5.RspErr(c, 401, "post content error")
|
||||
return
|
||||
}
|
||||
|
||||
strs := strings.Split(req.AccountId, "_")
|
||||
if len(strs) < 3 {
|
||||
f5.RspErr(c, 401, "params error1")
|
||||
return
|
||||
}
|
||||
|
||||
if !strings.EqualFold(q5.Md5Str(req.AccountId+constant.GLOBAL_SALT+req.SessionId), req.Sign) {
|
||||
f5.RspErr(c, 401, "sign err")
|
||||
return
|
||||
}
|
||||
|
||||
sigdata := map[string]interface{}{}
|
||||
if json.Unmarshal([]byte(req.SigData), &sigdata) != nil {
|
||||
f5.RspErr(c, 401, "sigdata err")
|
||||
return
|
||||
}
|
||||
|
||||
goodsid := q5.SafeToInt32(sigdata["productId"])
|
||||
if goodsid == 0 {
|
||||
f5.RspErr(c, 401, "sigdata productid err")
|
||||
return
|
||||
}
|
||||
|
||||
rediskey := "ls:accountid:" + req.AccountId
|
||||
str, err := service.Redis.Get(constant.LOGIN_REDIS, rediskey)
|
||||
if err != nil {
|
||||
f5.RspErr(c, 402, "invalid session")
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{}
|
||||
if json.Unmarshal([]byte(str), &data) != nil {
|
||||
f5.RspErr(c, 402, "invalid session 1")
|
||||
return
|
||||
}
|
||||
|
||||
sessionkey := q5.SafeToString(data["session_key"])
|
||||
if len(sessionkey) == 0 {
|
||||
f5.GetSysLog().Debug("empty sessionkey:%s", req.AccountId)
|
||||
f5.RspErr(c, 402, "invalid session 2")
|
||||
return
|
||||
}
|
||||
|
||||
sessionkeytime := q5.SafeToInt64(data["update_time"])
|
||||
if service.Wxpay.CheckExpireCache(req.AccountId, sessionkeytime) {
|
||||
f5.RspErr(c, 402, "session expired")
|
||||
return
|
||||
}
|
||||
|
||||
gameid := q5.SafeToInt64(strs[1])
|
||||
|
||||
nowTime := int32(f5.GetApp().GetRealSeconds())
|
||||
order := new(model.InAppOrder)
|
||||
order.AccountId = req.AccountId
|
||||
order.OrderId = q5.ToString(f5.GetApp().NewLockNodeUuid())
|
||||
order.ItemId = goodsid
|
||||
order.IP = req.UserIp
|
||||
|
||||
order.CreateTime = nowTime
|
||||
order.ModifyTime = nowTime
|
||||
|
||||
sigdata["outTradeNo"] = order.OrderId
|
||||
sigdatabyte, _ := json.Marshal(sigdata)
|
||||
fullsigdata := string(sigdatabyte)
|
||||
|
||||
paysig, signature := service.Wxpay.GetPurchaseSig(gameid, fullsigdata, sessionkey)
|
||||
if len(paysig) == 0 || len(signature) == 0 {
|
||||
f5.RspErr(c, 403, "account error")
|
||||
return
|
||||
}
|
||||
|
||||
if err := order.Create(); err != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
|
||||
rspObj := struct {
|
||||
ErrorCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
OrderId string `json:"order_id"`
|
||||
PaySig string `json:"pay_sig"`
|
||||
Signature string `json:"signature"`
|
||||
SigData string `json:"sig_data"`
|
||||
}{
|
||||
0,
|
||||
"",
|
||||
order.OrderId,
|
||||
paysig,
|
||||
signature,
|
||||
fullsigdata,
|
||||
}
|
||||
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *InGameApi) OrderInfo(c *gin.Context) {
|
||||
reqJson := struct {
|
||||
AccountId string `json:"account_id" binding:"required"`
|
||||
|
@ -19,4 +19,6 @@ func (this *IngameRouter) InitRouter() {
|
||||
api.InGameApi.ServerPreOrder)
|
||||
f5.GetApp().GetGinEngine().GET("/api/ingame/paid",
|
||||
api.InGameApi.PayDone)
|
||||
f5.GetApp().GetGinEngine().POST("/api/ingame/sprepurchase",
|
||||
api.InGameApi.ServerPrePurchase)
|
||||
}
|
||||
|
@ -22,6 +22,18 @@ func (wp *wxpay) GenSHA256Signature(str string, key string) string {
|
||||
return strings.ToLower(hex.EncodeToString(mac.Sum(nil)))
|
||||
}
|
||||
|
||||
func (wp *wxpay) GetPurchaseSig(gameid int64, data string, sessionkey string) (pay_sig string, signature string) {
|
||||
cfg := mt.Table.Wxconfig.GetById(gameid)
|
||||
if cfg == nil {
|
||||
return
|
||||
}
|
||||
pay_sig = wp.GenSHA256Signature("requestMidasPaymentGameItem&"+data, cfg.GetAppkey())
|
||||
signature = wp.GenSHA256Signature(data, sessionkey)
|
||||
|
||||
return pay_sig, signature
|
||||
|
||||
}
|
||||
|
||||
func (wp *wxpay) DecryptMsg(sMsgSignature string, sTimeStamp string, sNonce string, sEncryptMsg string) (sMsg []byte, msgappid []byte) {
|
||||
|
||||
// 2.validate signature
|
||||
|
Loading…
x
Reference in New Issue
Block a user