开发者社区> 问答> 正文

阿里云OpenAPI这个问题怎么解决?

阿里云OpenAPI这个问题怎么解决?82843ada438be17b1b98851f9c0af821.png

展开
收起
三分钟热度的鱼 2024-06-05 20:19:12 20 0
1 条回答
写回答
取消 提交回答
  • 用v2.0sdk。这篇
    https://help.aliyun.com/zh/sdk/developer-reference/how-to-automatically-generate-an-sdk-example?spm=a2c4g.11186623.0.0.531b6ef5cDKcxY package main

    import (
    "fmt"

    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
    )

    func main() {
    config := sdk.NewConfig()

    // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
    credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    / use STS Token
    credential := credentials.NewStsTokenCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), os.Getenv("ALIBABA_CLOUD_SECURITY_TOKEN"))
    /
    client, err := sdk.NewClientWithOptions("cn-shanghai", config, credential)
    if err != nil {
    panic(err)
    }

    request := requests.NewCommonRequest()

    request.Method = "POST"
    request.Scheme = "https" // https | http
    request.Domain = "dysmsapi.aliyuncs.com"
    request.Version = "2017-05-25"
    request.ApiName = "AddSmsSign"
    request.QueryParams["SignName"] = "a"
    request.QueryParams["Remark"] = "c"
    request.QueryParams["SignSource"] = "1"
    request.QueryParams["SignFileList.1.FileContents"] = "test"
    request.QueryParams["SignFileList.1.FileSuffix"] = "PNG"
    request.QueryParams["SignType"] = "0"

    response, err := client.ProcessCommonRequest(request)
    if err != nil {
    panic(err)
    }
    fmt.Print(response.GetHttpContentString())
    } 发短信是这个 上面发成申请短信签名的接口了..
    package main

    import (
    "fmt"
    "os"

    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
    )

    func main() {
    config := sdk.NewConfig()

    // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
    credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    / use STS Token
    credential := credentials.NewStsTokenCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), os.Getenv("ALIBABA_CLOUD_SECURITY_TOKEN"))
    /
    client, err := sdk.NewClientWithOptions("cn-shanghai", config, credential)
    if err != nil {
    panic(err)
    }

    request := requests.NewCommonRequest()

    request.Method = "POST"
    request.Scheme = "https" // https | http
    request.Domain = "dysmsapi.aliyuncs.com"
    request.Version = "2017-05-25"
    request.ApiName = "SendMessageToGlobe"
    request.QueryParams["To"] = "a"
    request.QueryParams["From"] = "c"
    request.QueryParams["Message"] = "1"
    request.QueryParams["Type"] = "test"
    request.QueryParams["OutId"] = "PNG"

    response, err := client.ProcessCommonRequest(request)
    if err != nil {
    panic(err)
    }
    fmt.Print(response.GetHttpContentString())
    } 此回答整理自钉群“阿里云 OpenAPI SDK 自签名服务群”

    2024-06-05 23:05:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
AutoTalk第七期:自动化工具-OpenAPI在线调试 立即下载
最大化阿里云OpenAPI能力的方法和实践 立即下载
低代码开发师(初级)实战教程 立即下载