容联七陌短信/验证码
Posted skj0330insn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了容联七陌短信/验证码相关的知识,希望对你有一定的参考价值。
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()); } }
以上是关于容联七陌短信/验证码的主要内容,如果未能解决你的问题,请参考以下文章
深化AI赋能,容联七陌入选《2022年中国对话式AI行业发展白皮书》