zoukankan      html  css  js  c++  java
  • 发送短信功能

    以建周短信平台为例

    package com.wjz.util;
    
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.PostMethod;
    
    public class SMSUtil {
    
        /**
         * 
         * @param url
         *            短信平台地址
         * @param phone
         *            目标手机
         * @param message
         *            短信内容
         * @param account
         *            动态获取短信平台账号如从数据库中获得
         * @param password
         *            动态获取短信平台密码如从数据库中获得
         * @return
         */
        public static String send(String url, String phone, String message, String account, String password) {
            HttpClient httpClient = new HttpClient();
            PostMethod postMethod = new PostMethod(url);
            postMethod.getParams().setContentCharset("UTF-8");
            postMethod.addParameter("account", account);
            postMethod.addParameter("password", password);
            postMethod.addParameter("destmobile", phone);
            postMethod.addParameter("sendDateTime", "");
            postMethod.addParameter("msgText", message);
    
            String responseMsg = null;
            try {
                int code = httpClient.executeMethod(postMethod);
                if (code == HttpStatus.SC_OK) {
                    responseMsg = postMethod.getResponseBodyAsString();
                }
            } catch (Exception e) {
                // 
            } finally {
                postMethod.releaseConnection();
            }
            return responseMsg;
        }
    
    }
  • 相关阅读:
    SpringBoot和SpringCould的关系
    MyBatis全局配置文件头
    MyBatis的SQL映射文件头
    MyBatis 驼峰式配置 yml配置
    频率组件
    序列化和反序列化
    生成器面试题
    序列化组件
    进程间通信IPC机制
    信号量、event事件和线程queue
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/7484438.html
Copyright © 2011-2022 走看看