This commit is contained in:
aozhiwei 2024-08-01 09:55:46 +08:00
parent 7988482857
commit ee7707286f
3 changed files with 52 additions and 0 deletions

View File

@ -88,6 +88,14 @@ type NftStackingPo struct {
Quality int32 `json:"q"`
}
type ContractCall struct {
TransId string `json:"trans_id"`
TransReq struct {
To string `json:"to"`
Data string `json:"data"`
} `json:"trans_req"`
}
type ContractStackingPo struct {
NetId int32 `json:"net_id"`
ContractAddress string `json:"contract_address"`

View File

@ -3,6 +3,7 @@ package recharge
import (
"f5"
"fmt"
"jccommon"
"main/common"
"main/constant"
@ -41,6 +42,48 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
c.JSON(200, rspObj)
}
func (this *RechargeApi) Pay(c *gin.Context) {
reqJson := struct {
NetId int32 `json:"net_id"`
GoodsId string `json:"goods_id"`
AccountAddress string `json:"account_address"`
} {}
if err := c.ShouldBindJSON(&reqJson); err != nil {
c.JSON(http.StatusOK, gin.H{
"errcode": 1,
"errmsg": err.Error(),
})
return
}
orderId := q5.ToString(f5.GetApp().NewLockNodeUuid())
params := map[string]string{
"c" : "BcService",
"a" : "recharge",
"net_id" : q5.ToString(reqJson.NetId),
"order_id" : orderId,
}
jsonRspObj := &struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Calls []jccommon.ContractCall `json:"calls"`
}{}
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3ServiceCluster.RandElement().GetUrl())
f5.GetHttpCliMgr().SendGoStyleRequest(
url,
params,
func(rsp f5.HttpCliResponse) {
if rsp.GetErr() != nil {
f5.RspErr(c, 500, "server internal error")
return
}
if q5.DecodeJson(rsp.GetRawData(), &jsonRspObj) != nil {
f5.RspErr(c, 500, "server internal error")
return
}
c.JSON(200, jsonRspObj);
})
}
func (ea *RechargeApi) RechargeQuery(c *gin.Context) {
account := strings.ToLower(c.Param("account_address"))
reqJson := struct {

View File

@ -11,4 +11,5 @@ func (er *RechargeRouter) InitRouter() {
api := v1.ApiGroupApp.RechargeApiGroup
f5.GetApp().GetGinEngine().GET("/api/recharge/history/:account_address", api.RechargeApi.RechargeQuery)
f5.GetApp().GetGinEngine().GET("/api/recharge/goods", api.RechargeApi.RechargeList)
f5.GetApp().GetGinEngine().GET("/api/recharge/pay", api.RechargeApi.Pay)
}