|
|
@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.hai.common.Base64Util; |
|
|
|
import com.hai.common.Base64Util; |
|
|
|
|
|
|
|
import com.hai.common.security.VerifyCode; |
|
|
|
|
|
|
|
import com.hai.common.security.VerifyCodeStorage; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.entity.BsCompany; |
|
|
|
import com.hai.entity.BsCompany; |
|
|
|
import com.hai.entity.SecRegion; |
|
|
|
import com.hai.entity.SecRegion; |
|
|
|
import com.hai.model.ResponseData; |
|
|
|
import com.hai.model.ResponseData; |
|
|
|
|
|
|
|
import com.hai.service.CommonService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import netscape.javascript.JSObject; |
|
|
|
import netscape.javascript.JSObject; |
|
|
@ -22,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
@ -37,40 +41,49 @@ public class SmsContentController { |
|
|
|
private static Logger log = LoggerFactory.getLogger(CmsContentController.class); |
|
|
|
private static Logger log = LoggerFactory.getLogger(CmsContentController.class); |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) |
|
|
|
@RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) |
|
|
|
@ApiOperation(value = "发生短信验证码") |
|
|
|
@ApiOperation(value = "发送短信验证码") |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) { |
|
|
|
public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); |
|
|
|
Map<String,Object> map = new LinkedHashMap<>(); |
|
|
|
String smsCode; |
|
|
|
map.put("", "88200409698"); |
|
|
|
if (verifyCode != null){ |
|
|
|
map.put("to", phone); |
|
|
|
smsCode = verifyCode.getObject(); |
|
|
|
map.put("templateId", "f42261f78d54488391f1d1ac4bd5bd3f"); |
|
|
|
}else{ |
|
|
|
ArrayList<Object> list = new ArrayList<>(); |
|
|
|
// 生成随机6位验证码
|
|
|
|
list.add(phone); |
|
|
|
smsCode = String.valueOf(new Random().nextInt(899999) + 100000); |
|
|
|
map.put("signature", "嗨森逛"); |
|
|
|
} |
|
|
|
|
|
|
|
String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + smsCode +"\"]"; |
|
|
|
String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + 123456 +"\"]"; |
|
|
|
|
|
|
|
//JSON.toJSONString(map);
|
|
|
|
|
|
|
|
Map<String,Object> body = new LinkedHashMap<>(); |
|
|
|
Map<String,Object> body = new LinkedHashMap<>(); |
|
|
|
body.put("from", param); |
|
|
|
body.put("from", param); |
|
|
|
|
|
|
|
|
|
|
|
String nonce = UUID.randomUUID().toString(); |
|
|
|
String nonce = UUID.randomUUID().toString(); |
|
|
|
String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); |
|
|
|
String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")); |
|
|
|
|
|
|
|
System.out.println(Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ"))); |
|
|
|
|
|
|
|
String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "=="; |
|
|
|
String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "=="; |
|
|
|
|
|
|
|
|
|
|
|
// 9CWFv4NlaRX49n43VPA6eucZ8xeQ
|
|
|
|
|
|
|
|
Map<String,Object> header = new LinkedHashMap<>(); |
|
|
|
Map<String,Object> header = new LinkedHashMap<>(); |
|
|
|
header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""); |
|
|
|
header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""); |
|
|
|
header.put("X-WSSE", "UsernameToken Username=\"QR5eMVrcW0Md6r634M6tf2i34cvb\",PasswordDigest=\""+passwordDigest+"\",Nonce=\""+nonce+"\",Created=\""+created+"\""); |
|
|
|
header.put("X-WSSE", "UsernameToken Username=\"QR5eMVrcW0Md6r634M6tf2i34cvb\",PasswordDigest=\""+passwordDigest+"\",Nonce=\""+nonce+"\",Created=\""+created+"\""); |
|
|
|
System.out.println(header.get("X-WSSE")); |
|
|
|
|
|
|
|
JSONObject object = HttpsUtils.doSmsPost("https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1", body,header); |
|
|
|
JSONObject object = HttpsUtils.doSmsPost("https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1", body,header); |
|
|
|
|
|
|
|
String code = object.getString("code"); |
|
|
|
|
|
|
|
if (code.equals("000000")) { |
|
|
|
|
|
|
|
verifyCode = new VerifyCode(phone,smsCode); |
|
|
|
|
|
|
|
VerifyCodeStorage.save(verifyCode); |
|
|
|
|
|
|
|
return ResponseMsgUtil.success("发送成功"); |
|
|
|
|
|
|
|
} |
|
|
|
return ResponseMsgUtil.success(object); |
|
|
|
return ResponseMsgUtil.success(object); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("CmsContentController --> getCorporateAdvertising() error!", e); |
|
|
|
log.error("CmsContentController --> sendSmsCode() error!", e); |
|
|
|
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getSmsCode", method = RequestMethod.GET) |
|
|
|
|
|
|
|
@ApiOperation(value = "发送短信验证码") |
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
public ResponseData getSmsCode(@RequestParam(value = "phone", required = true) String phone) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return ResponseMsgUtil.success(VerifyCodeStorage.getDate(phone)); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("CmsContentController --> getSmsCode() error!", e); |
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|