调用接口类:
package com.transfar.message.service;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.transfar.message.dao.MessageDao;
import net.sf.json.JSONObject;
public class MessageService {
public static void main(String[] args) {
try {
batch();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//单条发送
public static String single(String mobile) throws Exception {
Map<String, String> testMap = new HashMap<String, String>();
// Map<String, String> busParamsMap = new HashMap<String, String>();
String text = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 6);
testMap.put("text", "【XXX】验证码"+text+",您正在使用XXX,需要进行验证,请勿向任何人提供您收到的短信验证码"); //短信内容,必填项
testMap.put("mobile", mobile); //接收此条短信的手机号码,必填项mobile
testMap.put("apikey", "b3c4376e223f58477a6ff9e8b30f3d09");
testMap.put("extend", "001"); //扩展号。默认不开放,如有需要请联系客服申请 ,非必填项
testMap.put("uid", "10011"); //业务系统内的ID,非必填项
testMap.put("callback_url", "http://your_receive_url_address");//本条短信状态报告推送地址,非必填项
String url = null;
String jsonResultStr = null;
TestHttpClient client = TestHttpClient.getInstance();
url = "https://sms.yunpian.com/v2/sms/single_send.json";//单条发送短信接口
jsonResultStr = client.sendHttpPost(url, testMap);
JSONObject jsonObject = null;
if (jsonResultStr!=null){
jsonObject=JSONObject.fromObject(jsonResultStr);
String code = jsonObject.getString("code");//返回结果,0为成功
if(code.equals("0")){
int count = jsonObject.getInt("count");//计费条数,70个字一条,超出70个字时按每67字一条
double fee = jsonObject.getDouble("fee");//扣费金