diff --git a/pom.xml b/pom.xml
index 506a0b9..8a93884 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,15 @@
2.0.4
+
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+ 1.56
+
+
+
diff --git a/src/main/java/cn/com/tenlion/controller/app/apis/weixinlogin/WeiXinLoginAppController.java b/src/main/java/cn/com/tenlion/controller/app/apis/weixinlogin/WeiXinLoginAppController.java
index db99238..2235b5d 100644
--- a/src/main/java/cn/com/tenlion/controller/app/apis/weixinlogin/WeiXinLoginAppController.java
+++ b/src/main/java/cn/com/tenlion/controller/app/apis/weixinlogin/WeiXinLoginAppController.java
@@ -1,5 +1,6 @@
package cn.com.tenlion.controller.app.apis.weixinlogin;
+import cn.com.tenlion.pojo.dtos.weixinlogin.WeiXinLoginResult;
import cn.com.tenlion.service.weixinlogin.IWeiXinLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -26,7 +27,7 @@ public class WeiXinLoginAppController {
* @throws Exception
*/
@GetMapping("weiXinLoginBySmallRoutine/{vxCode}")
- public String weiXinLoginBySmallRoutine (@PathVariable("vxCode") String vxCode) throws Exception{
+ public WeiXinLoginResult weiXinLoginBySmallRoutine (@PathVariable("vxCode") String vxCode) throws Exception{
return weiXinLoginService.weiXinLoginBySmallRoutine(vxCode);
}
diff --git a/src/main/java/cn/com/tenlion/service/weixinlogin/IWeiXinLoginService.java b/src/main/java/cn/com/tenlion/service/weixinlogin/IWeiXinLoginService.java
index 0059c84..fa6ed1e 100644
--- a/src/main/java/cn/com/tenlion/service/weixinlogin/IWeiXinLoginService.java
+++ b/src/main/java/cn/com/tenlion/service/weixinlogin/IWeiXinLoginService.java
@@ -1,5 +1,6 @@
package cn.com.tenlion.service.weixinlogin;
+import cn.com.tenlion.pojo.dtos.weixinlogin.WeiXinLoginResult;
import com.alibaba.fastjson.JSONObject;
/**
@@ -19,6 +20,6 @@ public interface IWeiXinLoginService {
* @return
* @throws Exception
*/
- String weiXinLoginBySmallRoutine(String code) throws Exception;
+ WeiXinLoginResult weiXinLoginBySmallRoutine(String code) throws Exception;
}
diff --git a/src/main/java/cn/com/tenlion/service/weixinlogin/impl/WeiXinLoginServiceImpl.java b/src/main/java/cn/com/tenlion/service/weixinlogin/impl/WeiXinLoginServiceImpl.java
index 4459e93..38555c5 100644
--- a/src/main/java/cn/com/tenlion/service/weixinlogin/impl/WeiXinLoginServiceImpl.java
+++ b/src/main/java/cn/com/tenlion/service/weixinlogin/impl/WeiXinLoginServiceImpl.java
@@ -1,6 +1,8 @@
package cn.com.tenlion.service.weixinlogin.impl;
+import cn.com.tenlion.pojo.dtos.weixinlogin.WeiXinLoginResult;
import cn.com.tenlion.service.weixinlogin.IWeiXinLoginService;
+import cn.com.tenlion.util.AesUtil;
import cn.com.tenlion.util.WxUtil;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
@@ -27,15 +29,13 @@ public class WeiXinLoginServiceImpl implements IWeiXinLoginService {
/**小程序授权类型*/
private static String GRANT_TYPE = "authorization_code";
-
-
/**
* 微信小程序登录
* @param code
* @return
* @throws Exception
*/
- public String weiXinLoginBySmallRoutine(String code) throws Exception{
+ public WeiXinLoginResult weiXinLoginBySmallRoutine(String code) throws Exception{
if(StringUtils.isEmpty(code)){
throw new Exception("code不能为空");
}
@@ -46,12 +46,26 @@ public class WeiXinLoginServiceImpl implements IWeiXinLoginService {
param.put("js_code", code);
param.put("grant_type", GRANT_TYPE);
String str = WxUtil.doGet(VX_SMALL_ROUTINE_SESSION_KEY, param);
- if (StringUtils.isEmpty(str)) {
- return "";
+ JSONObject json = JSONObject.parseObject(str);
+ Integer errcode = json.getInteger("errcode");
+ WeiXinLoginResult initResult = new WeiXinLoginResult();
+ if (errcode == 0) {
+ String skye = json.getString("session_key");
+ String openId = json.getString("openid");
+ String unionId = json.getString("unionid");
+ String token = AesUtil.aesCommonEncoder(skye,openId+unionId);
+ initResult.setCode("200");
+ initResult.setMsg("success");
+ initResult.setToken(token);
+
+
+
+// json.getString("errmsg");
+ return initResult;
} else {
- JSONObject json = JSONObject.parseObject(str);
- json.getString("");
- return "";
+ initResult.setCode("500");
+ initResult.setMsg("系统异常");
+ return initResult;
}
}
diff --git a/src/main/java/cn/com/tenlion/util/WxUtil.java b/src/main/java/cn/com/tenlion/util/WxUtil.java
index f91ca7f..403201e 100644
--- a/src/main/java/cn/com/tenlion/util/WxUtil.java
+++ b/src/main/java/cn/com/tenlion/util/WxUtil.java
@@ -1,5 +1,6 @@
package cn.com.tenlion.util;
+import com.sun.org.apache.xml.internal.security.utils.Base64;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
@@ -16,7 +17,12 @@ import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.security.Security;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;