|
|
@@ -0,0 +1,57 @@
|
|
|
+package com.zhongzheng.framework.web.service;
|
|
|
+
|
|
|
+
|
|
|
+import com.zhongzheng.common.core.bo.WxLoginResultBo;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+
|
|
|
+import com.zhongzheng.modules.user.domain.User;
|
|
|
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
|
+import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 登录校验方法
|
|
|
+ *
|
|
|
+ * @author zhongzheng
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class WxLoginService
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private WxTokenService wxTokenService;
|
|
|
+
|
|
|
+ @Value("${wx.small.appid}")
|
|
|
+ private String appid;
|
|
|
+
|
|
|
+ @Value("${wx.small.appsecret}")
|
|
|
+ private String appsrcret;
|
|
|
+
|
|
|
+ private String wxAuthUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService iUserService;
|
|
|
+
|
|
|
+ public String login(String unionId) {
|
|
|
+ User user = iUserService.queryByUnionId(unionId);
|
|
|
+ if(user==null){
|
|
|
+ throw new CustomException("unionId不存在");
|
|
|
+ }
|
|
|
+ ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
+ loginUser.setUser(user);
|
|
|
+ return wxTokenService.createToken(loginUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getWxUnionId(String code) {
|
|
|
+ String url = String.format(wxAuthUrl, appid, appsrcret, code);
|
|
|
+ WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|