🎨 新增讲师相关接口(待完善)
This commit is contained in:
@@ -2,10 +2,15 @@ package sms
|
||||
|
||||
// SMS短信服务
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
||||
|
||||
@@ -71,3 +76,43 @@ func SendSMS(phone string, code string) bool {
|
||||
global.GVA_LOG.Info("短信[阿里云]", zap.String("发送成功", "手机号: "+phone))
|
||||
return true
|
||||
}
|
||||
|
||||
func SendSMSTest(phone, code string) bool {
|
||||
endpoint := "https://dfsns.market.alicloudapi.com/data/send_sms"
|
||||
templateID := "CST_ptdie100"
|
||||
|
||||
// 构造 POST 表单数据
|
||||
form := url.Values{}
|
||||
form.Set("content", fmt.Sprintf("code:%s", code))
|
||||
form.Set("template_id", templateID)
|
||||
form.Set("phone_number", phone)
|
||||
|
||||
// 创建 HTTP 请求
|
||||
req, err := http.NewRequest("POST", endpoint, strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 添加请求头
|
||||
req.Header.Set("Authorization", "APPCODE "+"b8f46ced154b44c5a40a0a49a91e1634")
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
// 创建 HTTP 客户端(跳过证书校验,模拟 curl -k)
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.Status != "ok" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user