1、新接textverified
This commit is contained in:
@ -5,8 +5,9 @@ import (
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/config"
|
||||
"go-admin/utils/redishelper"
|
||||
"go-admin/utils/utility"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -26,6 +27,19 @@ const (
|
||||
|
||||
// trx 链上支付定时查询
|
||||
func (j TrxPaymentJob) Exec(arg interface{}) error {
|
||||
key := fmt.Sprintf("pre_order:%s", "*")
|
||||
keys, err := redishelper.DefaultRedis.ScanKeys(key)
|
||||
|
||||
if err != nil {
|
||||
logger.Error("查询redis key失败", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(keys) == 0 {
|
||||
logger.Info("没有待处理订单")
|
||||
return nil
|
||||
}
|
||||
|
||||
configService := service.SysConfig{}
|
||||
configService.Orm = GetDb()
|
||||
req := dto.SysConfigByKeyReq{}
|
||||
@ -82,19 +96,31 @@ func (j TrxPaymentJob) Exec(arg interface{}) error {
|
||||
// GetTRC20Transfers 获取指定 TRC20 代币的交易记录
|
||||
func GetTRC20Transfers(contractAddress, accountAddress string, minTimestamp, maxTimestamp int64) ([]dto.TRC20Transfer, error) {
|
||||
url := fmt.Sprintf("%s/v1/accounts/%s/transactions/trc20?contract_address=%s", config.ExtConfig.TrxGridUrl, accountAddress, contractAddress)
|
||||
|
||||
if minTimestamp > 0 {
|
||||
url += fmt.Sprintf("&min_timestamp=%d", minTimestamp)
|
||||
}
|
||||
if maxTimestamp > 0 {
|
||||
url += fmt.Sprintf("&max_timestamp=%d", maxTimestamp)
|
||||
}
|
||||
resp, err := http.Get(url)
|
||||
// logger.Info("查询地址:", url)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %v", err)
|
||||
}
|
||||
|
||||
// 设置请求头(包含 TronGrid API Key)
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("TRON-PRO-API-KEY", config.ExtConfig.TronApiKey) // 从配置读取 API Key
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to send request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read response body: %v", err)
|
||||
}
|
||||
@ -102,6 +128,7 @@ func GetTRC20Transfers(contractAddress, accountAddress string, minTimestamp, max
|
||||
var result struct {
|
||||
Data []dto.TRC20Transfer `json:"data"`
|
||||
}
|
||||
// logger.Info("查询结果:", string(body))
|
||||
if err := sonic.Unmarshal(body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user