测试
This commit is contained in:
+53
-1
@@ -10,6 +10,9 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fangjia.dal.common.XcxKey;
|
||||
import com.fangjia.dal.mongo.model.bkoff.XcxUserInfo;
|
||||
import com.fangjia.service.mongo.fangjia.XcxUserInfoService;
|
||||
import com.fangjia.service.open.WeChatAuthService;
|
||||
import com.fangjia.service.open.WeChatAuthServiceImpl;
|
||||
import com.fangjia.service.util.CookieUtils;
|
||||
@@ -37,6 +40,7 @@ public class UserController {
|
||||
private UserCityService userCityService;
|
||||
private FjtUsersService fjtUsersService;
|
||||
private WeChatAuthService weChatAuthService;
|
||||
private XcxUserInfoService xcxUserInfoService;
|
||||
|
||||
public void setUserCityService(UserCityService userCityService) {
|
||||
this.userCityService = userCityService;
|
||||
@@ -58,7 +62,11 @@ public class UserController {
|
||||
public Object reqLoginPageAction(UserModel model) {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public void setXcxUserInfoService(XcxUserInfoService xcxUserInfoService) {
|
||||
this.xcxUserInfoService = xcxUserInfoService;
|
||||
}
|
||||
|
||||
public Object reqCityChoicePageAction(UserModel model, HttpServletResponse response, HttpServletRequest request) {
|
||||
String type = StringUtils.trimToNull(model.getType());
|
||||
if(!StringUtils.isBlank(type)){
|
||||
@@ -220,6 +228,8 @@ public class UserController {
|
||||
|
||||
if(StringUtils.isBlank(weiXinId) && StringUtils.isNotBlank(model.getCode())){
|
||||
System.out.println("小程序code:"+model.getCode());
|
||||
System.out.println("小程序AppId:"+model.getAppId());
|
||||
System.out.println("小程序AppSecret:"+model.getAppSecret());
|
||||
WeChatAuthServiceImpl.WeChatWebToken token = weChatAuthService.getWeChatWebToken(model.getCode(), model.getAppId(), model.getAppSecret());
|
||||
if(token != null) {
|
||||
weiXinId = token.getOpenid();
|
||||
@@ -234,6 +244,24 @@ public class UserController {
|
||||
}
|
||||
System.out.println("小程序微信OPEN_ID:" + weiXinId);
|
||||
}
|
||||
|
||||
if(StringUtils.isBlank(weiXinId) && StringUtils.isNotBlank(model.getSid())){
|
||||
System.out.println("小程序code:"+model.getCode());
|
||||
System.out.println("小程序AppId:"+model.getAppId());
|
||||
System.out.println("小程序AppSecret:"+model.getAppSecret());
|
||||
System.out.println("sid:"+model.getSid());
|
||||
XcxKey sessionValue = getSessionValue(model.getCode(), null, model.getAppId(), model.getAppSecret());
|
||||
if(sessionValue!=null){
|
||||
weiXinId = sessionValue.getOpenId();
|
||||
}
|
||||
if(weiXinId == null) {
|
||||
weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id");
|
||||
}
|
||||
if(weiXinId != null && !weiXinId.equals("")){
|
||||
CookieUtils.setCookie("we_chat_open_id", weiXinId, "/", 60 * 60 * 24 *7, response);
|
||||
}
|
||||
System.out.println("[sid]小程序微信OPEN_ID:" + weiXinId);
|
||||
}
|
||||
//测试时可以先去掉
|
||||
if (StringUtils.isBlank(username) || StringUtils.isBlank(pass) || StringUtils.isBlank(weiXinId)){
|
||||
resultModel.setMsg(Message.PARAM_NOT_NULL);
|
||||
@@ -258,6 +286,30 @@ public class UserController {
|
||||
return resultModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public XcxKey getSessionValue(String code, String sid, String appId, String secret){
|
||||
XcxKey sessionValue = null;
|
||||
if(StringUtils.isNotBlank(sid)){
|
||||
System.out.println(sid+"houqi");
|
||||
sessionValue = new XcxKey();
|
||||
sessionValue.setSid(sid);
|
||||
sessionValue.setOpenId(sid);
|
||||
}
|
||||
//缓存中没有登陆信息
|
||||
if(sessionValue==null){
|
||||
//获取openid信息
|
||||
sessionValue = xcxUserInfoService.getOpenId(code, appId, secret);
|
||||
XcxUserInfo user = null;
|
||||
if(sessionValue!=null&&StringUtils.isNotBlank(sessionValue.getOpenId())){
|
||||
//根据是否是第一次使用,保存并查询除用户信息
|
||||
user = xcxUserInfoService.save(sessionValue.getOpenId(), null);
|
||||
sessionValue.setSid(sessionValue.getOpenId());
|
||||
}
|
||||
|
||||
}
|
||||
return sessionValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的验证码
|
||||
|
||||
+2
@@ -191,6 +191,8 @@ public class XcxInfoController {
|
||||
}
|
||||
return sessionValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序估价接口
|
||||
|
||||
@@ -19,6 +19,7 @@ public class UserModel extends BaseModel {
|
||||
|
||||
private String appId;//²âÊÔ
|
||||
private String appSecret;//²âÊÔ
|
||||
private String sid;//²âÊÔ
|
||||
|
||||
public List<String> getCitys() {
|
||||
return citys;
|
||||
@@ -99,4 +100,12 @@ public class UserModel extends BaseModel {
|
||||
public void setAppSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,10 @@
|
||||
data : {
|
||||
"username" : username,
|
||||
"pass":pass,
|
||||
"code":"${code!''}"
|
||||
"code":"${code!''}",
|
||||
"sid":"${sid!''}",
|
||||
"appId":"${appId!''}",
|
||||
"appSecret":"${appSecret!''}"
|
||||
},
|
||||
success : function(result) {
|
||||
var re = $.parseJSON(result);
|
||||
|
||||
+2
@@ -34,6 +34,8 @@ public interface XcxUserInfoService {
|
||||
* @return
|
||||
*/
|
||||
public XcxKey getOpenId(String code);
|
||||
|
||||
public XcxKey getOpenId(String code, String appId, String secret);
|
||||
/**
|
||||
* 获取有多少人查询过他们自己的故事
|
||||
* @return
|
||||
|
||||
+33
@@ -101,6 +101,39 @@ public class XcxUserInfoServiceImpl implements XcxUserInfoService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public XcxKey getOpenId(String code, String appId, String secret) {
|
||||
HttpRequest http = new HttpRequest();
|
||||
//»ñÈ¡openid
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", appId);
|
||||
map.put("secret", secret);
|
||||
map.put("grant_type", XCXConstant.GRANT_TYPE);
|
||||
map.put("js_code", code);
|
||||
String result = null;
|
||||
try {
|
||||
result = http.get(XCXConstant.OPENID_URL, map, "utf-8");
|
||||
System.out.println(result);
|
||||
} catch (HttpRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//½âÎöresult
|
||||
if(StringUtils.isNotBlank(result)){
|
||||
JSONObject json = JSONObject.fromObject(result);
|
||||
if(json!=null&&json.get("openid")!=null){
|
||||
String openId = (json.get("openid")!=null)?json.get("openid").toString():null;
|
||||
String sessionKey = (json.get("session_key")!=null)?json.get("session_key").toString():null;
|
||||
XcxKey xcxKey = new XcxKey();
|
||||
xcxKey.setOpenId(openId);
|
||||
xcxKey.setSessionKey(sessionKey);
|
||||
return xcxKey;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int havaReviewStory() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user