自定义短信验证码
package com.ffcs.sms;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import com.ffcs.util.HttpInvoker;
import com.ffcs.util.RandomUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import open189.sign.ParamsSign;
/**
* 下发自定义短信验证码DEMO
*
*/
public class SendSMSRandcode
{
public static String APP_ID = "";//应用ID------登录平台在应用设置可以找到
public static String APP_SECRET = "";//应用secret-----登录平台在应用设置可以找到
public static String ACCESS_TOKEN = "";//访问令牌AT-------CC模式,AC模式都可,推荐CC模式获取令牌
public static String RANDCODE = RandomUtil.randomFor6();//自定义验证码
/**
* 1 获取信任码token get提交
* 2自定义短信验证码下发 post提交
* @param userPhone 下发手机号
* @return
* @throws Exception
*/
//第一步根据app_id,app_secret获取令牌接口
private static String getAccess_Token() throws Exception {
Gson gson = new Gson();
String postUrl = "https://oauth.api.189.cn/emp/oauth2/v3/access_token?grant_type=client_credentials&app_id="
+ APP_ID + "&app_secret=" + APP_SECRET;
String resJson1 = HttpInvoker.httpPost(postUrl, null, null);
System.err.println(resJson1);
Map<String, String> map1 = gson.fromJson(resJson1,
new TypeToken<Map<String, String>>() {
}.getType());
return map1.get("access_token").toString();
}
private static String sendSms(String userPhone) throws Exception {
ACCESS_TOKEN=getAccess_Token();
System.err.println(ACCESS_TOKEN);
Date date = new Date();
SimpleDateFormat dateFormat