update inapp_shop callback

This commit is contained in:
yangduo 2024-12-04 10:26:33 +08:00
parent f323500040
commit 177cb8b34c
6 changed files with 48 additions and 19 deletions

View File

@ -1,2 +1,3 @@
{ {
"shop_secret": "iG4Rpsa)6U31$H#^T85$^^3\""
} }

View File

@ -115,12 +115,12 @@ func (this *InAppShopApi) Callback(c *gin.Context) {
strb.WriteString(q5.SafeToString(rec[k])) strb.WriteString(q5.SafeToString(rec[k]))
} }
secret:= `iG4Rpsa)6U31$H#^T85$^^3"` secret := mt.Table.Config.GetShopSecret()
mac := hmac.New(sha256.New, []byte(secret)) mac := hmac.New(sha256.New, []byte(secret))
_, _ = mac.Write([]byte(strb.String())) _, _ = mac.Write([]byte(strb.String()))
sign := string(mac.Sum(nil)) sign := string(mac.Sum(nil))
if sign != reqObj.Signature { if strings.EqualFold(strings.ToLower(sign), strings.ToLower(reqObj.Signature)) {
f5.RspErr(c, 401, "invalid sign") f5.RspErr(c, 401, "invalid sign")
return return
} }
@ -135,11 +135,17 @@ func (this *InAppShopApi) Callback(c *gin.Context) {
return return
} }
orderModel.Status = q5.SafeToInt32(rec["status"]) status := q5.SafeToInt32(rec["status"])
if status <= orderModel.Status {
f5.RspErr(c, 401, "invalid status")
return
}
orderModel.Status = status
if orderModel.UpdateFields([]string{"status"}) != nil { if orderModel.UpdateFields([]string{"status"}) != nil {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error")
return return
} }
c.JSON(200,"") f5.RspErr(c, 0, "")
} }

View File

@ -39,12 +39,19 @@ func (this *InAppOrder) UpdateFields(fields []string) error {
} }
func (this *InAppOrder) Find(accountId string, orderId string) (error, bool) { func (this *InAppOrder) Find(accountId string, orderId string) (error, bool) {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take( // if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
this, "account_id = ? AND order_id = ?", accountId, orderId); result.Error != nil && // this, "account_id = ? AND order_id = ?", accountId, orderId); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) { // !errors.Is(result.Error, gorm.ErrRecordNotFound) {
return result.Error, false // return result.Error, false
// } else {
// return nil, result.RowsAffected > 0
// }
err, ok := this.FindByOrderId(orderId)
if err != nil {
return err, false
} else { } else {
return nil, result.RowsAffected > 0 return nil, ok && this.AccountId == accountId
} }
} }

View File

@ -20,3 +20,7 @@ func (this *ConfigTable) PostInit1() {
panic("无法读取config.json") panic("无法读取config.json")
} }
} }
func (this *ConfigTable) GetShopSecret() string {
return this.selfConf.GetShopSecret()
}

View File

@ -116,6 +116,7 @@ type ShopGoods struct {
} }
type Config struct { type Config struct {
shop_secret string
_flags1_ uint64 _flags1_ uint64
_flags2_ uint64 _flags2_ uint64
@ -481,6 +482,14 @@ func (this *ShopGoods) HasItemId() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0 return (this._flags1_ & (uint64(1) << 3)) > 0
} }
func (this *Config) GetShopSecret() string {
return this.shop_secret
}
func (this *Config) HasShopSecret() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *WheelServerCluster) LoadFromKv(kv map[string]interface{}) { func (this *WheelServerCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
@ -561,4 +570,5 @@ func (this *ShopGoods) LoadFromKv(kv map[string]interface{}) {
} }
func (this *Config) LoadFromKv(kv map[string]interface{}) { func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.shop_secret, "shop_secret", &this._flags1_, 1, kv)
} }

View File

@ -93,4 +93,5 @@ message ShopGoods
message Config message Config
{ {
optional string shop_secret = 1;
} }