码迷,mamicode.com
首页 > 其他好文 > 详细

容联七陌短信/验证码

时间:2019-01-18 15:36:29      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:分享   ESS   developer   ima   iba   短信发送   alt   cut   image   

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());
	}
	
}

  

 

容联七陌短信/验证码

标签:分享   ESS   developer   ima   iba   短信发送   alt   cut   image   

原文地址:https://www.cnblogs.com/skj0330insn/p/10287816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!