zoukankan      html  css  js  c++  java
  • 容联七陌短信/验证码

    1.容联七陌云客服登录地址:https://kf.7moor.com ,需要注册账号,接口参考容联七陌开发者中心:http://developer.7moor.com/v2docs/sms/

    package com.gsafety.operationmanagement.utils;
    
    import java.io.IOException;
    import java.util.Date;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.util.EntityUtils;
    
    import com.alibaba.fastjson.JSONObject;
    
    public class MoorMessageUtil {
    
    	/**
    	 * 获取短信发送模板
    	 * @return
    	 */
    	public static String getSmsTemplet() {
    		String smsURL = MoorConfig.SMSTEMPLET_URL;
    		String sig = MD5Util.getMd5(MoorConfig.accountID+MoorConfig.APISecret+DateUtil.getFullDateStr(new Date()));
    		String authorization = MD5Util.encryptBASE64(MoorConfig.accountID+":"+DateUtil.getFullDateStr(new Date()));
    		HttpPost httpPost = new HttpPost(smsURL.replace("accountID", MoorConfig.accountID).replace("SIG", sig));
    		httpPost.addHeader("Accept","application/json;");
    		httpPost.addHeader("Content-Type","application/json;charset=utf-8;");
    		//httpPost.addHeader("Content-Length","256");
    		httpPost.addHeader("Authorization",authorization);
    		HttpClientBuilder builder = HttpClientBuilder.create();
    		HttpClient client = builder.build();
    		StringEntity requestEntity = null;
    		HttpEntity entity = null;
    		String requestModel = "{}";
    		CloseableHttpResponse response = null;
    		String rstMsg = "";
    		try {
    			requestEntity = new StringEntity(requestModel,"UTF-8");
    			httpPost.setEntity(requestEntity);
    			response = (CloseableHttpResponse) client.execute(httpPost);
    			entity = response.getEntity();
    			 rstMsg = EntityUtils.toString(entity,"UTF-8");
    			System.out.println(rstMsg);
    		}  catch (IOException e) {
    			e.printStackTrace();
    			return null;
    		}
    		return rstMsg;
    	}
    	
    	/**
    	 * 发送短信接口
    	 * @return
    	 */
    	public static String SendMassage(JSONObject jsonObject) {
    		String smsURL = MoorConfig.SENDSMS_URL;
    		String sig = MD5Util.getMd5(MoorConfig.accountID+MoorConfig.APISecret+DateUtil.getFullDateStr(new Date()));
    		String authorization = MD5Util.encryptBASE64(MoorConfig.accountID+":"+DateUtil.getFullDateStr(new Date()));
    		HttpPost httpPost = new HttpPost(smsURL.replace("accountID", MoorConfig.accountID).replace("SIG", sig));
    		httpPost.addHeader("Accept","application/json;");
    		httpPost.addHeader("Content-Type","application/json;charset=utf-8;");
    		httpPost.addHeader("Authorization",authorization);
    		HttpClientBuilder builder = 	HttpClientBuilder.create();
    		HttpClient client = builder.build();
    		StringEntity requestEntity = null;
    		HttpEntity entity = null;
    		String requestModel = jsonObject.toJSONString();
    		CloseableHttpResponse response = null;
    		String rstMsg = "";
    		try {
    			requestEntity = new StringEntity(requestModel,"UTF-8");
    			httpPost.setEntity(requestEntity);
    			response = (CloseableHttpResponse) client.execute(httpPost);
    			entity = response.getEntity();
    			rstMsg = EntityUtils.toString(entity,"UTF-8");
    			System.out.println(rstMsg);
    		}  catch (IOException e) {
    			e.printStackTrace();
    		}
    		return rstMsg;
    	}
    	
    	
    	public static void main(String[] args) {
    		//getSmsTemplet();
    		SendMassage(new JSONObject());
    	}
    	
    }
    

      

  • 相关阅读:
    android开发我的新浪微博客户端-用户授权页面UI篇(3.1)
    android开发我的新浪微博客户端-OAuth篇(2.1)
    android开发我的新浪微博客户端-载入页面sqlite篇(1.2)
    android开发我的新浪微博客户端-载入页面UI篇(1.1)
    android 强制设置横屏 判断是横屏还是竖屏
    android 各种进度条(ProgressBar)
    android:百度地图-给地图添加标注物
    android应用与服务的通信之学生查询系统案例源码
    android手机多线程断点续传下载器案例源码
    android外拨电话拦截器,完整源码
  • 原文地址:https://www.cnblogs.com/skj0330insn/p/10287816.html
Copyright © 2011-2022 走看看