feat(app): update

This commit is contained in:
Yangtao
2025-11-18 18:33:22 +08:00
parent 6e56cab848
commit 7c0ad28e96
27 changed files with 20 additions and 673 deletions

View File

@ -14,22 +14,11 @@ import (
"github.com/spf13/viper"
)
// CreateAliSmsClient
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func CreateAliSmsClient(accessKeyId *string, accessKeySecret *string) (_result *dysmsapi20170525.Client, _err error) {
config := &openapi.Config{
// 必填,您的 AccessKey ID
AccessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
}
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
_result = &dysmsapi20170525.Client{}
_result, _err = dysmsapi20170525.NewClient(config)
@ -71,8 +60,6 @@ func SendMobileMsg01(mobile, signName, tempCode, content string) (_result *dysms
ID = viper.GetString("aliyun.sms.accessKeyId")
Secret = viper.GetString("aliyun.sms.accessKeySecret")
)
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378661.html
client, _err := CreateAliSmsClient(tea.String(ID), tea.String(Secret))
if _err != nil {
return nil, _err
@ -90,7 +77,6 @@ func SendMobileMsg01(mobile, signName, tempCode, content string) (_result *dysms
_e = r
}
}()
// 复制代码运行请自行打印 API 的返回值
_result, _err = client.SendSmsWithOptions(sendSmsRequest, &util.RuntimeOptions{})
if _err != nil {
return nil, _err
@ -116,9 +102,6 @@ func SendMobileMsg01(mobile, signName, tempCode, content string) (_result *dysms
}
func SendVerifyCodeUsaAndCanada(mobile, content string, fn func(_result *dysmsapi20170525.SendSmsResponse, success bool)) (_result *dysmsapi20170525.SendSmsResponse, e error) {
// if !helper.IsMobile(mobile) {
// return nil, errors.New("手机号有误!")
// }
sign, code := getSignAndCode()
log.InfoF("SendVerifyCodeUsaAndCanada get sms sign and code: %s %s", sign, code)
_result, e = SendMobileMsgUsaAndCanada(mobile, sign, code, content)
@ -129,9 +112,6 @@ func SendVerifyCodeUsaAndCanada(mobile, content string, fn func(_result *dysmsap
}
func SendVerifyCodeGlobalOther(mobile, content string, fn func(_result *dysmsapi20170525.SendSmsResponse, success bool)) (_result *dysmsapi20170525.SendSmsResponse, e error) {
// if !helper.IsMobile(mobile) {
// return nil, errors.New("手机号有误!")
// }
sign, code := getSignAndCode()
log.InfoF("SendVerifyCodeUsaAndCanada get sms sign and code: %s %s", sign, code)
_result, e = SendMobileMsgGlobalOther(mobile, sign, code, content)
@ -141,14 +121,11 @@ func SendVerifyCodeGlobalOther(mobile, content string, fn func(_result *dysmsapi
return
}
// SendMobileMsgUsaAndCanada 美国/加拿大地区短信发送
func SendMobileMsgUsaAndCanada(mobile, signName, tempCode, content string) (_result *dysmsapi20170525.SendSmsResponse, _err error) {
var (
ID = viper.GetString("aliyun.sms.accessKeyId")
Secret = viper.GetString("aliyun.sms.accessKeySecret")
)
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378661.html
client, _err := CreateAliSmsClient(tea.String(ID), tea.String(Secret))
if _err != nil {
return nil, _err
@ -166,7 +143,6 @@ func SendMobileMsgUsaAndCanada(mobile, signName, tempCode, content string) (_res
_e = r
}
}()
// 复制代码运行请自行打印 API 的返回值
_result, _err = client.SendSmsWithOptions(sendSmsRequest, &util.RuntimeOptions{})
if _err != nil {
return nil, _err
@ -191,20 +167,11 @@ func SendMobileMsgUsaAndCanada(mobile, signName, tempCode, content string) (_res
return res, _err
}
// SendMobileMsgGlobalOther 全球其他国家
func SendMobileMsgGlobalOther(mobile, signName, tempCode, content string) (_result *dysmsapi20170525.SendSmsResponse, _err error) {
var (
// ID AccessKey ID
// LTAI5tRfkJnr6Y6NU2T6jWoB
//
// AccessKey Secret
// BcaMWgXkwdxdJXFnCwRQbEl3Q3Xtxl
// TODO: 替换为您的AccessKey ID和AccessKey Secret
ID = viper.GetString("aliyun.sms.accessKeyId")
Secret = viper.GetString("aliyun.sms.accessKeySecret")
)
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378661.html
client, _err := CreateAliSmsClient(tea.String(ID), tea.String(Secret))
if _err != nil {
return nil, _err
@ -238,7 +205,6 @@ func SendMobileMsgGlobalOther(mobile, signName, tempCode, content string) (_resu
} else {
e.Message = tea.String(tryErr.Error())
}
// 如有需要,请打印 error
_, _err = util.AssertAsString(e.Message)
if _err != nil {
return nil, _err
@ -266,8 +232,6 @@ func SendMobileMsgHKMacauAndTW(mobile, signName, tempCode, content string) (_res
ID = viper.GetString("aliyun.sms.accessKeyId")
Secret = viper.GetString("aliyun.sms.accessKeySecret")
)
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378661.html
client, _err := CreateAliSmsClient(tea.String(ID), tea.String(Secret))
if _err != nil {
return nil, _err