1. 程式人生 > >阿里大於 DEMO(java)

阿里大於 DEMO(java)

package com.FangBianMian.utils;



import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;


public class AlidayuSMS {

public static void main(String[] args) {

//官網的URL, http請求就用這個連結
String url = "http://gw.api.taobao.com/router/rest";
//成為開發者,建立應用後系統自動生成
String appkey = "xxxx";
String secret = "xxxxxxxxxxxx";
//簡訊內容,請參照阿里大於文件中心的   接入指南 -》應用開發
String json = JsonUtil.toJson(new AlidayuSMSBean());

TaobaoClient client=new DefaultTaobaoClient(url,appkey,secret);
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
req.setExtend("123456"); //可選, 用於標識使用者
req.setSmsType("normal"); //預設使用 normal
req.setSmsFreeSignName("xxxx"); //簡訊簽名
req.setSmsParam(json); //簡訊內容
req.setSmsTemplateCode("SMS_xxxxxx"); //簡訊模板ID
req.setRecNum("183xxxxxxxx");//手機號碼,如果是多個手機號碼可以用逗號隔開

try{
AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
}catch(Exception e){
System.out.println("連線失敗");
}
}
}