package main

import (
"fmt"
"crypto/md5"
"encoding/hex"
"sort"
"strings"
"net/url"
"bytes"
"net/http"
"io/ioutil"
) var urls = "http://www.sendcloud.net/smsapi/send"
var token = "xxxxxx" type postData struct {
MsgType int `json:"msgType"`
Phone string `json:"phone"`
SmsUser string `json:"smsUser"`
TemplateId int `json:"templateId"`
Vars string `json:"vars"`
} func main() { postData := map[string]string{
"msgType": "0",
"smsUser": "xxxx",
"templateId": "19807",
"phone": "xxxxxx",
"vars": "{%name%:\"xxxxx\",%rulename%:\"aaaa\",%num%:\"1\"}",
}
var keys []string
for k := range postData {
keys = append(keys, k)
}
sort.Strings(keys)
param_str := ""
for _, k := range keys {
fmt.Println("Key:", k, "Value:", postData[k])
str := k + "=" + postData[k] + "&"
param_str += str
}
param_str = token + "&" + param_str + token
signature := Md5(param_str)
signature = strings.ToUpper(signature)
postData["signature"] = signature
postValues := url.Values{}
for postKey, PostValue := range postData{
postValues.Set(postKey, PostValue)
}
postDataStr := postValues.Encode()
postDataBytes := []byte(postDataStr)
postBytesReader := bytes.NewReader(postDataBytes)
httpReq, _ := http.NewRequest("POST", urls, postBytesReader)
httpReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
httpClient := &http.Client{}
httpResp, err := httpClient.Do(httpReq)
if err != nil {
fmt.Printf("http get strUrl=%s response error=%s\n", urls, err.Error())
}
defer httpResp.Body.Close()
body, errReadAll := ioutil.ReadAll(httpResp.Body)
if errReadAll != nil {
fmt.Printf("get response for strUrl=%s got error=%s\n", urls, errReadAll.Error())
}
fmt.Println(string(body))
} //生成32位md5字串
func Md5(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}

sendcloud golang 发送短信 示例代码的更多相关文章

  1. Android发送短信核心代码

    核心代码:(1)SmsManager manager = SmsManager.getDefault(); //获得默认的消息管理器(2)ArrayList<String> list = ...

  2. 使用短信猫发送短信java代码

    短信猫简单配置:https://www.cnblogs.com/Big-Boss/p/9699880.html 发送短信: package utils; import org.smslib.AGate ...

  3. #PHP# 华为云 API 方式发送短信

    使用给华为云 消息 服务 API 方式发送短信 代码来自华为云,已通过测试 <?php /** * 华为云发送短信示例代码 * 本段代码需要使用自己的配置信息才能正常运行,出配置信息外,不需要改 ...

  4. Windows Phone开发(24):启动器与选择器之发送短信

    原文:Windows Phone开发(24):启动器与选择器之发送短信 本节我们通过一个简单的发送短信示例来演示一下如果配合使用PhoneNumberChooserTask和SmsComposeTas ...

  5. Linux-C实现GPRS模块发送短信

    “GSM模块,是将GSM射频芯片.基带处理芯片.存储器.功放器件等集成在一块线路板上,具有独立的操作系统.GSM射频处理.基带处理并提供标准接口的功能模块.GSM模块根据其提供的数据传输速率又可以分为 ...

  6. One-day-学习笔记-商品成交时发送短信

    个人学习笔记(one) 根据需求:商品成交时发送短信 html代码省略..... Model代码省略..... /* * --------------------------------------- ...

  7. Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

    家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...

  8. jQuery实现倒计时重新发送短信验证码功能示例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 超实用的JavaScript代码段 Item4 --发送短信验证码

    发送短信验证码 实现点击“发送验证码”按钮后,按钮依次显示为“59秒后重试”.“58秒后重试”…直至倒计时至0秒时再恢复显示为“发送验证码”.在倒计时期间按钮为禁用状态 . 第一步.获取按钮.绑定事件 ...

随机推荐

  1. Gradle Goodness: Automatic Clean Tasks

    Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...

  2. Gradle Goodness: Renaming Files while Copying

    With the Gradle copy task we can define renaming rules for the files that are copied. We use the ren ...

  3. SpringMVC找不到对应的页面

    确认springmvc配置文件视图解析器配置正确. <!-- 视图解析器 --> <bean class="org.springframework.web.servlet. ...

  4. OpenID Connect Core 1.0(四)使用授权码流验证(上)

    3.1 使用授权码流验证(Authentication using the Authorization Code Flow) 本节描述如何使用授权码流执行验证.当使用授权码流时,会从令牌终结点返回的所 ...

  5. TensorFlow简要教程及线性回归算法示例

    TensorFlow是谷歌推出的深度学习平台,目前在各大深度学习平台中使用的最广泛. 一.安装命令 pip3 install -U tensorflow --default-timeout=1800 ...

  6. Android AIDL浅析及异步使用

    AIDL:Android Interface Definition Language,即 Android 接口定义语言. AIDL 是什么 Android 系统中的进程之间不能共享内存,因此,需要提供 ...

  7. CF451E Devu and Flowers(组合数)

    题目描述 Devu想用花去装饰他的花园,他已经购买了n个箱子,第i个箱子有fi朵花,在同一个的箱子里的所有花是同种颜色的(所以它们没有任何其他特征).另外,不存在两个箱子中的花是相同颜色的. 现在De ...

  8. 【Linux】日志分析及管理

    日志的作用   用于记录系统.程序运行中发生的各种事件   eg: [root@localhost ~]# yum install -y httpd [root@localhost ~]# tail ...

  9. C# 解压gzip文件(.tgz)

    1.引用 SharpCompress.dll 2.代码 using System;using System.IO;using System.Text;using SharpCompress.Reade ...

  10. 搭建kafka高级消费 (high-consumer)php7

    说明:有很多同学在服务器上搭建好,kafka,在应用端使用kafka时候出现很多问题,这里提供下我的kafka生产和消费的php函数 环境说明: 1:首先php要有kafka扩展,在命令行中输入 ph ...