|
@@ -7,6 +7,7 @@ import com.zhongzheng.common.core.bo.WxLoginResultBo;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
|
|
|
|
|
import com.zhongzheng.common.utils.*;
|
|
import com.zhongzheng.common.utils.*;
|
|
|
|
|
+import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
|
|
import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
|
|
|
import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
@@ -40,7 +41,9 @@ public class WxLoginService
|
|
|
@Value("${wx.small.appsecret}")
|
|
@Value("${wx.small.appsecret}")
|
|
|
private String appsrcret;
|
|
private String appsrcret;
|
|
|
|
|
|
|
|
- private String wxAuthUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
|
|
|
|
|
|
|
+ private String wxAuthUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
|
|
+
|
|
|
|
|
+ private String wxAuthParam = "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
@@ -53,12 +56,12 @@ public class WxLoginService
|
|
|
|
|
|
|
|
public String login(WxLoginBody loginBody) {
|
|
public String login(WxLoginBody loginBody) {
|
|
|
String unionId = getWxUnionId(loginBody);
|
|
String unionId = getWxUnionId(loginBody);
|
|
|
- User user = iUserService.queryByUnionId(unionId);
|
|
|
|
|
|
|
+ /* User user = iUserService.queryByUnionId(unionId);
|
|
|
if(user==null){
|
|
if(user==null){
|
|
|
throw new CustomException("unionId不存在");
|
|
throw new CustomException("unionId不存在");
|
|
|
}
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
- loginUser.setUser(user);
|
|
|
|
|
|
|
+ loginUser.setUser(user);*/
|
|
|
// return wxTokenService.createToken(loginUser);
|
|
// return wxTokenService.createToken(loginUser);
|
|
|
return unionId;
|
|
return unionId;
|
|
|
}
|
|
}
|
|
@@ -102,9 +105,15 @@ public class WxLoginService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getWxUnionId(WxLoginBody loginBody) {
|
|
public String getWxUnionId(WxLoginBody loginBody) {
|
|
|
- String url = String.format(wxAuthUrl, appid, appsrcret, loginBody.getCode());
|
|
|
|
|
- WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
|
|
- String wxResult = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),wxLoginResult.getSession_key());
|
|
|
|
|
|
|
+ String url = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
|
|
|
|
|
+
|
|
|
|
|
+ String resultString = HttpUtils.sendGet(wxAuthUrl,wxAuthParam);
|
|
|
|
|
+ //解析json
|
|
|
|
|
+ JSONObject jsonObject1 = (JSONObject) JSONObject.parse(resultString);
|
|
|
|
|
+ String session_key = jsonObject1.get("session_key")+"";
|
|
|
|
|
+ String openid = jsonObject1.get("openid")+"";
|
|
|
|
|
+ // WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
|
|
+ String wxResult = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
|
|
|
return wxResult;
|
|
return wxResult;
|
|
|
}
|
|
}
|
|
|
|
|
|