阿里巴巴发送短信接口的使用

1、与阿里巴巴谈个生意,申请阿里巴巴的短信服务。这个我就不写了,按照阿里巴巴官网的申请步骤,一步一步,不会了打阿里巴巴的客服电话。
2、复制一下代码:

/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 功能描述:
 * @Package: com.newtouch.modules.sys.utils 
 * @author: admin   
 * @date: 2019年5月17日 下午3:13:23 
 */
package com.newtouch.modules.sys.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * Copyright: Copyright (c) 2019 LanRu-Caifu
 * 
 * @ClassName: SendSMSUtils.java
 * @Description: alibaba发送短信
 * @version: v1.0.0
 * @author: admin
 * @date: 2019年5月17日 下午3:13:23
 */
public class SendSMSUtils {
	private final static String accessKeyId = "";// 你的accessKeyId
	private final static String accessKeySecret = "";// 你的accessKeySecret
	private final static String signName = "";你的signName

	public static String sendSMS(String phoneNumber, String templateParam, String templateCode) {
		    DefaultProfile profile = DefaultProfile.getProfile("default", accessKeyId, accessKeySecret);
	        IAcsClient client = new DefaultAcsClient(profile);

	        CommonRequest request = new CommonRequest();
	        //request.setProtocol(ProtocolType.HTTPS);
	        request.setMethod(MethodType.POST);
	        request.setDomain("dysmsapi.aliyuncs.com");
	        request.setVersion("2017-05-25");
	        request.setAction("SendSms");
	        request.putQueryParameter("SignName", signName);
	        request.putQueryParameter("PhoneNumbers", phoneNumber);
	        request.putQueryParameter("TemplateCode", templateCode);
	        request.putQueryParameter("TemplateParam", templateParam);
	        CommonResponse response = null;
	        try {
	            response = client.getCommonResponse(request);
	        } catch (ServerException e) {
	            e.printStackTrace();
	        } catch (ClientException e) {
	            e.printStackTrace();
	        }
	        System.out.println(response.getData());
	        return response.getData();
	    }
	}

3、调用接口:
String templateParam = “{name:”"+applyOnline.getName()+""}";
SendSMSUtils.sendSMS(applyOnline.getMobilephone(), templateParam, “你的templateCode”);
**注:**上面穿的参数,除了电话和参数是你自己的,其他的都是在阿里巴巴的短信平台生成的。要使用这个服务,你的服务必须能访问外网,不能访问外网,就要考虑其他方式实现。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值