亿美软通短信

最近公司在用亿美软通短信,这个整体下来感觉不错。文档写的也很清晰,整合起来也不费事。下面来介绍一下整合步骤;

首先找到相关的网站,需要向管理人员获取相关的账号(appId)和秘钥(secretkey16位)
然后下面是
国内接口http标准协议文档和demo的地址:
http://www.b2m.cn/static/doc/sms/onlysms_or.html
接口的url地址:
http://bjmtn.b2m.cn(北京地址)
http://shmtn.b2m.cn (上海地址)
http://gzmtn.b2m.cn (广州地址)

读懂相关文档,整合相关代码

这里可以查看相关的接口文档,在工作需求中大多会用到单发短信和批量发送。
这个官网上也附带有相关的短信 demo ,有C有Java有PHP,这里我们只看JAVA。

整合接口,根据demo进行整理

这些都是软通的工具类 其中有各种加密的方式等等的封装,其中
这些是调用各种短信的例子demo,调用时可以查看。

整合项目,实现短信发送,首先在整合时需要查看一些注意事项

必要参数appId,secretKey需向亿美软通获取默认UTF-8字符集,默认不进行GZip压缩获取上行和扩展码需账号支持支持短信单发,群发,获取账号短信剩余条数,获取状态报告,上行单发短信支持自定义信息id,与扩展码,群发支持扩展码项目是对亿美软通demo进行简单封装方便使用PS,短信内容必须带上类似此【前缀】,否则无法发送成功(运营商要求)PS,短信内容含有群发等非法关键字也无法正常发送本包依赖一个gson-2.6.2.jar


MAVEN项目时 ,需引用

 <dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.4</version></dependency>

接下来只需要写一个工具类就可以了,
这些是demo里可以取出来需要取出来。下面是简单的需要的工具类的例子

@Component
public class EmaySMSUtils {// appIdprivate static String appId = "EUCP-EMY-SMS0-27TIT ";//需要向软通获取// 密钥private static String secretKey = "LB663MSJC8W51LET";// 需要向软通获取// 接口地址private static String host = "http://bjmtn.b2m.cn";// 北京接口// 加密算法private static String algorithm = "AES/ECB/PKCS5Padding";// 编码private static String encode = "UTF-8";// 是否压缩private static Boolean isGzip = true;/*** 发送单条短信  这里R是我所用的架构 封装的 需要什么可以更改*/public static R sendSingleSms(String content, String mobile){Boolean flag =checkKeyParam(content,mobile);SysMail sysMail = new SysMail();if(flag){content ="【测试】"+content;try {       SmsResponse smsResponse = setSingleSms(appId, secretKey, host, algorithm, content, null, null, mobile, isGzip, encode);return R.ok("发送成功!");}catch (Exception exception){return R.fail("发送失败!");}}else{return R.fail("发送失败!");}}/*** @描述 群发短信不需要扩展码* @参数 @param content* @参数 @param mobiles* @参数 @return* @return SmsResponse[]*/public static R sendBatchOnlySms(String content, String[] mobiles){Boolean flag =checkKeyParam(appId,secretKey,mobiles);SysMail sysMail = new SysMail();if(flag){try {content ="【测试】"+content;//调用批量发送SmsResponse[] smsResponses = setBatchOnlySms(appId, secretKey, host, algorithm, content, null, mobiles, isGzip, encode);return R.ok("发送成功!");}catch (Exception exception){return R.fail("发送失败!");}}else{return R.fail("发送失败!");}}/*** 发送单条短信** @param isGzip*            是否压缩* @param content*             内容*/private static SmsResponse setSingleSms(String appId, String secretKey, String host, String algorithm, String content, String customSmsId, String extendCode, String mobile, boolean isGzip, String encode) {Boolean flag = checkKeyParam(appId, secretKey, mobile);if (flag) {System.out.println("=============begin setSingleSms==================");SmsSingleRequest pamars = new SmsSingleRequest();pamars.setContent(content);pamars.setCustomSmsId(customSmsId);pamars.setExtendedCode(extendCode);pamars.setMobile(mobile);ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendSingleSMS", isGzip, encode);System.out.println("result code :" + result.getCode());if ("SUCCESS".equals(result.getCode())) {SmsResponse response = JsonHelper.fromJson(SmsResponse.class, result.getResult());if (response != null) {System.out.println("data : " + response.getMobile() + "," + response.getSmsId() + "," + response.getCustomSmsId());}return response;}System.out.println("=============end setSingleSms==================");return null;} else {System.out.println("=============param check error==================");return null;}}/*** 发送批次短信** @param isGzip*            是否压缩*/private static SmsResponse[] setBatchOnlySms(String appId, String secretKey, String host, String algorithm, String content, String extendCode, String[] mobiles, boolean isGzip, String encode) {Boolean flag = checkKeyParam(appId, secretKey, mobiles);if (flag) {System.out.println("=============begin setBatchOnlySms==================");SmsBatchOnlyRequest pamars = new SmsBatchOnlyRequest();pamars.setMobiles(mobiles);pamars.setExtendedCode(extendCode);pamars.setContent(content);ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendBatchOnlySMS", isGzip, encode);System.out.println("result code :" + result.getCode());if ("SUCCESS".equals(result.getCode())) {SmsResponse[] response = JsonHelper.fromJson(SmsResponse[].class, result.getResult());if (response != null) {for (SmsResponse d : response) {System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());}}return response;}System.out.println("=============end setBatchOnlySms==================");return null;} else {System.out.println("=============param check error==================");return null;}}@PostConstruct // 初始化public void init(){emaySMSUtils = this;emaySMSUtils.iSysMailService = this.iSysMailService;}/**** @描述 校验key与secret* @参数 @param appId* @参数 @param secretKey* @参数 @param mobile* @参数 @return* @return Boolean*/private static Boolean checkKeyParam(String appId, String secretKey) {if (null == appId || secretKey == null || appId.trim().equals("") || secretKey.trim().equals("")) {return false;}return true;}/**** @描述 校验key与secret,mobile* @参数 @param appId* @参数 @param secretKey* @参数 @param mobile* @参数 @return* @return Boolean*/private static Boolean checkKeyParam(String appId, String secretKey, String mobile) {if (null == appId || secretKey == null || mobile == null || appId.trim().equals("")|| secretKey.trim().equals("") || mobile.trim().equals("") || mobile.trim().equals("")) {return false;}return true;}/**** @描述 校验key与secret,mobiles[]* @参数 @param appId* @参数 @param secretKey* @参数 @param mobiles* @参数 @return* @return Boolean*/private static Boolean checkKeyParam(String appId, String secretKey, String[] mobiles) {if (null == appId || secretKey == null || mobiles == null || appId.trim().equals("")|| secretKey.trim().equals("") || mobiles.length == 0) {return false;}return true;}/*** 公共请求方法*/public static ResultModel request(String appId, String secretKey, String algorithm, Object content, String url, final boolean isGzip, String encode) {Map<String, String> headers = new HashMap<String, String>();HttpRequest<byte[]> request = null;try {headers.put("appId", appId);headers.put("encode", encode);String requestJson = JsonHelper.toJsonString(content);System.out.println("result json: " + requestJson);byte[] bytes = requestJson.getBytes(encode);System.out.println("request data size : " + bytes.length);if (isGzip) {headers.put("gzip", "on");bytes = GZIPUtils.compress(bytes);System.out.println("request data size [com]: " + bytes.length);}byte[] parambytes = AES.encrypt(bytes, secretKey.getBytes(), algorithm);System.out.println("request data size [en] : " + parambytes.length);HttpRequestParams<byte[]> params = new HttpRequestParams<byte[]>();params.setCharSet("UTF-8");params.setMethod("POST");params.setHeaders(headers);params.setParams(parambytes);params.setUrl(url);if (url.startsWith("https://")) {request = new HttpsRequestBytes(params, null);} else {request = new HttpRequestBytes(params);}} catch (Exception e) {System.out.println("加密异常");e.printStackTrace();}HttpClient client = new HttpClient();String code = null;String result = null;try {HttpResponseBytes res = client.service(request, new HttpResponseBytesPraser());if (res == null) {System.out.println("请求接口异常");return new ResultModel(code, result);}if (res.getResultCode().equals(HttpResultCode.SUCCESS)) {if (res.getHttpCode() == 200) {code = res.getHeaders().get("result");if (code.equals("SUCCESS")) {byte[] data = res.getResult();System.out.println("response data size [en and com] : " + data.length);data = AES.decrypt(data, secretKey.getBytes(), algorithm);if (isGzip) {data = GZIPUtils.decompress(data);}System.out.println("response data size : " + data.length);result = new String(data, encode);System.out.println("response json: " + result);}} else {System.out.println("请求接口异常,请求码:" + res.getHttpCode());}} else {System.out.println("请求接口网络异常:" + res.getResultCode().getCode());}} catch (Exception e) {System.out.println("解析失败");e.printStackTrace();}ResultModel re = new ResultModel(code, result);return re;}/**** @描述   获取剩余短信条数* @参数 @param appId* @参数 @param secretKey* @参数 @return* @return Long*/public static Long getBalance(String appId, String secretKey) {Boolean flag = checkKeyParam(appId, secretKey);if (flag) {System.out.println("=============begin getBalance==================");BalanceRequest pamars = new BalanceRequest();ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/getBalance",isGzip, encode);System.out.println("result code :" + result.getCode());if ("SUCCESS".equals(result.getCode())) {BalanceResponse response = JsonHelper.fromJson(BalanceResponse.class, result.getResult());if (response != null) {System.out.println("result data : " + response.getBalance());System.out.println("=============end getBalance==================");return response.getBalance();}}System.out.println("=============end getBalance==================");return null;} else {System.out.println("=============param check error==================");return null;}}public static void main(String[] args) {Long balance = getBalance(appId, secretKey);System.out.print("====剩余短信条数:  "+"\033[0;31m"+balance+"条");}}

看这demo写的话,其实很容易。有需要的可以私聊我!!!

亿美软通 短信接口整合(JAVA)相关推荐

  1. 亿美软通短信发送----PHP版本

    <?php /*** Created by PhpStorm.* User: kung* Date: 18-1-26* Time: 上午10:41*/ class Ymsms {private ...

  2. 亿美软通年终短信最强大促 送三重好礼

    秋风飘至,落叶纷飞,天气已经渐凉,APEC也在北京召开了,然而在电商领域却是一派热火朝天,淘宝双11的571亿当天交易额已经过去,马上就要准备12.12电商狂欢,年底的圣诞元旦,可谓马不停蹄.亿美软通 ...

  3. 亿美软通一键登录升级:扩大适用范围、更高安全保障

    时至今日,一键登录已不再是开发人员的"新宠",随着越来越多APP的应用,也在用户心中形成愈发强烈的感知:相比传统身份核验方式,一键登录的确"快"出了新速度. 一 ...

  4. 媒体报道 | 亿美软通以诚信之心 守护信息安全

    北京亿美软通科技有限公司(以下简称"亿美软通")是一家具备国际水准的移动商务平台技术和应用方案提供商.自2001年成立以来,亿美软通始终坚持诚信为本,致力于为国内外企业提供具备国际 ...

  5. 亿美软通参与编制,《5G消息业务显示规范》等团标正式发布

    近日,中国通信企业协会发布公告,正式发布<5G消息业务显示规范>.<Chatbot名称规范>.<双卡5G消息终端技术规范>等团体标准,自2022年9月15日起实施. ...

  6. 亿美软通打造5G消息精品案例,覆盖多垂直电商领域

    近日,亿美软通在5G消息行业探索上传佳音.亿美软通20余款电商行业5G消息应用在中国移动5G消息应用专区上架,已覆盖多垂直领域零售电商业务的全流程场景. 打造电商零售行业 5G消息精品案例 亿美软通在 ...

  7. 亿美软通张翀:安全性是5G消息区别于其他OTT的关键优势

    2021年12月21-22日,"2021中国增值电信及虚拟运营高峰论坛"在北京拉开帷幕,活动以"5G融合通信趋势下的技术创新"为主题,共同探讨未来5G融合通信趋 ...

  8. PT展揭晓“2021年中国5G实力榜”,亿美软通入围“5G消息企业十强”

    2021年中国国际信息通信展览会(以下简称PT展)在京开幕,ICT领域新兴技术和应用创新成果汇聚亮相,展现出5G赋能千行百业的生态繁荣. 5G消息进展:已集纳近600项服务 一年一度的PT展历来作为I ...

  9. 吉信通短信接口(HTTP协议) java

    最近学习了吉信通接口的内容,做了简单的短信对接功能.和大家分享一下吉信通短信接口(HTTP协议).吉信通官网上也有相关的代码示例. 吉信通官网:http://www.winic.org/api/Sen ...

最新文章

  1. 【转载】浏览器事件循环机制(event loop)
  2. 集合的hashCode方法的最佳实现
  3. linux中w命令参数详解
  4. 【转】C# HttpWebRequest 异常时获取 HttpWebResponse 数据
  5. 宋体配置JAVA j2ee (一) 轻松入门
  6. 7-3 对整型数据排序 (15 分)
  7. qtableview选中第一行时表头会变色_超新颖的Word目录制作法,包你一看就会!【Word教程】...
  8. SharePoint 2013 Step by Step——How to Create a Lookup Column to Another Site(Cross Site) 阅读目录...
  9. 如何系统地学习数据挖掘
  10. HTML-参考手册: HTML 符号实体
  11. word查重_医学论文查重参考文献算不算?
  12. Newcoder lxh裁木棍 (不开long double见祖宗 ceil前不加long long也去
  13. EventListenerTouchOneByOne::create() 单点触摸
  14. MarkDown学习备忘录
  15. indesign选中不了图片删除_word图文设计:如何用图片水印功能制作日历画册
  16. Android 动态分区详解(六) 动态分区的底层机制
  17. 第7课:郭盛华课程_Linux系统的常用操作命令
  18. javamail连接gmail邮箱时报错:javax.mail.AuthenticationFailedException
  19. c语言控制台数字键打地鼠,C语言编程打地鼠
  20. C语言问题:0xC0000005: 写入位置 0xFFFFFFCC 时发生访问冲突。

热门文章

  1. 使用记事本编写Java程序的运行步骤及乱码问题
  2. oracle 中将number类型的数据转化成指定格式的小数
  3. 什么是UTM参数?这些你知道吗
  4. Java NIO(三)通道Channel
  5. 猪哥学习群直播第一期:人工智能在银行电信企业中的应用
  6. 各种wifi共享妙招汇总
  7. TRUNK端口的配置实验
  8. 有苦有乐的算法 --- 一个无序数组,如果从小到大排好序,任何一个元素任何一个元素移动索引长度不超过k,实现排序
  9. 无法安装或运行此应用程序。该应用程序要求首先在全局程序集缓存(GAC)中安装程序集
  10. GBDC2017全球大数据峰会