Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

阿里云 sdk 是外包写的吗? 给不起钱吗? #404

Closed
yanjinbin opened this issue Mar 29, 2024 · 2 comments
Closed

阿里云 sdk 是外包写的吗? 给不起钱吗? #404

yanjinbin opened this issue Mar 29, 2024 · 2 comments

Comments

@yanjinbin
Copy link

yanjinbin commented Mar 29, 2024

https://next.api.aliyun.com/api/Dysmsapi/2017-05-25/SendSms

// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  dysmsapi20170525  "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


/**
 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
 */
func CreateClient () (_result *dysmsapi20170525.Client, _err error) {
  // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
  // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378661.html。
  config := &openapi.Config{
    // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }
  // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
  config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
  _result = &dysmsapi20170525.Client{}
  _result, _err = dysmsapi20170525.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
    SignName: tea.String("阿里云短信测试"),
    TemplateCode: tea.String("SMS_154950909"),
    PhoneNumbers: tea.String("15757538011"),
    TemplateParam: tea.String("{\"code\":\"1234\"}"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // 复制代码运行请自行打印 API 的返回值
    _, _err = client.SendSmsWithOptions(sendSmsRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.Error())
    }
    // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
    // 错误 message
    fmt.Println(tea.StringValue(error.Message))
    // 诊断地址
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}
@yanjinbin
Copy link
Author

还是文档不会写啊 连个curl demo请求都没有

@ccfish86
Copy link

确实用的够够的了,一个SchedulerX的包,把所有用到的第三方包打进去不说 还把各平台的so文件都打进去,接近40M。
而且还依赖一些很旧的包(比如dom4j),搞得logback各种失效(cloudauth20190307 2.3.x)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants