This commit is contained in:
2025-03-21 20:44:35 +08:00
parent bac4fd8b11
commit 8cede57a70
21 changed files with 430 additions and 120 deletions

View File

@ -0,0 +1,6 @@
package rediskey
const (
//用户总资产 {exchange_type,user_id}
User_Total_Asset = "u_total_asset:%s:%v"
)

View File

@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
"golang.org/x/net/proxy"
)
@ -20,7 +21,9 @@ import (
*/
func CreateHtppProxy(proxyType, proxyAddr string, client *http.Client) error {
// Set up proxy based on type (HTTP, HTTPS, SOCKS5)
transport := &http.Transport{}
transport := &http.Transport{
TLSHandshakeTimeout: 10 * time.Second,
}
if proxyAddr != "" {
if !strings.HasPrefix(proxyAddr, "http://") && !strings.HasPrefix(proxyAddr, "https://") && !strings.HasPrefix(proxyAddr, "socks5://") {
proxyAddr = proxyType + "://" + proxyAddr

View File

@ -1,18 +1,13 @@
package authservice
import (
"bytes"
"fmt"
"go-admin/common/const/rediskey"
"go-admin/common/helper"
statuscode "go-admin/common/status_code"
ext "go-admin/config"
"go-admin/pkg/cryptohelper/inttostring"
"io/ioutil"
"net/http"
"time"
"github.com/bytedance/sonic"
log "github.com/go-admin-team/go-admin-core/logger"
"go.uber.org/zap"
)
@ -496,60 +491,8 @@ func SendGoToneSms(phone, area string, smsType int) int {
}
//ext.ExtConfig.GoToneSmsConfig
// SmsRequest 用于构建发送短信请求的结构体
type SmsRequest struct {
Recipient string `json:"recipient"` // 收件人电话号码
Message string `json:"message"` // 短信内容
SenderId string `json:"sender_id"` // 发送者名称
Type string `json:"type"`
}
// 创建请求数据
smsRequest := SmsRequest{
Recipient: "+" + area + phone,
SenderId: ext.ExtConfig.GoToneSmsConfig.SenderId,
Message: fmt.Sprintf("欢迎使用 GoTone SMS高速稳定地发送短信至中国大陆及全球用户体验验证码%s。如非本人操作请忽略此信息", smsString),
Type: "plain",
}
// 将请求数据编码为 JSON
requestBody, err := sonic.Marshal(smsRequest)
if err != nil {
log.Error("GoToneSms requestBody Error:", err)
return statuscode.ServerError
}
// 创建 HTTP 请求
req, err := http.NewRequest("POST", ext.ExtConfig.GoToneSmsConfig.APIEndpoint, bytes.NewBuffer(requestBody))
if err != nil {
log.Error("GoToneSms http.NewRequest Error:", err)
return statuscode.ServerError
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+ext.ExtConfig.GoToneSmsConfig.Authorization) // 使用 API 密钥进行身份验证
// todo 短信cangchu
// 创建 HTTP 客户端并发送请求
client := &http.Client{
Timeout: 10 * time.Second, // 设置请求超时时间
}
resp, err := client.Do(req)
fmt.Println("resp:", resp)
if err != nil {
log.Error("GoToneSms do NewRequest Error:", err)
return statuscode.CaptchaFailInSend
}
defer resp.Body.Close()
// 检查响应状态
if resp.StatusCode != http.StatusOK {
log.Error("GoToneSms do NewRequest Error:", err)
return statuscode.CaptchaFailInSend
}
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error("读取响应体失败:", err)
fmt.Printf("响应体: %s", string(body))
return statuscode.CaptchaFailInSend
//return fmt.Errorf("读取响应体失败: %v", err)
}
// 打印响应内容(调试用)
//记录短信发送操作
helper.DefaultRedis.SetStringExpire(registerKey, "1", time.Second*60)