package com.odcc.cpzidc.common.utils.sms;
|
|
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.mzlion.easyokhttp.HttpClient;
|
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLEncoder;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class SMSYUnPian {
|
|
|
/**
|
* 用户登记验证码
|
* @param mobile
|
* @param code
|
* @param language
|
* @return
|
* @throws UnsupportedEncodingException
|
*/
|
public static Integer sendVerificationCode(String mobile,String code,String language) throws UnsupportedEncodingException {
|
String tpl_id = "5921370";
|
if(language.equals("zh")){
|
tpl_id = "5921370";
|
}else if(language.equals("en")){
|
tpl_id = "5921464";
|
}else if(language.equals("ru")){
|
tpl_id = "5921466";
|
}
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("apikey", "c92bf9680de6e2df1644bb517815c4a6");
|
params.put("mobile", mobile);
|
params.put("tpl_id", tpl_id);
|
params.put("tpl_value", URLEncoder.encode("#code#", "utf-8") + "=" + URLEncoder.encode(code, "utf-8") );
|
String responseData = HttpClient
|
// 请求方式和请求url
|
.post("https://sms.yunpian.com/v2/sms/tpl_single_send.json")
|
// 表单参数
|
.param(params)
|
//url参数
|
.asString();
|
JSONObject jsonObject = JSON.parseObject(responseData);
|
System.out.println(responseData);
|
return jsonObject.getInteger("code");
|
}
|
|
|
/**
|
* 用户登记验证码
|
* @param mobile
|
* @param name
|
* @param language
|
* @return
|
* @throws UnsupportedEncodingException
|
*/
|
public static Integer sendRegSuccess(String mobile,String name,String language) throws UnsupportedEncodingException {
|
String tpl_id = "5921300";
|
if(language.equals("zh")){
|
tpl_id = "5921300";
|
}else if(language.equals("en")){
|
tpl_id = "5921302";
|
}else if(language.equals("ru")){
|
tpl_id = "5921466";
|
}
|
Map<String, String> params = new HashMap<String, String>();
|
params.put("apikey", "c92bf9680de6e2df1644bb517815c4a6");
|
params.put("mobile", mobile);
|
params.put("tpl_id", tpl_id);
|
params.put("tpl_value", URLEncoder.encode("#name#", "utf-8") + "=" + URLEncoder.encode(name, "utf-8") );
|
String responseData = HttpClient
|
// 请求方式和请求url
|
.post("https://sms.yunpian.com/v2/sms/tpl_single_send.json")
|
// 表单参数
|
.param(params)
|
//url参数
|
.asString();
|
JSONObject jsonObject = JSON.parseObject(responseData);
|
return jsonObject.getInteger("code");
|
}
|
|
public static void main(String args[]) throws UnsupportedEncodingException {
|
System.out.println(sendVerificationCode("18612580880","38383","zh"));
|
// System.out.println(sendRegSuccess("18612580880","38383","zh"));
|
}
|
|
|
}
|