+4
-2
@@ -17,6 +17,7 @@ import com.fangjia.service.open.WeChatAuthService;
|
||||
import com.fangjia.service.open.WeChatAuthServiceImpl;
|
||||
import com.fangjia.service.util.CookieUtils;
|
||||
|
||||
import com.fangjia.service.util.DataConvertUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.fangjia.core.util.CacheUtils;
|
||||
@@ -77,13 +78,14 @@ public class UserController {
|
||||
} else {
|
||||
weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id");
|
||||
}
|
||||
if(weiXinId == null) {
|
||||
weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id");
|
||||
if(weiXinId == null && StringUtils.isNotBlank(model.getCode())) {//微信公众号渤海银行
|
||||
weiXinId = DataConvertUtil.getRandomString2(16);
|
||||
}
|
||||
if(weiXinId != null && !weiXinId.equals("")){
|
||||
CookieUtils.setCookie("we_chat_open_id", weiXinId, "/", 60 * 60 * 24 *7, response);
|
||||
}
|
||||
System.out.println("bhyd微信OPEN_ID:" + weiXinId);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
+29
-7
@@ -1,12 +1,7 @@
|
||||
package com.fangjia.service.util;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class DataConvertUtil {
|
||||
public static String convert(Integer value){
|
||||
@@ -186,6 +181,33 @@ public class DataConvertUtil {
|
||||
ip[2] = Long.parseLong(strIp.substring(position2 + 1, position3));
|
||||
ip[3] = Long.parseLong(strIp.substring(position3 + 1));
|
||||
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//可以指定字符串的某个位置是什么范围的值
|
||||
public static String getRandomString2(int length){
|
||||
Random random=new Random();
|
||||
StringBuffer sb=new StringBuffer();
|
||||
for(int i=0;i<length;i++){
|
||||
int number=random.nextInt(3);
|
||||
long result=0;
|
||||
switch(number){
|
||||
case 0:
|
||||
result=Math.round(Math.random()*25+65);
|
||||
sb.append(String.valueOf((char)result));
|
||||
break;
|
||||
case 1:
|
||||
result=Math.round(Math.random()*25+97);
|
||||
sb.append(String.valueOf((char)result));
|
||||
break;
|
||||
case 2:
|
||||
sb.append(String.valueOf(new Random().nextInt(10)));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user