短信验证码
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.peanut.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bcloud.msg.http.HttpSender;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@@ -9,6 +8,7 @@ import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@Component
|
||||
public class SmsUtil {
|
||||
@@ -31,22 +31,25 @@ public class SmsUtil {
|
||||
private String abroadContent;
|
||||
|
||||
public R sendSmsCode(String phone, String code) {
|
||||
String mobiles = phone;//手机号码,多个号码使用","分割
|
||||
boolean needstatus = true;//是否需要状态报告,需要true,不需要false
|
||||
String product = "";//产品ID
|
||||
String extno = "";//扩展码
|
||||
String respType = "json";//返回json格式响应
|
||||
boolean encrypt = true;// 密码使用时间戳加密
|
||||
try {
|
||||
String returnString = HttpSender.send(url, account, pswd, mobiles, content.replace("XXXXXX",code), needstatus, product, extno, respType, encrypt);
|
||||
//{"result":108,"ts":"20250416115415"}
|
||||
//{"result":0,"msgid":"2150416115442493200","ts":"20250416115442"}
|
||||
JSONObject object = JSONObject.parseObject(returnString);
|
||||
if ("0".equals(object.get("result").toString())){
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
StringEntity entity = new StringEntity("" +
|
||||
"account="+account+
|
||||
"&pswd="+pswd+
|
||||
"&mobile="+phone+
|
||||
"&msg="+ URLEncoder.encode(content.replace("XXXXXX",code), "UTF-8")+
|
||||
"&needstatus=false");
|
||||
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
httpPost.setEntity(entity);
|
||||
String returnString = EntityUtils.toString(client.execute(httpPost).getEntity());
|
||||
//20250416115415,0
|
||||
String[] res = returnString.split(",");
|
||||
if ("0".equals(res[1])){
|
||||
return R.ok();
|
||||
}else if ("104".equals(object.get("result").toString())){
|
||||
}else if ("104".equals(res[1])){
|
||||
return R.error("短信平台系统忙,请稍后重试。");
|
||||
}else if ("107".equals(object.get("result").toString())){
|
||||
}else if ("107".equals(res[1])){
|
||||
return R.error("错误的手机号码。");
|
||||
}else {
|
||||
return R.error("系统错误,请联系管理员");
|
||||
|
||||
Reference in New Issue
Block a user