短信營(yíng)銷接口文檔 點(diǎn)擊下載
短信營(yíng)銷接口接入指南 點(diǎn)擊訪問
// 接口類型:互億無(wú)線營(yíng)銷短信批量發(fā)送DEMO
// 賬戶注冊(cè):請(qǐng)通過該地址開通賬戶 http://user.ihuyi.com/
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import util.StringUtil;
public class sendsms {
private static String Url = "http://api.ihuyi.com/sms-yx/v1/batchSend";
public static void main(String [] args) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(Url);
client.getParams().setContentCharset("UTF-8");
method.setRequestHeader("ContentType", "application/json;charset=UTF-8");
// 需要修改的參數(shù)-開始
String api_id = "sms-xxxxxxxx";
String api_key = "xxxxxxxxxxxxxxxxxxx";
String[] phone = {"1366197xxxx","1366197xxxx"};
String sign_name = "互億無(wú)線";
int product_id = 1018;
String content = new String("您好,短信內(nèi)容,回T退訂");
// 需要修改的參數(shù)-結(jié)束
long timest = System.currentTimeMillis() / 1000;
String timestamp = "" + timest;
String request_id = timestamp + (int)((Math.random()*9+1)*100000);
// 生成sign方式一
// Map<String, String> map = new HashMap<String,String>();
// map.put("api_id", api_id);
// map.put("api_key", api_key);
// map.put("request_id", request_id);
// map.put("timestamp", ""+timest);
// String sign = StringUtil.getSign(map);
// System.out.println(sign);
// 生成sign方式二
String sig = "api_id=" + api_id + "&api_key=" + api_key + "&request_id=" + request_id + "×tamp=" + timest;
// System.out.println(sign);
String sign = StringUtil.MD5Encode(sig).toLowerCase();
JSONObject data = new JSONObject();
data.put("api_id", api_id);
data.put("signature", sign);
data.put("phone", phone);
data.put("sign_name", sign_name);
data.put("request_id", request_id);
data.put("timestamp", timest);
data.put("product_id", product_id);
data.put("send_time", "");
data.put("content", content);
// String arrStr = JSON.toJSONString(data);
String objStr = JSON.toJSONString(data);
System.out.println(data);
method.setRequestBody(objStr);
try {
client.executeMethod(method);
String SubmitResult =method.getResponseBodyAsString();
// System.out.println(SubmitResult);
JSONObject obj = JSON.parseObject(SubmitResult);
System.out.println(obj);
if("OK".equals(obj.getString("code"))){
System.out.println("短信提交成功");
}else{
System.out.println("短信提交失敗");
}
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
// Release connection
method.releaseConnection();
// client.getConnectionManager().shutdown();
}
}
}
驗(yàn)證碼已發(fā)送到您的手機(jī),請(qǐng)查收!
輸入驗(yàn)證碼后,點(diǎn)擊“開通體驗(yàn)賬戶”按鈕可立即開通體驗(yàn)賬戶。