123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.chinacreator.videoalliance.smc.action;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.pipe.DataOutPipe;
- import com.chinacreator.common.util.DESUtil;
- import com.chinacreator.common.util.MD5;
- import com.chinacreator.videoalliance.common.annotation.DataOut;
- import com.chinacreator.videoalliance.common.util.ConfigUtil;
- import com.chinacreator.videoalliance.order.bean.ChannelOrgBean;
- import com.chinacreator.videoalliance.order.dao.ChannelDao;
- import com.chinacreator.videoalliance.order.util.JsonUtil;
- import com.chinacreator.videoalliance.order.util.RedisCluster;
- import com.chinacreator.videoalliance.order.util.URLUtil;
- import com.chinacreator.videoalliance.smc.bean.SmsCheckBean;
- import com.chinacreator.videoalliance.smc.dao.SmsNumberDao;
- import com.chinacreator.videoalliance.smc.dao.SmsWhiteDao;
- import org.apache.commons.lang.math.NumberUtils;
- import org.apache.commons.lang.time.DateFormatUtils;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.*;
- @Controller
- public class SmsNumberAction {
-
- private static Logger logger = Logger.getLogger(SmsNumberAction.class);
- private static Logger log = Logger.getLogger("sendSms");
- @Value("${sms.error.times}")
- private String times; // = "3";
- @Autowired
- private SmsWhiteDao smsWhiteDao;
-
- @Autowired
- private ChannelDao channelDao;
- @RequestMapping({ "/smsNumber.do" })
- @DataOut(callback = "SmsNumber")
- public DataOutPipe doNet(HttpServletRequest request, HttpServletResponse response) throws Exception {
- long startTime = System.currentTimeMillis();
- String cpid = request.getParameter("cpid");
- String userid = request.getParameter("userid");
- String vcode = request.getParameter("vcode");
- final String entype = request.getParameter("entype");
- final String channel = request.getParameter("channel");
- String isvoice = request.getParameter("isvoice");//1:使用语音验证码
- String phone = "";//ConfigUtil.decrypt(userid, cpid);
- String fakePhone = ""; //ConfigUtil.getFakeid(phone, cpid);
- ChannelOrgBean channelOrgBean = null;
- if("1".equals(entype)){//渠道方接入
- channelOrgBean = channelDao.findByChannelId(channel);
- if (channelOrgBean == null || channelOrgBean.getStatus().equals("1")) {
- throw new BusinessException("9001", "渠道参数错误");
- }
- phone = DESUtil.decode(userid, channelOrgBean.getPassword());
- fakePhone = phone;
- }else{ //entype为空或为1时,合作方接入
- phone = ConfigUtil.decrypt(userid, cpid);
- fakePhone = ConfigUtil.getFakeid(phone, cpid);
- }
- logger.info("phone:"+phone+", fakePhone:"+fakePhone+", vcode:"+vcode);
- SmsNumberDao snd = new SmsNumberDao();
- DataOutPipe dop = new DataOutPipe();
- String vcpid="";
- if ("1".equals(isvoice)){
- vcpid=cpid+"isvoice";
- }else {
- vcpid=cpid;
- }
- long findTime = System.currentTimeMillis();
- SmsCheckBean smsCheckBean = snd.checkVcode(phone, vcpid);
- log.info("手机号:"+phone+"smsNumber.do查询数据库响应时间==="+(System.currentTimeMillis()-findTime)/1000);
- if (smsWhiteDao.isBlackUserCanValidate(phone, cpid)) {
- throw new BusinessException("8007", "黑名单用户,短信验证失败", new String[0]);
- }
- if(smsCheckBean == null){
- dop.add("userid", null);
- dop.setResultCode("8999");
- dop.setErrorInfo("验证码已失效");
- dop.add("flowwarn", Integer.valueOf(1));
- return dop;
- }else if(smsCheckBean.getTimes() >= Integer.parseInt(times)){
- dop.add("userid", null);
- dop.setResultCode("8998");
- dop.setErrorInfo("验证码校验次数超过上限");
- dop.add("flowwarn", Integer.valueOf(1));
- return dop;
- }
- if (smsCheckBean.getVercode().equals(vcode)) {
- snd.diabled(smsCheckBean);
- if ((cpid.equals("tencent")) && (queryOrder(phone,cpid))){
- if("1".equals(entype)){//渠道方接入
- channelOrgBean = channelDao.findByChannelId(channel);
- dop.add("userid", DESUtil.encode(phone, channelOrgBean.getPassword()));
- }else{
- dop.add("userid", ConfigUtil.encrypt(phone, cpid));
- }
- }else{
- if("1".equals(entype)){//渠道方接入
- channelOrgBean = channelDao.findByChannelId(channel);
- dop.add("userid", DESUtil.encode(fakePhone, channelOrgBean.getPassword()));
- }else{
- dop.add("userid", ConfigUtil.encrypt(fakePhone, cpid));
- }
- }
- String token = UUID.randomUUID().toString().replaceAll("-", "");
- RedisCluster.jedis.incrBy(token,1);
- RedisCluster.jedis.expire(token,300);
- dop.add("token",token);
- } else {
- snd.addVcodeTimes(smsCheckBean);
- dop.add("userid", null);
- dop.add("token",null);
- }
- dop.add("flowwarn", Integer.valueOf(1));
- log.info("手机号:"+phone+"smsNumber.do响应时间==="+(System.currentTimeMillis()-startTime)/1000);
- return dop;
- }
- public static boolean queryOrder(String userid ,String cpid) throws Exception{
- try{
- String[] spids = {"79","78","81","21135","82","83"};
- List<String> listspids =Arrays.asList(spids);
- String url = "http://10.199.99.51:809/orderQuery/userOrder?";
- //String url = "http://127.0.0.51:809/orderQuery/userOrder?";
- String channel = "zxOrderQ";
- String times = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
- String params = "userid=" + userid + "&cpid=" + cpid + "&channel=" + channel + "&time=" + times;
- String mkey = MD5.MD5Encode("/orderQuery/userOrder?" + params + "3dae9o03mde74wk4" );
- url = url+params+"&mkey="+mkey;
- String result = URLUtil.get(url);
- Map<?,?> map = JsonUtil.jsonToMap(result);
- if(map.get("errcode").equals("0")){
- List<Map<String,String>> list = (List<Map<String,String>>) map.get("data");
- for (Map<String, String> map2 : list) {
- if(listspids.contains(map2.get("spid"))){
- if(map2.get("type").equals("0") && NumberUtils.toLong(map2.get("ordertime"))<=NumberUtils.toLong(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"))){
- return true;
- }else{
- if(NumberUtils.toLong(map2.get("endtime"))>=NumberUtils.toLong(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"))){
- return true;
- }
- }
- }
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- return false;
- }
-
- public static void main(String[] args) throws Exception {
- System.out.println(UUID.randomUUID().toString().replaceAll("-",""));
- //System.out.println(DESUtil.decode("qaAKeJlfWCnbcsNxH3nUVQ==", "7dea1gd5"));
- }
- }
|