阿里雲獲取簡訊驗證碼案列

2021-09-25 22:00:23 字數 4434 閱讀 9547

1,整合的springboot框架,以使用者註冊為列

@apioperation(value = "使用者註冊", notes = "使用者註冊")

@transactional(rollbackfor = exception.class)

public returninfo register(@apiparam(name = "userregister",value = "使用者註冊資訊",required = true)

//判斷手機號是否已註冊

userinfo reguserinfo = userinfoservice.getuserinfobyphone(phone);

if(reguserinfo != null)

if(!stringutil.hasvalue(smscode))

if(smscode.length() != 4)

//校驗驗證碼

//隨機暱稱

string nickname = stringutil.randomnumstr(8);

userinfo.setnickname(nickname);

userinfo.setupdatetime(new date());

//設定使用者型別為普通使用者

userinfo.setusertype("1");

//初始化賬戶資訊

useraccount useraccount = new useraccount();

useraccount.setamount(new double(0));

//通過裝置號獲取使用者資訊

userinfo userinforesult = userinfoservice.getuserinfobydeviceno(deviceno);

if(userinforesult != null)else

//初始化賬戶

accountservice.adduseraccount(useraccount);

//修改使用者註冊資訊

}

二.獲取簡訊驗證碼

@apioperation(value = "獲取簡訊驗證碼", notes="獲取簡訊驗證碼")

public returninfogetsmscode(@apiparam(name = "phone", value = "手機號碼", required = true) @pathvariable string phone)

if(!validateutils.isphone(phone))

string cachecode = redisservice.getredisservice().get(rediskeyconstants.smscode_cache+phone);

if(stringutil.hasvalue(cachecode))

return smsutil.sendsmscode(phone);

}

三.傳送簡訊驗證碼

/**

* 傳送簡訊驗證碼

** @param phone

* @return

*/public static returninfosendsmscode(string phone)

}// 簡訊傳送成功

if(sendflag)

return returninfo.getinstance().setresult(errorcodeenum.sms_code_fail).setdata(null);

}/**

* 阿里雲簡訊傳送

* @param smsoperatormap

* @return

*/private static boolean aliyunsendsms(mapsmsoperatormap));

list> msgmouldlist = ( list>) smsoperatormap.get("msgmouldlist");

msgmouldlist.stream().foreach((msgmouldmap) -> ", true);

string array = result.toarray(new string[0]);

templateparam.put(array[0],smsoperatormap.get("code").tostring());

map.put("templateparam",jsonutil.objecttostring(templateparam));

}});

defaultprofile profile = defaultprofile.getprofile(map.get("regionid"),map.get("accesskeyid"),map.get("secret"));

iacsclient client = new defaultacsclient(profile);

commonrequest request = new commonrequest();

request.setmethod(methodtype.post);

request.setdomain("dysmsapi.aliyuncs.com");

request.setversion("2017-05-25"); //api版本號

request.setaction("sendsms");

request.putqueryparameter("regionid", map.get("regionid"));

request.putqueryparameter("phonenumbers", smsoperatormap.get("phone").tostring());

request.putqueryparameter("signname", map.get("signname"));

request.putqueryparameter("templatecode", map.get("templatecode"));

request.putqueryparameter("templateparam", map.get("templateparam"));

try

}} catch (serverexception e) catch (clientexception e)

return false;

}

四.可以用在使用者註冊上進行手機號碼的校驗

阿里雲簡訊驗證碼開發

首先需要在阿里雲上開通簡訊服務,然後在accesskey裡面 設定使用者和使用者組,並把使用者加入到使用者組裡面 然後建立乙個key 密碼一定要事先記住,後面是不會在顯示密碼的 然後在使用者組裡面新增簡訊許可權管理 再去簡訊服務裡面新增簽名和模板 一定要注意用詞,不然阿里不會通過的 到這裡所需阿里的...

阿里雲簡訊服務的使用 獲取簡訊驗證碼

美多 先獲取redis 的圖 驗證碼來 對 redis cli get redis connection img code redis img code redis cli.get image code uuid decode print redis img code print image cod...

阿里雲簡訊服務的使用 獲取簡訊驗證碼

美多 先獲取redis 的圖 驗證碼來 對 redis cli get redis connection img code redis img code redis cli.get image code uuid decode print redis img code print image cod...