diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 8d876b53..01d7b0c9 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -109,6 +109,8 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/user/login") .excludePathPatterns("/user/unionPhoneLogin") .excludePathPatterns("/user/getUnionId") + .excludePathPatterns("/user/setCacheParam") + .excludePathPatterns("/user/getCacheParam") .excludePathPatterns("/order/orderToH5Pay") .excludePathPatterns("/order/orderToPay") .excludePathPatterns("/test/*") diff --git a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java index beb4cdc0..f751abda 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java @@ -1,6 +1,13 @@ package com.cweb.controller; +import com.alibaba.fastjson.JSONObject; +import com.cweb.config.SysConst; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.common.utils.WxUtils; import com.hai.entity.BsCompany; import com.hai.entity.SecConfig; import com.hai.entity.SecRegion; @@ -10,6 +17,7 @@ import com.hai.service.CommonService; import com.hai.service.SecConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import me.chanjar.weixin.common.util.crypto.SHA1; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -223,4 +231,51 @@ public class CommonController { } } + @RequestMapping(value = "/getScanCodePageHtmlSign", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获取扫码页面签名") + public ResponseData getScanCodePageHtmlSign(@RequestBody JSONObject body) { + try { + if (body == null || StringUtils.isBlank(body.getString("url"))) { + log.error("getH5UserInfo error!", "参数校验失败" ); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + Map params = new HashMap<>(); + params.put("appid", SysConst.getSysConfig().getWxH5AppId()); + params.put("secret", SysConst.getSysConfig().getWxH5AppSecret()); + params.put("grant_type", "client_credential"); + + JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params); + if (accessTokenObject == null) { + log.error("getH5UserInfo error!", "获取微信access_token失败" ); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取微信access_token失败"); + } + + params.clear(); + params.put("access_token", accessTokenObject.getString("access_token")); + params.put("type", "jsapi"); + JSONObject jsapiTicketObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", params); + if (jsapiTicketObject == null) { + log.error("getH5UserInfo error!", "获取微信jsapi_ticket失败" ); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取微信jsapi_ticket失败"); + } + + params = new HashMap<>(); + params.put("noncestr", WxUtils.makeNonStr()); + params.put("jsapi_ticket", jsapiTicketObject.getString("ticket")); + params.put("timestamp", System.currentTimeMillis() / 1000); + params.put("url", body.getString("url")); + + String signatureStr = WxUtils.generateSignature(params); + System.out.println(signatureStr); + params.put("signature", SHA1.gen(signatureStr)); + return ResponseMsgUtil.success(params); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java index efb82c4f..12579214 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java @@ -205,37 +205,39 @@ public class HighUserController { } } - @RequestMapping(value="/setUserParam",method = RequestMethod.GET) + @RequestMapping(value="/setCacheParam",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "设置用户参数") - public ResponseData setUserParam(@RequestParam(name = "param", required = true) String param,HttpServletRequest request) { + public ResponseData setCacheParam(JSONObject body) { try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - redisUtil.hset("USER_PARAM", userInfoModel.getHighUser().getPhone(), param, 60*60*60); - return ResponseMsgUtil.success(redisUtil.hget("USER_PARAM", userInfoModel.getHighUser().getPhone())); + if (body == null + || StringUtils.isBlank(body.getString("key")) + || StringUtils.isBlank(body.getString("value"))) { + log.error("HighUserController --> setUserPayPwd() error!", "请求参数校验失败"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + redisUtil.hset("PROVISIONAL_CACHE_PARAM", body.getString("key"), body.getString("value"), 60*5); + + return ResponseMsgUtil.success("设置成功"); } catch (Exception e) { - log.error("CommonController --> getDictionaryByCodeTypeAndValue() error!", e); + log.error("CommonController --> setCacheParam() error!", e); return ResponseMsgUtil.exception(e); } } - @RequestMapping(value="/getUserParam",method = RequestMethod.GET) + @RequestMapping(value="/getCacheParam",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取设置用户参数") - public ResponseData getUserParam(HttpServletRequest request) { + public ResponseData getCacheParam(@RequestParam(name = "key", required = true) String key) { try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - return ResponseMsgUtil.success(redisUtil.hget("USER_PARAM", userInfoModel.getHighUser().getPhone())); + return ResponseMsgUtil.success(redisUtil.hget("PROVISIONAL_CACHE_PARAM", key)); } catch (Exception e) { - log.error("CommonController --> getDictionaryByCodeTypeAndValue() error!", e); + log.error("CommonController --> getCacheParam() error!", e); return ResponseMsgUtil.exception(e); } } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java index 31a40005..d5ac138a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -90,11 +90,11 @@ public class HighUserDiscountController { @ResponseBody @ApiOperation(value = "获取用户的优惠券列表") public ResponseData getUserDiscountList(@RequestParam(name = "status", required = false) Integer status, + @RequestParam(name = "useScope", required = false) Integer useScope, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { - // 用户 SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); @@ -132,7 +132,6 @@ public class HighUserDiscountController { @ApiOperation(value = "根据卡券,查询【可以使用】优惠券列表") public ResponseData getDiscountListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,HttpServletRequest request) { try { - // 用户 SessionObject sessionObject = userCenter.getSessionObject(request); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); @@ -141,7 +140,6 @@ public class HighUserDiscountController { map.put("userId", userInfoModel.getHighUser().getId()); map.put("status", 1); - List list = new ArrayList<>(); // 查询用户的优惠券 List userRels = highDiscountUserRelService.getDiscountList(map); diff --git a/hai-service/src/main/java/com/hai/common/utils/WxUtils.java b/hai-service/src/main/java/com/hai/common/utils/WxUtils.java index a9c152b4..4df0fdc2 100644 --- a/hai-service/src/main/java/com/hai/common/utils/WxUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/WxUtils.java @@ -8,6 +8,7 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.naming.NoNameCoder; import com.thoughtworks.xstream.io.xml.XppDriver; import net.sf.cglib.beans.BeanMap; +import org.apache.commons.lang3.StringUtils; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLContexts; @@ -247,7 +248,7 @@ public class WxUtils { } } - public static String generateSignature(final Map data, String key) throws Exception { + public static String generateSignature(final Map data) throws Exception { Set keySet = data.keySet(); String[] keyArray = keySet.toArray(new String[keySet.size()]); Arrays.sort(keyArray); @@ -256,11 +257,11 @@ public class WxUtils { if (k.equals(WXPayConstants.FIELD_SIGN)) { continue; } - if (data.get(k) != null) // 参数值为空,则不参与签名 - sb.append(k).append("").append(data.get(k)).append(""); - } - if (key != null) { - //sb.append("app_secret=").append(key); + if (StringUtils.isBlank(sb.toString())) { + sb.append(k).append("=").append(data.get(k)); + } else { + sb.append("&").append(k).append("=").append(data.get(k)); + } } return sb.toString(); }