|
@@ -1,8 +1,11 @@
|
|
|
package com.template.controller;
|
|
package com.template.controller;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.template.annotation.PassToken;
|
|
import com.template.annotation.PassToken;
|
|
|
import com.template.api.WechatScanLoginControllerAPI;
|
|
import com.template.api.WechatScanLoginControllerAPI;
|
|
|
import com.template.common.constanst.Constanst;
|
|
import com.template.common.constanst.Constanst;
|
|
@@ -31,6 +34,7 @@ import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -260,4 +264,33 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
List<List<BigDecimal>> ld = RandomTrackAlgorithm.getPosition();
|
|
List<List<BigDecimal>> ld = RandomTrackAlgorithm.getPosition();
|
|
|
return CommonResult.ok(ld);
|
|
return CommonResult.ok(ld);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public CommonResult vertify(String code){
|
|
|
|
|
+ if (StringUtils.isBlank(code)){
|
|
|
|
|
+ return CommonResult.fail("请传入code");
|
|
|
|
|
+ }
|
|
|
|
|
+ String url = "https://api.weixin.qq.com/sns/jscode2session?" +
|
|
|
|
|
+ "appid=" + PropertiesUtil.getValue(HttpParame.APPID) +
|
|
|
|
|
+ "&secret=" + PropertiesUtil.getValue(HttpParame.SECRET) +
|
|
|
|
|
+ "&js_code=" + code +
|
|
|
|
|
+ "&grant_type=authorization_code";
|
|
|
|
|
+
|
|
|
|
|
+ String json = HttpClientUtils.getInstance().sendHttpGet(url);
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ HashMap<String, String> userMap = gson.fromJson(json.toString(), new TypeToken<HashMap<String, String>>() {}.getType());
|
|
|
|
|
+ String openid = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+ openid = userMap.get("openid").toString();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return CommonResult.fail("code异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ SmartUser user = wechatScanLoginService.selectByOpenid(openid);
|
|
|
|
|
+ if (user==null){
|
|
|
|
|
+ return CommonResult.fail("请绑定后再进入");
|
|
|
|
|
+ }
|
|
|
|
|
+ String token = JWTUtil.getToken(user);
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("token", token);
|
|
|
|
|
+ return CommonResult.ok(jsonObject.toString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|