|
@@ -1,18 +1,26 @@
|
|
|
package com.factory.controller.wx;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.factory.base.entity.aggregates.ResponseBean;
|
|
|
+import com.factory.base.util.res.ResponseBeanBuilder;
|
|
|
+import com.factory.util.client.HttpCilentUntil;
|
|
|
import com.factory.wx.entity.res.FunctionsRes;
|
|
|
import com.factory.wx.service.WxService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 小程序功能显示
|
|
@@ -35,4 +43,30 @@ public class WxController {
|
|
|
Long userId = (Long) request.getAttribute("LOGIN_USER_ID");//获取用户id
|
|
|
return wxService.getUserFunction(userId);
|
|
|
}
|
|
|
+ @Value("${wx.minprogram.appsecret}")
|
|
|
+ private String appsecret;
|
|
|
+
|
|
|
+ @Value("${wx.minprogram.appid}")
|
|
|
+ private String appid;
|
|
|
+
|
|
|
+ @ApiOperation(value = "小程序获取openid")
|
|
|
+ @GetMapping("/minprogram/openId")
|
|
|
+ public ResponseBean<String> requestWeChatOpenid(HttpServletResponse response, HttpServletRequest request) throws Throwable {
|
|
|
+ String code = request.getParameter("code");//获取code
|
|
|
+ response.setContentType("text/html");
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ Map params = new HashMap();
|
|
|
+ params.put("secret",appsecret);
|
|
|
+ params.put("appid", appid);
|
|
|
+ params.put("grant_type", "authorization_code");
|
|
|
+ params.put("js_code", code);
|
|
|
+ params.put("connect_redirect","1");
|
|
|
+ String result = HttpCilentUntil.httpGetToString(
|
|
|
+ "https://api.weixin.qq.com/sns/jscode2session", params);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ String openid = jsonObject.get("openid").toString();
|
|
|
+ return ResponseBeanBuilder.ok(openid);
|
|
|
+ }
|
|
|
+
|
|
|
}
|