生活随笔
收集整理的這篇文章主要介紹了
阿里巴巴发送短信接口的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 = "";// 你的accessKeyIdprivate final static String accessKeySecret = "";// 你的accessKeySecretprivate final static String signName = "";你的signNamepublic 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”);
**注:**上面穿的參數,除了電話和參數是你自己的,其他的都是在阿里巴巴的短信平臺生成的。要使用這個服務,你的服務必須能訪問外網,不能訪問外網,就要考慮其他方式實現。
總結
以上是生活随笔為你收集整理的阿里巴巴发送短信接口的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。