Code Monkey home page Code Monkey logo

go-sms-sdk's Introduction

Yuntongxun SMS SDK for GO

容联云通讯 SDK

Quick Start

go get -u github.com/cloopen/go-sms-sdk/cloopen
package main

import (
 "github.com/cloopen/go-sms-sdk/cloopen"
 "log"
)

func main() {
 cfg := cloopen.DefaultConfig().
  // 开发者主账号
  WithAPIAccount("xxxxxxxxxxxxx").
  // 主账号令牌 TOKEN
  WithAPIToken("xxxxxxxxxxxxx")
 sms := cloopen.NewJsonClient(cfg).SMS()
 // 下发包体参数
 input := &cloopen.SendRequest{
  // 应用的APPID
  AppId: "xxxxxxxxxxxxx",
  // 手机号码
  To: "1352*******",
  // 模版ID
  TemplateId: "xxxx",
  // 模版变量内容 非必填
  Datas: []string{"变量1","变量2","变量3"},
 }
 // 下发
 resp, err := sms.Send(input)
 if err != nil {
  log.Fatal(err)
  return
 }
 log.Printf("Response MsgId: %s \n", resp.TemplateSMS.SmsMessageSid)

}

使用说明

  • 自定义配置及默认

    WithAPIAccount(xxx) 配置主账号 需调用者初始化此值

    WithAPIToken(xxx) 配置主账号令牌 需调用者初始化此值

    WithSmsHost(xxx) 配置ip:port 默认 app.cloopen.com:8883

    WithUseSSL(true) 配置是否使用https 默认启用https

    WithHTTPClient(customHttp) 配置自定义httpClient 默认使用sdk封装的httpClient

    WithHttpConf(&HttpConf{...}) 配置sdk封装的httpClient可调整参数 默认使用sdk封装的httpClient参数

    参考HttpConf默认配置:

    // 时间单位为毫秒
    &HttpConf{
       Timeout:             300,
       KeepAlive:           30000,
       MaxIdleConns:        100,
       IdleConnTimeout:     30000,
       TLSHandshakeTimeout: 300,
    }
  • 方法调用

    cloopen.NewJsonClient(cfg) json 格式包体使用此方法

    cloopen.NewXmlClient(cfg) xml 格式包体使用此方法

源码说明

  • sdk
    • config.go 接口基础配置
    • client.go 客户端定义、配置
    • fields.go 常量定义
    • sms.go 短信功能
    • util.go 工具函数
  • 分支说明
    • master最新稳定发布版本
    • develop待发布版本,贡献的代码请pull request到这里:)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.