mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
test
This commit is contained in:
parent
b7f257daf1
commit
cfcc5c1095
@ -689,11 +689,20 @@ demo:
|
|||||||
listenIP: 0.0.0.0
|
listenIP: 0.0.0.0
|
||||||
#demo对外服务端口,默认即可,需要开放此端口或做nginx转发
|
#demo对外服务端口,默认即可,需要开放此端口或做nginx转发
|
||||||
openImDemoPort: [ 10004 ]
|
openImDemoPort: [ 10004 ]
|
||||||
alismsverify: #阿里云短信配置,在阿里云申请成功后修改以下四项,必须修改
|
alismsverify: #阿里云短信配置,在阿里云申请成功后修改以下四项,enable为true则必须修改,阿里云为默认短信验证方式
|
||||||
accessKeyId: LTAI5tJPkn4HuuePdiLdGqe7
|
accessKeyId: LTAI5tJPkn4HuuePdiLdGqe7
|
||||||
accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV
|
accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV
|
||||||
signName: 托云信息技术
|
signName: 托云信息技术
|
||||||
verificationCodeTemplateCode: SMS_226810164
|
verificationCodeTemplateCode: SMS_226810164
|
||||||
|
enable: true
|
||||||
|
tencentsms: #腾讯云短信配置,在腾讯云申请成功后,修改以下选项,enable为true则必须修改
|
||||||
|
appID: 1400529182
|
||||||
|
region: ap-chengdu
|
||||||
|
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC1
|
||||||
|
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe1
|
||||||
|
signName: ""
|
||||||
|
verificationCodeTemplateCode: 1449250
|
||||||
|
enable: true
|
||||||
superCode: 666666 #超级验证码,建议修改掉,收不到短信验证码时可以用此替代
|
superCode: 666666 #超级验证码,建议修改掉,收不到短信验证码时可以用此替代
|
||||||
# second
|
# second
|
||||||
codeTTL: 300
|
codeTTL: 300
|
||||||
|
14
internal/demo/register/CreateTencentSMSClient_test.go
Normal file
14
internal/demo/register/CreateTencentSMSClient_test.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package register
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_CreateTencentSMSClient(t *testing.T) {
|
||||||
|
result, err := CreateTencentSMSClient()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
fmt.Println("return result is ", result)
|
||||||
|
|
||||||
|
}
|
@ -6,11 +6,16 @@ import (
|
|||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
|
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
|
||||||
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
|
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||||
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
|
sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111"
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -128,3 +133,34 @@ func CreateClient(accessKeyId *string, accessKeySecret *string) (result *dysmsap
|
|||||||
result, err = dysmsapi20170525.NewClient(c)
|
result, err = dysmsapi20170525.NewClient(c)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
func CreateTencentSMSClient() (string, error) {
|
||||||
|
credential := common.NewCredential(
|
||||||
|
config.Config.Demo.TencentSMS.SecretID,
|
||||||
|
config.Config.Demo.TencentSMS.SecretKey,
|
||||||
|
)
|
||||||
|
cpf := profile.NewClientProfile()
|
||||||
|
client, err := sms.NewClient(credential, config.Config.Demo.TencentSMS.Region, cpf)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
request := sms.NewSendSmsRequest()
|
||||||
|
request.SmsSdkAppId = common.StringPtr(config.Config.Demo.TencentSMS.AppID)
|
||||||
|
request.SignName = common.StringPtr(config.Config.Demo.TencentSMS.SignName)
|
||||||
|
request.TemplateId = common.StringPtr(config.Config.Demo.TencentSMS.VerificationCodeTemplateCode)
|
||||||
|
request.TemplateParamSet = common.StringPtrs([]string{"1234"})
|
||||||
|
request.PhoneNumberSet = common.StringPtrs([]string{"+8613711112222"})
|
||||||
|
// 通过client对象调用想要访问的接口,需要传入请求对象
|
||||||
|
response, err := client.SendSms(request)
|
||||||
|
// 非SDK异常,直接失败。实际代码中可以加入其他的处理。
|
||||||
|
if err != nil {
|
||||||
|
log.Error("test", "send code to tencent err", err.Error())
|
||||||
|
}
|
||||||
|
// 处理异常
|
||||||
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||||
|
log.Error("test", "An API error has returned:", err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := json.Marshal(response.Response)
|
||||||
|
return string(b), nil
|
||||||
|
}
|
||||||
|
@ -452,6 +452,16 @@ type config struct {
|
|||||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||||
SignName string `yaml:"signName"`
|
SignName string `yaml:"signName"`
|
||||||
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
|
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
|
||||||
|
Enable bool `yaml:"enable"`
|
||||||
|
}
|
||||||
|
TencentSMS struct {
|
||||||
|
AppID string `yaml:"appID"`
|
||||||
|
Region string `yaml:"region"`
|
||||||
|
SecretID string `yaml:"secretID"`
|
||||||
|
SecretKey string `yaml:"secretKey"`
|
||||||
|
SignName string `yaml:"signName"`
|
||||||
|
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
|
||||||
|
Enable bool `yaml:"enable"`
|
||||||
}
|
}
|
||||||
SuperCode string `yaml:"superCode"`
|
SuperCode string `yaml:"superCode"`
|
||||||
CodeTTL int `yaml:"codeTTL"`
|
CodeTTL int `yaml:"codeTTL"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user