123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package aliyun
- import (
- cams20200606 "github.com/alibabacloud-go/cams-20200606/v2/client"
- openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
- "github.com/alibabacloud-go/tea/tea"
- )
- const (
- AccessKeyId string = "LTAI5tSJwCQyuaxXR3UxfnWw"
- AccessKeySecret string = "0pv4xhSPJv9IPSxrkB52FspJk27W7V"
- RegionId string = "cams.ap-southeast-1.aliyuncs.com"
- )
- // Description:
- // 使用AK&SK初始化账号Client
- // @return Client
- // @throws Exception
- func CreateCamsClient() (_result *cams20200606.Client, _err error) {
- // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
- // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378661.html。
- config := &openapi.Config{
- // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
- AccessKeyId: tea.String(AccessKeyId),
- // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
- AccessKeySecret: tea.String(AccessKeySecret),
- }
- // Endpoint 请参考 https://api.aliyun.com/product/cams
- config.Endpoint = tea.String(RegionId)
- _result = &cams20200606.Client{}
- _result, _err = cams20200606.NewClient(config)
- return _result, _err
- }
- // GetCamsAppId 获取 AppId
- // "LTAI5tSJwCQyuaxXR3UxfnWw", "0pv4xhSPJv9IPSxrkB52FspJk27W7V" "cams.ap-southeast-1.aliyuncs.com"
- func GetCamsAppId() (string, error) {
- client, _err := CreateCamsClient()
- if _err != nil {
- return "", _err
- }
- request := &cams20200606.IsvGetAppIdRequest{
- Type: tea.String("WHATSAPP"),
- }
- isvResponse, _err := client.IsvGetAppId(request)
- if _err != nil {
- return "", _err
- }
- return *isvResponse.Body.AppId, nil
- }
- // AddCamsPhoneNumber 添加WhatsApp号码
- func AddCamsPhoneNumber(phone, cc, custSpaceId, verifiedName string) (*cams20200606.AddChatappPhoneNumberResponse, error) {
- client, _err := CreateCamsClient()
- if _err != nil {
- return nil, _err
- }
- request := &cams20200606.AddChatappPhoneNumberRequest{
- PhoneNumber: tea.String(phone),
- Cc: tea.String(cc),
- CustSpaceId: tea.String(custSpaceId),
- VerifiedName: tea.String(verifiedName),
- }
- response, _err := client.AddChatappPhoneNumber(request)
- if _err != nil {
- return nil, _err
- }
- return response, nil
- }
|