免費的無紡布手提袋在線報價,輸入規格參數,全程10秒鐘出價格,方便快捷,歡迎使用!
無紡布廠家15838056980日常開發中,我們需要給用戶發送操作驗證碼或者其他一些群發消息通知之類的短信。這時候一般都是使用大廠提供的短信接口,阿里云或者騰訊云等短信接口。今天我們來看看騰訊云短信接口的調用。 短信構成:普通短信一般由2兩部分構成,簽名和正文,正文里包含了變量 例如:[騰訊云]你的驗證碼是:。“騰訊云”就是你申請的簽名,“你的驗證碼是:”是正文.""是變量,個人認證用戶創建的短信正文模板每個變量取值最多支持12個字,企業用戶沒有限制。變量可以是多個按照的順序,我們在發送的時候按照變量順序將參數傳入就可以了。 1.注冊騰訊云(需要實名驗證,個人可以注冊)并且注冊贈送100條 2.創建簽名(必須先創建簽名) 個人申請簽名的支持APP、網站、、小程序.需要提供后臺的截圖,如小程序的話需要提供小程序管理后臺的截圖如: 3.創建短信模板 這里我們使用:為您的登錄驗證碼,請于分鐘內填寫。如非本人操作,請忽略本短信。為模板。 4.構建工具類 1.取得你賬號騰訊云的SecretId和SecretKey 點擊右上角賬戶圖標然后選擇賬戶信息,選擇左側訪問管理,點擊訪問密鑰,API密鑰管理 2.取得應用ID 3.工具類 添加依賴: 工具類: import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.sms.v.SmsClient; import com.tencentcloudapi.sms.v.models.*; public class TxSendSmsUtil { private static String SecretId= "你的SecretId"; private static String SecretKey = "你的SecretKey"; //接口地址 private static String smsapiurl = "sms.tencentcloudapi.com"; //短信模板ID private static String TemplateID = "你的模板ID"; //短信簽名 private static String Sign = "你的簽名"; // 短信應用 SDK AppID,SDK AppID 以1400開頭 private static String SmsSdkAppid = "你的應用ID"; /** * 短信發送工具類 * @param phoneNumber接收的手機號碼 * @param templateParam模板中變量參數 * @return */ public static String txSendSms(String[] phoneNumber,String[] templateParam) { try{ Credential cred = new Credential(SecretId, SecretKey); HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint(smsapiurl); ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); SmsClient client = new SmsClient(cred, "", clientProfile); SendSmsRequest req = new SendSmsRequest(); String[] phoneNumberSet1 = phoneNumber; req.setPhoneNumberSet(phoneNumberSet1); req.setTemplateID(TemplateID); req.setSign(Sign); String[] templateParamSet1 = templateParam; req.setTemplateParamSet(templateParamSet1); req.setSmsSdkAppid(SmsSdkAppid); SendSmsResponse resp = client.SendSms(req); String res = SendSmsResponse.toJsonString(resp); //System.out.println(res); return res; //System.out.println(SendSmsResponse.toJsonString(resp)); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); return e.toString(); } } } 5.調用 //短信模板為:為您的登錄驗證碼,請于分鐘內填寫。如非本人操作,請忽略本短信。 String[] templateParamSet1 = new String[]{ "",//對用模板;//對應模板;//需要在號碼前加入”+86“,可在工具類中處理 TxSendSmsUtil.txSendSms(phoneNumberSet1,templateParamSet1);//調用返回是字符串 用戶接收的信息: 【你的簽名】為您的登錄驗證碼,請于3分鐘內填寫。如非本人操作,請忽略本短信。 至此基礎的發送功能已經實現,下次再寫容錯、重試和群發的處理。

添加微信好友, 獲取更多信息
復制微信號
網友評論
最新評論