网建平台短信发送

网建平台短信发送

package com.util;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.IOException;

/**
 * @auther: 张勇波
 * @date: 2019-05-13 10:47
 * @description: 网建sms短信发送工具类
 */
public class SendMsg {
    public static void main(String[] args) throws IOException {
        String userID = "***";
        String userKey = "***";
        String smsMob = "130****2104,139****1027";
        String smsText = "网建sms 这是开发测试用的短信批量发送内容2";
        String result = sendMsg(userID, userKey, smsMob, smsText);
        System.out.println(result);
    }

    /**
     * sms短信发送smschinese.cn网建短信通
     *
     * @param userID  注册的用户名
     * @param userKey 接口秘钥
     * @param smsMob  目的手机号码(多个手机号请用半角逗号隔开)
     * @param smsText 短信内容,最多支持400个字,普通短信70个字/条,长短信64个字/条计费
     * @return 返回值说明
     * -1    没有该用户账户
     * -2    接口密钥不正确 [查看密钥] 不是账户登陆密码
     * -21   MD5接口密钥加密不正确
     * -3    短信数量不足
     * -11   该用户被禁用
     * -14   短信内容出现非法字符
     * -4    手机号格式不正确
     * -41   手机号码为空
     * -42   短信内容为空
     * -51   短信签名格式不正确 接口签名格式为:【签名内容】
     * -52   短信签名太长 建议签名10个字符以内
     * -6    IP限制
     * 大于0  短信发送数量
     * @throws IOException
     */
    public static String sendMsg(String userID, String userKey, String smsMob, String smsText) throws IOException {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("http://utf8.api.smschinese.cn");
        //在头文件中设置转码
        post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf8");
        NameValuePair[] data = {
                new NameValuePair("Uid", userID),
                new NameValuePair("Key", userKey),
                new NameValuePair("smsMob", smsMob),
                new NameValuePair("smsText", smsText)
        };
        post.setRequestBody(data);
        client.executeMethod(post);
//        System.out.println("--sendMsg--statusCode:" + post.getStatusCode());
//        Header[] headers = post.getResponseHeaders();
//        for (Header h : headers) {
//            System.out.println(h.toString());
//        }
        String result = new String(post.getResponseBodyAsString().getBytes("UTF-8"));
        post.releaseConnection();
        return result;
    }
}

 上一篇
日期转换为中文大写 日期转换为中文大写
日期转换为中文大写ALTER FUNCTION GetCNDay ( @dt ) RETURNS Nvarchar(50) AS BEGIN DECLARE @str Nvarchar(50) -- 中间字符串,用于存储
2019-08-19
下一篇 
深复制(深克隆)与浅复制(浅克隆) 深复制(深克隆)与浅复制(浅克隆)
深复制(深克隆)与浅复制(浅克隆)浅复制与深复制概念浅复制(浅克隆)被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象。换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象。 深复制(深克隆)被
2019-08-19
  目录