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. 翻译 TI SerialBLEbridge V 1.4.1

    原文地址:http://processors.wiki.ti.com/index.php/SerialBLEbridge_V_1.4.1 Sample App Overview This page d ...

  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. 转 Grand Central Dispatch 基础教程:Part 1/2 -swift

    本文转载,原文地址:http://www.cocoachina.com/ios/20150609/12072.html 原文 Grand Central Dispatch Tutorail for S ...

  4. Microsoft Visio / Project professional 2013 官方版本(下载)

    Microsoft Visio微软开发的一款软件, 它有助于 IT 和商务专业人员轻松地可视化.分析和交流复杂信息. 它能够将难以理解的复杂文本和表格转换为一目了然的 Visio 图表. 该软件通过创 ...

  5. 【星云测试】开发者测试(3)-采用精准测试工具对springcloud微服务应用进行穿透测试

    1.微服务简介 微服务英文名称Microservice,Microservice架构模式就是将整个Web应用组织为一系列小的Web服务.这些小的Web服务可以独立地编译及部署,并通过各自暴露的API接 ...

  6. CABasicAnimation使用总结

    CABasicAnimation使用总结 实例化 使用方法animationWithKeyPath:对 CABasicAnimation进行实例化,并指定Layer的属性作为关键路径进行注册. //围 ...

  7. Vue如何循环渲染图片

    Vue如何把服务器返回的图片数据渲染出来 首先,一般来说,当请求图片的接口时,会返回一个数组,这个数组里会是一些图片的名字,比如1.jpg,2.jpg. 我的做法是先在data里定义一个数组,来存储服 ...

  8. poj1733 Parity Game(扩展域并查集)

    描述 Now and then you play the following game with your friend. Your friend writes down a sequence con ...

  9. 双硬盘双系统win10+manjaro-kde搭建

    电脑sdd+hdd双硬盘,默认win10装在了sdd分区,uefi+gpt引导.现在想要在hdd中划分出一个分区安装manjaro,并在开机多重引导. 1. 制作安装盘 先去下载最新的镜像,最好在国内 ...

  10. Python编程Message: CGI script is not executable ('/cgi-bin/xxxxx.py')

    Message: CGI script is not executable ('/cgi-bin/xxxxx.py'). 今天在练习python服务器端编程时遇到了这个错误,查阅一番最终解决 系统为l ...