我来给你讲解下吧 具体看代码
properties:
smsName=你自己充值后的用户名
smsPwd=密码
smsInterface=http://106.ihuyi.cn/webservice/sms.php?method=Submit //我用的是这个公司的发送短信接口,还是比较快的 ,大概延迟2-5秒 收到短信service:
public void sendSMS(String phone,String content) throws Exception{
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(PropertiesUtil.getString("smsInterface"));
        client.getParams().setContentCharset("UTF-8");
        method.setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=UTF-8");
        NameValuePair[] data = {//提交短信
                new NameValuePair("account", PropertiesUtil.getString("smsName")),
                new NameValuePair("password", PropertiesUtil.getString("smsPwd")), //密码可以使用明文密码或使用32位MD5加密
                //new NameValuePair("password", util.StringUtil.MD5Encode("密码")),
                new NameValuePair("mobile", phone),
                new NameValuePair("content",content),
        };        method.setRequestBody(data);
        try {
            client.executeMethod(method);
            String SubmitResult =method.getResponseBodyAsString();
            Document doc = DocumentHelper.parseText(SubmitResult);
            Element root = doc.getRootElement();
            String code = root.elementText("code");
            String msg = root.elementText("msg");
            if(code.equals("2")){
                logger.info("sms send ok");
            }else{
                logger.info("sms maybe senderror code:"+code+" msg;"+msg);
                throw new Exception("sms send code is error");
            }        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    } @Transactional
    public void cardPhoneBindingNoLogin(String phoneNum,Card card) throws Exception{
        String smsCode = Encrypt.random(6);
        String msg = "您的验证码是:"+smsCode+"。请不要把验证码泄露给其他人。如非本人操作,可不用理会!";
        card.setLastSMSPhone(phoneNum);
        card.setLastSMSCode(smsCode);
        card.setLastSMSTime(new Date().getTime());
        card.merge();
        sendSMS(phoneNum, msg);
    }

解决方案 »

  1.   

    我来给你讲解下吧 具体看代码
    properties:
    smsName=你自己充值后的用户名
    smsPwd=密码
    smsInterface=http://106.ihuyi.cn/webservice/sms.php?method=Submit //我用的是这个公司的发送短信接口,还是比较快的 ,大概延迟2-5秒 收到短信service:
    public void sendSMS(String phone,String content) throws Exception{
            HttpClient client = new HttpClient();
            PostMethod method = new PostMethod(PropertiesUtil.getString("smsInterface"));
            client.getParams().setContentCharset("UTF-8");
            method.setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=UTF-8");
            NameValuePair[] data = {//提交短信
                    new NameValuePair("account", PropertiesUtil.getString("smsName")),
                    new NameValuePair("password", PropertiesUtil.getString("smsPwd")), //密码可以使用明文密码或使用32位MD5加密
                    //new NameValuePair("password", util.StringUtil.MD5Encode("密码")),
                    new NameValuePair("mobile", phone),
                    new NameValuePair("content",content),
            };        method.setRequestBody(data);
            try {
                client.executeMethod(method);
                String SubmitResult =method.getResponseBodyAsString();
                Document doc = DocumentHelper.parseText(SubmitResult);
                Element root = doc.getRootElement();
                String code = root.elementText("code");
                String msg = root.elementText("msg");
                if(code.equals("2")){
                    logger.info("sms send ok");
                }else{
                    logger.info("sms maybe senderror code:"+code+" msg;"+msg);
                    throw new Exception("sms send code is error");
                }        } catch (HttpException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }    } @Transactional
        public void cardPhoneBindingNoLogin(String phoneNum,Card card) throws Exception{
            String smsCode = Encrypt.random(6);
            String msg = "您的验证码是:"+smsCode+"。请不要把验证码泄露给其他人。如非本人操作,可不用理会!";
            card.setLastSMSPhone(phoneNum);
            card.setLastSMSCode(smsCode);
            card.setLastSMSTime(new Date().getTime());
            card.merge();
            sendSMS(phoneNum, msg);
        }
      

  2.   

    我来给你讲解下吧 具体看代码
    properties:
    smsName=你自己充值后的用户名
    smsPwd=密码
    smsInterface=http://106.ihuyi.cn/webservice/sms.php?method=Submit //我用的是这个公司的发送短信接口,还是比较快的 ,大概延迟2-5秒 收到短信service:
    public void sendSMS(String phone,String content) throws Exception{
            HttpClient client = new HttpClient();
            PostMethod method = new PostMethod(PropertiesUtil.getString("smsInterface"));
            client.getParams().setContentCharset("UTF-8");
            method.setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=UTF-8");
            NameValuePair[] data = {//提交短信
                    new NameValuePair("account", PropertiesUtil.getString("smsName")),
                    new NameValuePair("password", PropertiesUtil.getString("smsPwd")), //密码可以使用明文密码或使用32位MD5加密
                    //new NameValuePair("password", util.StringUtil.MD5Encode("密码")),
                    new NameValuePair("mobile", phone),
                    new NameValuePair("content",content),
            };        method.setRequestBody(data);
            try {
                client.executeMethod(method);
                String SubmitResult =method.getResponseBodyAsString();
                Document doc = DocumentHelper.parseText(SubmitResult);
                Element root = doc.getRootElement();
                String code = root.elementText("code");
                String msg = root.elementText("msg");
                if(code.equals("2")){
                    logger.info("sms send ok");
                }else{
                    logger.info("sms maybe senderror code:"+code+" msg;"+msg);
                    throw new Exception("sms send code is error");
                }        } catch (HttpException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }    }
      

  3.   

    要实现发短信的功能,你别急着在网上找,首先你要确定你发短信的功能是通过你自建平台发送(就是买个短信猫发),还是通过第三方短信平台发送的,如果确定买短信猫发,那么厂商会提供你发短信的API的,这个我想你很容易看懂,不想网上的资料那么零乱,如果你是通过第三方平台发送,那就更简单了,他们的API接口更简单,你只要编辑你的短信就行了。
      

  4.   

    通过第三方短信平台来发送,他们会提供WebService接口。
    用短信猫的话,厂家也会提供API和DEMO。
    最麻烦的情况,是自己写串口+AT指令代码。