短信平台服务热线:400-114-8008
  • 试用测试
  • 开通产品
  • 内容报备
  • 接口对接
  • 接入成功
  • 国际短信
    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Text;  
    using System.Net.Security;  
    using System.Security.Cryptography.X509Certificates;  
    using System.Net;  
    using System.IO;  
    using System.IO.Compression;  
    using System.Text.RegularExpressions; 
    using System.Security.Cryptography;
    using System.Web;
    public class Test
    {
       private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";  
      private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)  
        {  
          return true; //总是接受     
        }  
      static void Main(string[] args)  
          {  
                DateTime dt = DateTime.Now; 
                string mttime = dt.ToString("yyyyMMddHHmmss");
                string pwd1 = "密码"+mttime;//密码
                string pwd = md5(pwd1);
                 Console.WriteLine(pwd.Length);
                string content = "【阅信】验证码888888,请注意保密,以防泄露!";
                //string content = "123456"; 语音验证码内容
                string url = " http://IP:Port/HttpSmsMt";//接口地址,请咨询客服  
                Encoding encoding = Encoding.GetEncoding("utf-8");  
                IDictionary parameters = new Dictionary();  
                parameters.Add("name", "用户名");//开通的用户名  
                parameters.Add("pwd", pwd);  
                parameters.Add("content",content);
                parameters.Add("phone","13400000000");
                parameters.Add("subid","");
                parameters.Add("mttime", mttime);  
                parameters.Add("rpttype", "1");  
                HttpWebResponse response = CreatePostHttpResponse(url,parameters,encoding);  
                //打印返回值  
                Stream stream = response.GetResponseStream();   //获取响应的字符串流  
                StreamReader sr = new StreamReader(stream); //创建一个stream读取流  
                string html = sr.ReadToEnd();   //从头读到尾,放到字符串html  
                Console.WriteLine(html);   
            }
        public static String md5(String s)
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
                bytes = md5.ComputeHash(bytes);
                md5.Clear();
    
                string ret = "";
                for (int i = 0; i < bytes.Length; i++)
                {
                    ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
                }
    
                return ret.PadLeft(32, '0');
            }
         public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary parameters,Encoding charset)  
            {  
                HttpWebRequest request = null;  
                //HTTPSQ请求  
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);  
                request = WebRequest.Create(url) as HttpWebRequest;  
                request.ProtocolVersion = HttpVersion.Version10;  
                request.Method = "POST";  
                request.ContentType = "application/x-www-form-urlencoded";  
                request.UserAgent = DefaultUserAgent;  
                //如果需要POST数据     
                if (!(parameters == null || parameters.Count == 0))  
                {  
                    StringBuilder buffer = new StringBuilder();  
                    int i = 0;  
                    foreach (string key in parameters.Keys)  
                    {  
                        if (i > 0)  
                        {  
                           buffer.AppendFormat("&{0}={1}",key,parameters[key]);  
                        }  
                        else  
                        {  
                            buffer.AppendFormat("{0}={1}",key, parameters[key]);  
                        }  
                        i++;  
                    }  
                    byte[] data = charset.GetBytes(buffer.ToString());  
                    using (Stream stream = request.GetRequestStream())  
                    {  
                        stream.Write(data, 0, data.Length);  
                    }  
                }  
                return request.GetResponse() as HttpWebResponse;  
            } 
    }
    #!/usr/bin/env python
    #coding=utf-8
    import urllib
    import urllib2
    import time
    import hashlib
    
    def md5(str):
        import hashlib
        m = hashlib.md5()   
        m.update(str)
        return m.hexdigest()
        
    url = 'http://IP:Port/HttpSmsMt' #接口地址,请咨询客服
    timenew= time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
    pwd = md5(密码+timenew) #密码
    values = {'name':用户名,'pwd':pwd,'content':'【阅信】验证码888888。','phone':'13400000000','subid':'','mttime':timenew} #开通的用户名
    # values = {'name':用户名,'pwd':pwd,'content':'123456','phone':'13400000000','subid':'','mttime':timenew} 语音验证码内容
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    the_page = response.read()
    print the_page
    package main
    import (
    	"fmt"
    	"io/ioutil"
    	"net/http"
    	"net/url"
        "time"
        "strconv"  
        "strings"
        "crypto/md5"
        "encoding/hex"
    )
    func httpPostForm() {
        var time=Format(time.Now(), "yyyyMMddHHmmss");
        var password = "xxxxx";//密码
        pwd := md5.New()
        pwd.Write([]byte(password+time)) // 需要将密码和时间加密
        var content = "【阅信】验证码888888";
        //var content = "123456";  语音验证码内容
        var name = "xxxxx"//账号
    	resp, err := http.PostForm("http://IP:Port/HttpSmsMt",//接口地址,请咨询客服
    		url.Values{"name": {name}, "pwd": {hex.EncodeToString(pwd.Sum(nil))},"content":{content},"phone":{"13400000000"},"subid":{""},"mttime":{time},"rpttype":{"1"}})
    	if err != nil {
    		// handle error
    	}
    	defer resp.Body.Close()
    	body, err := ioutil.ReadAll(resp.Body)
    	if err != nil {
    		// handle error
    	}
    	fmt.Println(string(body))
    }
    func byteString(p []byte) string {
            for i := 0; i < len(p); i++ {
                    if p[i] == 0 {
                            return string(p[0:i])
                    }
            }
            return string(p)
    }
    
    func Format(t time.Time, format string) string {  
        //year  
        if strings.ContainsAny(format, "y") {  
            year := strconv.Itoa(t.Year())  
            if strings.Count(format, "yy") == 1 && strings.Count(format, "y") == 2 {  
                format = strings.Replace(format, "yy", year[2:], 1)  
            } else if strings.Count(format, "yyyy") == 1 && strings.Count(format, "y") == 4 {  
                format = strings.Replace(format, "yyyy", year, 1)  
            } else {  
                panic("format year error! please 'yyyy' or 'yy'")  
            }  
        }  
      
        //month  
        if strings.ContainsAny(format, "M") {  
            var month string  
            if int(t.Month()) < 10 {  
                month = "0" + strconv.Itoa(int(t.Month()))  
            } else {  
                month = strconv.Itoa(int(t.Month()))  
            }  
            if strings.Count(format, "MM") == 1 && strings.Count(format, "M") == 2 {  
                format = strings.Replace(format, "MM", month, 1)  
            } else {  
                panic("format month error! please 'MM'")  
            }  
        }  
        //day  
        if strings.ContainsAny(format, "d") {  
            var day string  
            if t.Day() < 10 {  
                day = "0" + strconv.Itoa(t.Day())  
            } else {  
                day = strconv.Itoa(t.Day())  
            }  
            if strings.Count(format, "dd") == 1 && strings.Count(format, "d") == 2 {  
                format = strings.Replace(format, "dd", day, 1)  
            } else {  
                panic("format day error! please 'dd'")  
            }  
        }  
      
        //hour  
        if strings.ContainsAny(format, "H") {  
            var hour string  
            if t.Hour() < 10 {  
                hour = "0" + strconv.Itoa(t.Hour())  
            } else {  
                hour = strconv.Itoa(t.Hour())  
            }  
            if strings.Count(format, "HH") == 1 && strings.Count(format, "H") == 2 {  
                format = strings.Replace(format, "HH", hour, 1)  
            } else {  
                panic("format hour error! please 'HH'")  
            }  
        }  
        //minute  
        if strings.ContainsAny(format, "m") {  
            var minute string  
            if t.Minute() < 10 {  
                minute = "0" + strconv.Itoa(t.Minute())  
            } else {  
                minute = strconv.Itoa(t.Minute())  
            }  
            if strings.Count(format, "mm") == 1 && strings.Count(format, "m") == 2 {  
                format = strings.Replace(format, "mm", minute, 1)  
            } else {  
                panic("format minute error! please 'mm'")  
            }  
        }  
      
        //second  
        if strings.ContainsAny(format, "s") {  
            var second string  
            if t.Second() < 10 {  
                second = "0" + strconv.Itoa(t.Second())  
            } else {  
                second = strconv.Itoa(t.Second())  
            }  
            if strings.Count(format, "ss") == 1 && strings.Count(format, "s") == 2 {  
                format = strings.Replace(format, "ss", second, 1)  
            } else {  
                panic("format second error! please 'ss'")  
            }  
        }  
        return format  
    } 
    
    func main() {
    httpPostForm()
    }
    public class Api {
    	public static void main(String[] args) {
    		// 接口地址
    		String url = "http://IP:Port/HttpSmsMt";//接口地址,请咨询客服
    		// 下发时间
    		String mttime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    		Map param = new HashMap();
    		param.put("name", "账号");//开通的用户名
    		param.put("pwd", Api.MD51("密码" + mttime));//密码
    		try {
    			param.put("content", URLEncoder.encode("【阅信】验证码888888。 ", "UTF-8"));
               // param.put("content", "123456"); 语音验证码内容
    		} catch (UnsupportedEncodingException e) {
    			e.printStackTrace();
    		}
    		param.put("phone", "13400000000");
    		param.put("subid", "");
    		param.put("mttime", mttime);
           param.put("rpttype", "1");
    		sendPost(url, param);
    	}
    
    	public static String sendPost(String url, Map params) {
    		URL u = null;
    		HttpURLConnection con = null;
    		// 构建请求参数
    		StringBuffer sb = new StringBuffer();
    		if (params != null) {
    			for (Entry e : params.entrySet()) {
    				sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
    			}
    			sb.substring(0, sb.length() - 1);
    		}
    		// 尝试发送请求
    		try {
    			u = new URL(url);
    			con = (HttpURLConnection) u.openConnection();
    			con.setRequestMethod("POST");
    			con.setConnectTimeout(6000);
    			con.setDoOutput(true);
    			con.setDoInput(true);
    			con.setUseCaches(false);
    			con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    			OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
    			osw.write(sb.toString());
    			osw.flush();
    			osw.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			if (con != null) {
    				con.disconnect();
    			}
    		}
    
    		// 读取返回内容
    		StringBuffer buffer = new StringBuffer();
    		try {
    			BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
    			String temp;
    			while ((temp = br.readLine()) != null) {
    				buffer.append(temp).append("\n");
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return buffer.toString();
    	}
    
    	public static String MD51(String str) {
    		MessageDigest md5 = null;
    		try {
    			md5 = MessageDigest.getInstance("MD5");
    		} catch (Exception e) {
    			e.printStackTrace();
    			return "";
    		}
    		char[] charArray = str.toCharArray();
    		byte[] byteArray = new byte[charArray.length];
    		for (int i = 0; i < charArray.length; i++)
    			byteArray[i] = (byte) charArray[i];
    		byte[] md5Bytes = md5.digest(byteArray);
    		StringBuffer hexValue = new StringBuffer();
    		for (int i = 0; i < md5Bytes.length; i++) {
    			int val = ((int) md5Bytes[i]) & 0xff;
    			if (val < 16) {
    				hexValue.append("0");
    			}
    			hexValue.append(Integer.toHexString(val));
    		}
    		return hexValue.toString();
    	}
    
    	public final static String MD5(String s) {
    		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    		try {
    			byte[] btInput = s.getBytes();
    			// 获得MD5摘要算法的 MessageDigest 对象
    			MessageDigest mdInst = MessageDigest.getInstance("MD5");
    			// 使用指定的字节更新摘要
    			mdInst.update(btInput);
    			// 获得密文
    			byte[] md = mdInst.digest();
    			// 把密文转换成十六进制的字符串形式
    			int j = md.length;
    			char str[] = new char[j * 2];
    			int k = 0;
    			for (int i = 0; i < j; i++) {
    				byte byte0 = md[i];
    				str[k++] = hexDigits[byte0 >>> 4 & 0xf];
    				str[k++] = hexDigits[byte0 & 0xf];
    			}
    			return new String(str);
    		} catch (Exception e) {
    			e.printStackTrace();
    			return null;
    		}
    	}
    }
    php
     date_default_timezone_set('PRC'); //设置时区为东八区否则时间比北京时间早8小时
     $url = 'http:///IP:Port/HttpSmsMt';//接口地址,请咨询客服
     $mttime=date("YmdHis");
     $name = 'xxxxx';//开通的用户名
     $password='xxxxx';//密码
     $post_data['name']  = $name;
     $post_data['pwd'] = md5($password.$mttime);
     $post_data['content'] = '【阅信】验证码888888。';
     //$post_data['content'] = '123456'; 语音验证码内容
     $post_data['phone']    = '13400000000';//手机号码
     $post_data['subid']    = '';
     $post_data['mttime']=$mttime;
     $post_data['rpttype']    = '1';
     $o = "";
     foreach ( $post_data as $k => $v )
      {
    	  $o.= "$k=" . urlencode( $v ). "&" ;
      }
     $post_data = substr($o,0,-1);
     $res = request_post($url, $post_data);
     print $res;
    
    
    /**
     * 模拟post进行url请求
     * @param string $url
     * @param string $param
     */
    function request_post($url = '', $param = '') {
    	if (empty($url) || empty($param)) {
    		return false;
    	}
    
    	$postUrl = $url;
    	$curlPost = $param;
    	$ch = curl_init();//初始化curl
    	curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
    	curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且屏幕上
    	curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    	$data = curl_exec($ch);//运行curl
    	curl_close($ch);
    
    	return $data;
    }
    ?>