测试
This commit is contained in:
+52
@@ -10,6 +10,9 @@ import java.util.List;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.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;
|
||||||
@@ -37,6 +40,7 @@ public class UserController {
|
|||||||
private UserCityService userCityService;
|
private UserCityService userCityService;
|
||||||
private FjtUsersService fjtUsersService;
|
private FjtUsersService fjtUsersService;
|
||||||
private WeChatAuthService weChatAuthService;
|
private WeChatAuthService weChatAuthService;
|
||||||
|
private XcxUserInfoService xcxUserInfoService;
|
||||||
|
|
||||||
public void setUserCityService(UserCityService userCityService) {
|
public void setUserCityService(UserCityService userCityService) {
|
||||||
this.userCityService = userCityService;
|
this.userCityService = userCityService;
|
||||||
@@ -59,6 +63,10 @@ public class UserController {
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setXcxUserInfoService(XcxUserInfoService xcxUserInfoService) {
|
||||||
|
this.xcxUserInfoService = xcxUserInfoService;
|
||||||
|
}
|
||||||
|
|
||||||
public Object reqCityChoicePageAction(UserModel model, HttpServletResponse response, HttpServletRequest request) {
|
public Object reqCityChoicePageAction(UserModel model, HttpServletResponse response, HttpServletRequest request) {
|
||||||
String type = StringUtils.trimToNull(model.getType());
|
String type = StringUtils.trimToNull(model.getType());
|
||||||
if(!StringUtils.isBlank(type)){
|
if(!StringUtils.isBlank(type)){
|
||||||
@@ -220,6 +228,8 @@ public class UserController {
|
|||||||
|
|
||||||
if(StringUtils.isBlank(weiXinId) && StringUtils.isNotBlank(model.getCode())){
|
if(StringUtils.isBlank(weiXinId) && StringUtils.isNotBlank(model.getCode())){
|
||||||
System.out.println("小程序code:"+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());
|
WeChatAuthServiceImpl.WeChatWebToken token = weChatAuthService.getWeChatWebToken(model.getCode(), model.getAppId(), model.getAppSecret());
|
||||||
if(token != null) {
|
if(token != null) {
|
||||||
weiXinId = token.getOpenid();
|
weiXinId = token.getOpenid();
|
||||||
@@ -234,6 +244,24 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
System.out.println("小程序微信OPEN_ID:" + weiXinId);
|
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)){
|
if (StringUtils.isBlank(username) || StringUtils.isBlank(pass) || StringUtils.isBlank(weiXinId)){
|
||||||
resultModel.setMsg(Message.PARAM_NOT_NULL);
|
resultModel.setMsg(Message.PARAM_NOT_NULL);
|
||||||
@@ -259,6 +287,30 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存的验证码
|
* 获取缓存的验证码
|
||||||
* @author yinjihuan
|
* @author yinjihuan
|
||||||
|
|||||||
+2
@@ -192,6 +192,8 @@ public class XcxInfoController {
|
|||||||
return sessionValue;
|
return sessionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序估价接口
|
* 小程序估价接口
|
||||||
* @param model
|
* @param model
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class UserModel extends BaseModel {
|
|||||||
|
|
||||||
private String appId;//²âÊÔ
|
private String appId;//²âÊÔ
|
||||||
private String appSecret;//²âÊÔ
|
private String appSecret;//²âÊÔ
|
||||||
|
private String sid;//²âÊÔ
|
||||||
|
|
||||||
public List<String> getCitys() {
|
public List<String> getCitys() {
|
||||||
return citys;
|
return citys;
|
||||||
@@ -99,4 +100,12 @@ public class UserModel extends BaseModel {
|
|||||||
public void setAppSecret(String appSecret) {
|
public void setAppSecret(String appSecret) {
|
||||||
this.appSecret = appSecret;
|
this.appSecret = appSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSid() {
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSid(String sid) {
|
||||||
|
this.sid = sid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,10 @@
|
|||||||
data : {
|
data : {
|
||||||
"username" : username,
|
"username" : username,
|
||||||
"pass":pass,
|
"pass":pass,
|
||||||
"code":"${code!''}"
|
"code":"${code!''}",
|
||||||
|
"sid":"${sid!''}",
|
||||||
|
"appId":"${appId!''}",
|
||||||
|
"appSecret":"${appSecret!''}"
|
||||||
},
|
},
|
||||||
success : function(result) {
|
success : function(result) {
|
||||||
var re = $.parseJSON(result);
|
var re = $.parseJSON(result);
|
||||||
|
|||||||
+2
@@ -34,6 +34,8 @@ public interface XcxUserInfoService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public XcxKey getOpenId(String code);
|
public XcxKey getOpenId(String code);
|
||||||
|
|
||||||
|
public XcxKey getOpenId(String code, String appId, String secret);
|
||||||
/**
|
/**
|
||||||
* 获取有多少人查询过他们自己的故事
|
* 获取有多少人查询过他们自己的故事
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
+33
@@ -101,6 +101,39 @@ public class XcxUserInfoServiceImpl implements XcxUserInfoService {
|
|||||||
return null;
|
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
|
@Override
|
||||||
public int havaReviewStory() {
|
public int havaReviewStory() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user