284c6feb85fc02e1696fa5a66e97218e5eeb1a7d.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.chinacreator.videoalliance.smc.action;
  2. import com.chinacreator.common.exception.BusinessException;
  3. import com.chinacreator.common.pipe.DataOutPipe;
  4. import com.chinacreator.common.util.DESUtil;
  5. import com.chinacreator.common.util.MD5;
  6. import com.chinacreator.videoalliance.common.annotation.DataOut;
  7. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  8. import com.chinacreator.videoalliance.order.bean.ChannelOrgBean;
  9. import com.chinacreator.videoalliance.order.dao.ChannelDao;
  10. import com.chinacreator.videoalliance.order.util.JsonUtil;
  11. import com.chinacreator.videoalliance.order.util.RedisCluster;
  12. import com.chinacreator.videoalliance.order.util.URLUtil;
  13. import com.chinacreator.videoalliance.smc.bean.SmsCheckBean;
  14. import com.chinacreator.videoalliance.smc.dao.SmsNumberDao;
  15. import com.chinacreator.videoalliance.smc.dao.SmsWhiteDao;
  16. import org.apache.commons.lang.math.NumberUtils;
  17. import org.apache.commons.lang.time.DateFormatUtils;
  18. import org.apache.log4j.Logger;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.stereotype.Controller;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.util.*;
  26. @Controller
  27. public class SmsNumberAction {
  28. private static Logger logger = Logger.getLogger(SmsNumberAction.class);
  29. private static Logger log = Logger.getLogger("sendSms");
  30. @Value("${sms.error.times}")
  31. private String times; // = "3";
  32. @Autowired
  33. private SmsWhiteDao smsWhiteDao;
  34. @Autowired
  35. private ChannelDao channelDao;
  36. @RequestMapping({ "/smsNumber.do" })
  37. @DataOut(callback = "SmsNumber")
  38. public DataOutPipe doNet(HttpServletRequest request, HttpServletResponse response) throws Exception {
  39. long startTime = System.currentTimeMillis();
  40. String cpid = request.getParameter("cpid");
  41. String userid = request.getParameter("userid");
  42. String vcode = request.getParameter("vcode");
  43. final String entype = request.getParameter("entype");
  44. final String channel = request.getParameter("channel");
  45. String isvoice = request.getParameter("isvoice");//1:使用语音验证码
  46. String phone = "";//ConfigUtil.decrypt(userid, cpid);
  47. String fakePhone = ""; //ConfigUtil.getFakeid(phone, cpid);
  48. ChannelOrgBean channelOrgBean = null;
  49. if("1".equals(entype)){//渠道方接入
  50. channelOrgBean = channelDao.findByChannelId(channel);
  51. if (channelOrgBean == null || channelOrgBean.getStatus().equals("1")) {
  52. throw new BusinessException("9001", "渠道参数错误");
  53. }
  54. phone = DESUtil.decode(userid, channelOrgBean.getPassword());
  55. fakePhone = phone;
  56. }else{ //entype为空或为1时,合作方接入
  57. phone = ConfigUtil.decrypt(userid, cpid);
  58. fakePhone = ConfigUtil.getFakeid(phone, cpid);
  59. }
  60. logger.info("phone:"+phone+", fakePhone:"+fakePhone+", vcode:"+vcode);
  61. SmsNumberDao snd = new SmsNumberDao();
  62. DataOutPipe dop = new DataOutPipe();
  63. String vcpid="";
  64. if ("1".equals(isvoice)){
  65. vcpid=cpid+"isvoice";
  66. }else {
  67. vcpid=cpid;
  68. }
  69. long findTime = System.currentTimeMillis();
  70. SmsCheckBean smsCheckBean = snd.checkVcode(phone, vcpid);
  71. log.info("手机号:"+phone+"smsNumber.do查询数据库响应时间==="+(System.currentTimeMillis()-findTime)/1000);
  72. if (smsWhiteDao.isBlackUserCanValidate(phone, cpid)) {
  73. throw new BusinessException("8007", "黑名单用户,短信验证失败", new String[0]);
  74. }
  75. if(smsCheckBean == null){
  76. dop.add("userid", null);
  77. dop.setResultCode("8999");
  78. dop.setErrorInfo("验证码已失效");
  79. dop.add("flowwarn", Integer.valueOf(1));
  80. return dop;
  81. }else if(smsCheckBean.getTimes() >= Integer.parseInt(times)){
  82. dop.add("userid", null);
  83. dop.setResultCode("8998");
  84. dop.setErrorInfo("验证码校验次数超过上限");
  85. dop.add("flowwarn", Integer.valueOf(1));
  86. return dop;
  87. }
  88. if (smsCheckBean.getVercode().equals(vcode)) {
  89. snd.diabled(smsCheckBean);
  90. if ((cpid.equals("tencent")) && (queryOrder(phone,cpid))){
  91. if("1".equals(entype)){//渠道方接入
  92. channelOrgBean = channelDao.findByChannelId(channel);
  93. dop.add("userid", DESUtil.encode(phone, channelOrgBean.getPassword()));
  94. }else{
  95. dop.add("userid", ConfigUtil.encrypt(phone, cpid));
  96. }
  97. }else{
  98. if("1".equals(entype)){//渠道方接入
  99. channelOrgBean = channelDao.findByChannelId(channel);
  100. dop.add("userid", DESUtil.encode(fakePhone, channelOrgBean.getPassword()));
  101. }else{
  102. dop.add("userid", ConfigUtil.encrypt(fakePhone, cpid));
  103. }
  104. }
  105. String token = UUID.randomUUID().toString().replaceAll("-", "");
  106. RedisCluster.jedis.incrBy(token,1);
  107. RedisCluster.jedis.expire(token,300);
  108. dop.add("token",token);
  109. } else {
  110. snd.addVcodeTimes(smsCheckBean);
  111. dop.add("userid", null);
  112. dop.add("token",null);
  113. }
  114. dop.add("flowwarn", Integer.valueOf(1));
  115. log.info("手机号:"+phone+"smsNumber.do响应时间==="+(System.currentTimeMillis()-startTime)/1000);
  116. return dop;
  117. }
  118. public static boolean queryOrder(String userid ,String cpid) throws Exception{
  119. try{
  120. String[] spids = {"79","78","81","21135","82","83"};
  121. List<String> listspids =Arrays.asList(spids);
  122. String url = "http://10.199.99.51:809/orderQuery/userOrder?";
  123. //String url = "http://127.0.0.51:809/orderQuery/userOrder?";
  124. String channel = "zxOrderQ";
  125. String times = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
  126. String params = "userid=" + userid + "&cpid=" + cpid + "&channel=" + channel + "&time=" + times;
  127. String mkey = MD5.MD5Encode("/orderQuery/userOrder?" + params + "3dae9o03mde74wk4" );
  128. url = url+params+"&mkey="+mkey;
  129. String result = URLUtil.get(url);
  130. Map<?,?> map = JsonUtil.jsonToMap(result);
  131. if(map.get("errcode").equals("0")){
  132. List<Map<String,String>> list = (List<Map<String,String>>) map.get("data");
  133. for (Map<String, String> map2 : list) {
  134. if(listspids.contains(map2.get("spid"))){
  135. if(map2.get("type").equals("0") && NumberUtils.toLong(map2.get("ordertime"))<=NumberUtils.toLong(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"))){
  136. return true;
  137. }else{
  138. if(NumberUtils.toLong(map2.get("endtime"))>=NumberUtils.toLong(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"))){
  139. return true;
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }catch(Exception e){
  146. e.printStackTrace();
  147. }
  148. return false;
  149. }
  150. public static void main(String[] args) throws Exception {
  151. System.out.println(UUID.randomUUID().toString().replaceAll("-",""));
  152. //System.out.println(DESUtil.decode("qaAKeJlfWCnbcsNxH3nUVQ==", "7dea1gd5"));
  153. }
  154. }