Merge branch 'open_gj' into 'master'

Open gj

See merge request !98
This commit is contained in:
2021-08-28 15:06:31 +08:00
2 changed files with 33 additions and 9 deletions
@@ -17,6 +17,7 @@ import com.fangjia.service.open.WeChatAuthService;
import com.fangjia.service.open.WeChatAuthServiceImpl; import com.fangjia.service.open.WeChatAuthServiceImpl;
import com.fangjia.service.util.CookieUtils; import com.fangjia.service.util.CookieUtils;
import com.fangjia.service.util.DataConvertUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.fangjia.core.util.CacheUtils; import com.fangjia.core.util.CacheUtils;
@@ -77,13 +78,14 @@ public class UserController {
} else { } else {
weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id"); weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id");
} }
if(weiXinId == null) { if(weiXinId == null && StringUtils.isNotBlank(model.getCode())) {//微信公众号渤海银行
weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id"); weiXinId = DataConvertUtil.getRandomString2(16);
} }
if(weiXinId != null && !weiXinId.equals("")){ if(weiXinId != null && !weiXinId.equals("")){
CookieUtils.setCookie("we_chat_open_id", weiXinId, "/", 60 * 60 * 24 *7, response); CookieUtils.setCookie("we_chat_open_id", weiXinId, "/", 60 * 60 * 24 *7, response);
} }
System.out.println("bhyd微信OPEN_ID:" + weiXinId); System.out.println("bhyd微信OPEN_ID:" + weiXinId);
return model; return model;
} }
@@ -1,12 +1,7 @@
package com.fangjia.service.util; package com.fangjia.service.util;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DataConvertUtil { public class DataConvertUtil {
public static String convert(Integer value){ public static String convert(Integer value){
@@ -188,4 +183,31 @@ public class DataConvertUtil {
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3]; 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();
}
} }