Ver Fonte

代码修改

jk-GitHub-coder há 4 anos atrás
pai
commit
dc0c1e95b6

+ 30 - 26
YijiaRestful/src/main/java/com/platform/yijia/controller/AppUserInfoController.java

@@ -27,6 +27,7 @@ import javax.annotation.Resource;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 @Controller
 @RequestMapping("/demo")
@@ -42,10 +43,6 @@ public class AppUserInfoController {
     private CustomerPointsService customerPointsService;
     @Resource
     private RedisCacheUtil redisCacheUtil;
-    @Resource
-    private WeiXinUserUtil weiXinUserUtil;
-    @Resource
-    private AesDecryptUtil aesDecryptUtil;
 
 //    String appId = "wxe1135cd390b38a54";        //微信小程序appID
 //    String appSecret = "0532c7d9ae876c4ad636df0b1e3b9ddb";      //微信小程序密钥
@@ -68,7 +65,7 @@ public class AppUserInfoController {
             appSecret = map.get("appSecret");      //微信小程序密钥
         }
         //获取session_key 和 openid
-        return weiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
+        return WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
     }
 
     /*
@@ -82,17 +79,17 @@ public class AppUserInfoController {
     @RequestMapping(value = "/decryptEncryptedData", method = RequestMethod.POST, consumes = "application/json")
     public String decryptEncryptedData(@RequestBody JSONObject jsonObject){
         logger.info("解密获取手机号前台传入参数:" +jsonObject.toString());
-        return aesDecryptUtil.decryptEncryptedData(jsonObject.get("encryptedData").toString(), jsonObject.get("sessionKey").toString(), jsonObject.get("iv").toString(), "UTF-8").toString();
+        return AesDecryptUtil.decryptEncryptedData(jsonObject.get("encryptedData").toString(), jsonObject.get("sessionKey").toString(), jsonObject.get("iv").toString(), "UTF-8").toString();
     }
 
-    //获取UnionId信息
-    @RequestMapping(value = "/getUnionIdAndAccessToken", method = RequestMethod.GET)
+    //获取公众号信息
+    @RequestMapping(value = "/getGzhUserInfo", method = RequestMethod.GET)
     @ResponseBody
-    public String redisCacheUtil(@RequestParam String openId, Integer stationId){
+    public String getGzhUserInfo(@RequestParam String openId, Integer stationId){
         Gson gson =new Gson();
         //返回结果集
         ResultData resultData = null;
-        Map<String, String> map= new HashMap<>();
+        //Map<String, String> map= new HashMap<>();
         if(openId !=null && stationId !=null){
             String gzhAppId ="";
             String gzhAppSecret ="";
@@ -101,22 +98,9 @@ public class AppUserInfoController {
             if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
                 gzhAppId = m.get("gzhAppId");
                 gzhAppSecret = m.get("gzhAppSecret");
-                accessToken  = weiXinUserUtil.getTokenByRedisCache(gzhAppId, gzhAppSecret);
-                net.sf.json.JSONObject unionIdInfo = weiXinUserUtil.getUnionIdInfo(accessToken, openId);
-                if(unionIdInfo !=null && unionIdInfo.containsKey("nickname")){
-                    map.put("nickName", unionIdInfo.get("nickname").toString());
-                }
-                if(unionIdInfo !=null && unionIdInfo.containsKey("openid")){
-                    map.put("openId", unionIdInfo.get("openid").toString());
-                }
-                if(unionIdInfo !=null && unionIdInfo.containsKey("unionid")){
-                    map.put("unoinId", unionIdInfo.get("unionid").toString());
-                }
-//                if(unionIdInfo !=null && unionIdInfo.containsKey("headimgurl")){
-//                    map.put("headImgUrl", unionIdInfo.get("headimgurl").toString());
-//                }
-                map.put("accessToken", accessToken);
-                resultData=ResultData.success(map);
+                accessToken  = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
+                net.sf.json.JSONObject unionIdInfo = WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
+                resultData=ResultData.success(unionIdInfo);
             }
         }else {
             resultData=ResultData.success(CodeMsg.REQUEST_FAIL);
@@ -124,6 +108,26 @@ public class AppUserInfoController {
         return gson.toJson(resultData);
     }
 
+    /*
+     * 从Redis缓存中获取 tokenCache
+     * @param appId
+     * @param appSecret
+     * @return
+     */
+    public String getTokenByRedisCache(String appId, String appSecret){
+        logger.info("appId参数: "+ appId+" ;appSecret参数: " +appSecret);
+        String tokenCache ="";
+        if(!redisCacheUtil.hasKey(appId)){
+            String token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
+            redisCacheUtil.setCacheObject(appId, token);
+            redisCacheUtil.expire(appId, 7200, TimeUnit.SECONDS);
+            tokenCache = token;
+            logger.info("Redis缓存中token信息: " + tokenCache);
+        }else {
+            tokenCache = redisCacheUtil.getCacheObject(appId);
+        }
+        return tokenCache;
+    }
 
     /*
      * 添加用户信息

+ 44 - 1
YijiaRestful/src/main/java/com/platform/yijia/controller/PosMachineController.java

@@ -87,11 +87,54 @@ public class PosMachineController {
         return gson.toJson(resultData);
     }
 
+    /*
+     * 获取班结人要班结的订单列表
+     * @param stationId
+     * @param userName
+     * @return
+     */
+    @RequestMapping (value = "/getClassStructureList", method = RequestMethod.GET)
+    @ResponseBody
+    public String getClassStructureList(@RequestParam Integer stationId) throws ParseException {
+        Gson gson =new Gson();
+        //返回结果集
+        ResultData resultData = null;
+        if(stationId !=null){
+            StationClassStructure classes =new StationClassStructure();
+            classes.setStationId(stationId);
+            //查询出上次班结,最后一条数据
+            StationClassStructure sss =stationClassStructureService.selectStationClassStructureMax(classes);
+            String beginTime="";
+            //当前时间
+            Date date= new Date();
+            StationClassStructure classesStructure =new StationClassStructure();
+            classesStructure.setStationId(stationId);
+            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            if(sss != null){
+                //班结过
+                beginTime= dateFormat.format(sss.getClassStructureDate());
+            }else {
+                //没有班结过:第一次班结
+                beginTime =null;
+            }
+            //获取上次班结时间
+            PayOrder order=new PayOrder();
+            order.setStationId(stationId);
+            order.setStatus("1");
+            order.setBeginTime(beginTime);
+            order.setEndTime(dateFormat.format(date));
+            List<PayOrder> list = payOrderService.selectPayOrderList(order);
+            resultData =ResultData.success(list);
+        }else {
+            resultData =ResultData.error(CodeMsg.PARAMS_NUll);
+        }
+        return  gson.toJson(resultData);
+    }
 
 
 
 
-    /**
+    /*
      * pos机班结
      * @param stationClassStructure
      * @return

+ 1 - 2
YijiaRestful/src/main/java/com/platform/yijia/utils/weixinapp/AesDecryptUtil.java

@@ -25,7 +25,6 @@ import java.security.spec.InvalidParameterSpecException;
  * @author JK
  * @date 2019-11-12
  */
-@Component
 public class AesDecryptUtil {
 
     private static Logger logger =(Logger) LoggerFactory.getLogger(AesDecryptUtil.class);
@@ -42,7 +41,7 @@ public class AesDecryptUtil {
      * @param encodingFormat 解码后编码方式 像UTF-8等
      * @return 返回String类型字符串: new String(resultBytes, encodingFormat)
      */
-    public JSONObject decryptEncryptedData(String encryptedData, String session_key, String iv, String encodingFormat){
+    public static JSONObject decryptEncryptedData(String encryptedData, String session_key, String iv, String encodingFormat){
 
         //被加密的数据
         byte[] edBytes = Base64.decodeBase64(encryptedData.getBytes());

+ 1 - 2
YijiaRestful/src/main/java/com/platform/yijia/utils/weixinapp/HttpRequestUtil.java

@@ -20,7 +20,6 @@ import java.security.SecureRandom;
  * @author JK
  * @date 2019年11月14日
  */
-@Component
 public class HttpRequestUtil {
     /*
      * 发送https请求
@@ -29,7 +28,7 @@ public class HttpRequestUtil {
      * @param outPutStr         //提交的数据
      * @return  jsonObject (通过JSONObject.get(key)的方式获取json的对象)
      */
-    public JSONObject getHttpsRequestData(String requestUrl, String requestMethod, String outPutStr){
+    public static JSONObject getHttpsRequestData(String requestUrl, String requestMethod, String outPutStr){
         JSONObject jsonObject = null;
         try {
             //创建SSLContext对象

+ 23 - 29
YijiaRestful/src/main/java/com/platform/yijia/utils/weixinapp/WeiXinUserUtil.java

@@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit;
  * @author JK
  * @date 2019年11月10日
  */
-@Component
 public class WeiXinUserUtil {
 
     //微信小程序获取用户信息 https://api.weixin.qq.com/sns/userinfo
@@ -38,28 +37,23 @@ public class WeiXinUserUtil {
     //日志
     private static final Logger logger = LoggerFactory.getLogger(WeiXinUserUtil.class);
 
-    @Resource
-    private RedisCacheUtil redisCacheUtil;
-
-    @Resource
-    private HttpRequestUtil httpRequestUtil;
+//    @Resource
+//    private  RedisCacheUtil redisCacheUtil;
 
 
     /*
-     * 获取UnionId信息
+     * 获取公众号UnionId信息
      * @param accessToken
      * @param openId
      * @return
      */
-    public  JSONObject getUnionIdInfo(String accessToken, String openId){
+    public static JSONObject getUnionIdInfo(String accessToken, String openId){
         String requestUrl = unionId_Url.replace("ACCESS_TOKEN", accessToken).replace("OPENID", openId);
-        JSONObject jsonObject = httpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
+        JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
         logger.info("获取UnionId信息:" + jsonObject.toString());
         return jsonObject;
     }
 
-
-
     /*
      * 获取用户的openid和session_key 格式例子:{"session_key":"rlxKT/xhq2bxAuvrMeEq8Q==","openid":"o9RM50ppeCgx065T2PvJjtzB_Gmo"}
      * @param appId     //凭证
@@ -67,11 +61,11 @@ public class WeiXinUserUtil {
      * @param code
      * @return
      */
-    public  Map<String, Object> getUserSessionKeyAndOpenID(String appId, String appSecret, String code){
+    public static Map<String, Object> getUserSessionKeyAndOpenID(String appId, String appSecret, String code){
         String requestUrl = openID_url.replace("APPID", appId).replace("APPSECRET", appSecret).replace("CODE", code);
         Map<String, Object> resultMap = new HashMap<>();
         //发起GET请求
-        JSONObject jsonObject = httpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
+        JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
         logger.info("用户openid和session_key:" + jsonObject.toString());
         if(jsonObject != null && jsonObject.containsKey("openid")){
             resultMap.put("openid", jsonObject.getString("openid"));
@@ -92,11 +86,11 @@ public class WeiXinUserUtil {
      * @param appSecret     //密钥
      * @return
      */
-    public  Token getToken(String appId, String appSecret){
+    public static Token getToken(String appId, String appSecret){
         Token token = null;
         String requestUrl = token_url.replace("APPID", appId).replace("APPSECRET", appSecret);
         //发起GET请求获取凭证
-        JSONObject jsonObject = httpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
+        JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
         System.out.println("getToken: "+jsonObject);
         if(jsonObject != null){
             try {
@@ -116,20 +110,20 @@ public class WeiXinUserUtil {
      * @param appSecret
      * @return
      */
-    public String getTokenByRedisCache(String appId, String appSecret){
-        logger.info("appId参数: "+ appId+" ;appSecret参数: " +appSecret);
-        String tokenCache ="";
-        if(!redisCacheUtil.hasKey(appId)){
-            String token = this.getToken(appId, appSecret).getAccessToken();
-            redisCacheUtil.setCacheObject(appId, token);
-            redisCacheUtil.expire(appId, 7200, TimeUnit.SECONDS);
-            tokenCache = token;
-            logger.info("Redis缓存中token信息: " + tokenCache);
-        }else {
-            tokenCache = redisCacheUtil.getCacheObject(appId);
-        }
-        return tokenCache;
-    }
+//    public String getTokenByRedisCache(String appId, String appSecret){
+//        logger.info("appId参数: "+ appId+" ;appSecret参数: " +appSecret);
+//        String tokenCache ="";
+//        if(!redisCacheUtil.hasKey(appId)){
+//            String token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
+//            redisCacheUtil.setCacheObject(appId, token);
+//            redisCacheUtil.expire(appId, 7200, TimeUnit.SECONDS);
+//            tokenCache = token;
+//            logger.info("Redis缓存中token信息: " + tokenCache);
+//        }else {
+//            tokenCache = redisCacheUtil.getCacheObject(appId);
+//        }
+//        return tokenCache;
+//    }
 
 
 }

+ 11 - 4
YijiaRestful/src/main/java/com/platform/yijia/utils/weixinapp/WxPushUtil.java

@@ -26,9 +26,6 @@ import java.util.concurrent.TimeUnit;
 public class WxPushUtil {
     @Resource
     private RedisCacheUtil redisCacheUtil;
-    @Resource
-    private WeiXinUserUtil weiXinUserUtil;
-
     private static Logger logger =(Logger) LoggerFactory.getLogger(WxPushUtil.class);
 
     /*
@@ -46,7 +43,17 @@ public class WxPushUtil {
         wxMpInMemoryConfigStorage.setAppId(appId);
         wxMpInMemoryConfigStorage.setSecret(appSecret);
         //公众号token缓存处理
-        String tokenCache = weiXinUserUtil.getTokenByRedisCache(appId, appSecret);
+        //String tokenCache = weiXinUserUtil.getTokenByRedisCache(appId, appSecret);
+        String tokenCache ="";
+        if(!redisCacheUtil.hasKey(appId)){
+            String token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
+            redisCacheUtil.setCacheObject(appId, token);
+            redisCacheUtil.expire(appId, 7200, TimeUnit.SECONDS);
+            tokenCache = token;
+            logger.info("Redis缓存中token信息: " + tokenCache);
+        }else {
+            tokenCache = redisCacheUtil.getCacheObject(appId);
+        }
         logger.info("token信息: " + tokenCache);
         wxMpInMemoryConfigStorage.setAccessToken(tokenCache);