|
@@ -2,18 +2,23 @@ package com.platform.yijia.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.platform.yijia.pojo.AppUserInfo;
|
|
|
+import com.platform.yijia.service.AppUserInfoService;
|
|
|
import com.platform.yijia.utils.ConstantUtil;
|
|
|
import com.platform.yijia.utils.HttpClientUtil;
|
|
|
import com.platform.yijia.utils.SignUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @Author : suxinghua
|
|
@@ -25,7 +30,8 @@ import java.text.ParseException;
|
|
|
@RequestMapping("/wxAuth")
|
|
|
public class WxLoginController {
|
|
|
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private AppUserInfoService appUserInfoService;
|
|
|
/**
|
|
|
* 用于给微信验证token
|
|
|
*
|
|
@@ -116,7 +122,26 @@ public class WxLoginController {
|
|
|
|
|
|
String resultInfo = HttpClientUtil.doGet(infoUrl);
|
|
|
JSONObject resultInfoObject = JSON.parseObject(resultInfo);
|
|
|
+ AppUserInfo appUserInfo =new AppUserInfo();
|
|
|
|
|
|
+ if(StringUtils.isNotBlank(resultInfoObject.getString("openid"))){
|
|
|
+ appUserInfo.setBlogOpenid(resultInfoObject.getString("openid"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(resultInfoObject.getString("nickname"))){
|
|
|
+ appUserInfo.setBlogNickName(resultInfoObject.getString("nickname"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(resultInfoObject.getString("sex"))){
|
|
|
+ appUserInfo.setSexFlag(resultInfoObject.getString("sex"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(resultObject.getString("access_token"))){
|
|
|
+ appUserInfo.setBlogToken(resultObject.getString("access_token"));
|
|
|
+ }
|
|
|
+ appUserInfo.setUserType("1");//公众号
|
|
|
+ //查询用户是否存在
|
|
|
+ List<AppUserInfo> list =appUserInfoService.Authentication(appUserInfo);
|
|
|
+ if(list!=null && list.size()==0){
|
|
|
+ appUserInfoService.AddAppUserInfo(appUserInfo);
|
|
|
+ }
|
|
|
//此时已获取到userInfo,再根据业务进行处理
|
|
|
System.out.println("请求获取userInfo:" + resultInfo);
|
|
|
return resultInfoObject.toString();
|