提交代码

dev-discount
胡锐 3 years ago
parent 344d300193
commit ad60b67b2f
  1. 2
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 55
      hai-cweb/src/main/java/com/cweb/controller/CommonController.java
  3. 32
      hai-cweb/src/main/java/com/cweb/controller/HighUserController.java
  4. 4
      hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java
  5. 13
      hai-service/src/main/java/com/hai/common/utils/WxUtils.java

@ -109,6 +109,8 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/user/login") .excludePathPatterns("/user/login")
.excludePathPatterns("/user/unionPhoneLogin") .excludePathPatterns("/user/unionPhoneLogin")
.excludePathPatterns("/user/getUnionId") .excludePathPatterns("/user/getUnionId")
.excludePathPatterns("/user/setCacheParam")
.excludePathPatterns("/user/getCacheParam")
.excludePathPatterns("/order/orderToH5Pay") .excludePathPatterns("/order/orderToH5Pay")
.excludePathPatterns("/order/orderToPay") .excludePathPatterns("/order/orderToPay")
.excludePathPatterns("/test/*") .excludePathPatterns("/test/*")

@ -1,6 +1,13 @@
package com.cweb.controller; 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.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.entity.BsCompany; import com.hai.entity.BsCompany;
import com.hai.entity.SecConfig; import com.hai.entity.SecConfig;
import com.hai.entity.SecRegion; import com.hai.entity.SecRegion;
@ -10,6 +17,7 @@ import com.hai.service.CommonService;
import com.hai.service.SecConfigService; import com.hai.service.SecConfigService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.util.crypto.SHA1;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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<String, Object> 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);
}
}
} }

@ -205,37 +205,39 @@ public class HighUserController {
} }
} }
@RequestMapping(value="/setUserParam",method = RequestMethod.GET) @RequestMapping(value="/setCacheParam",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "设置用户参数") @ApiOperation(value = "设置用户参数")
public ResponseData setUserParam(@RequestParam(name = "param", required = true) String param,HttpServletRequest request) { public ResponseData setCacheParam(JSONObject body) {
try { try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
redisUtil.hset("USER_PARAM", userInfoModel.getHighUser().getPhone(), param, 60*60*60); if (body == null
return ResponseMsgUtil.success(redisUtil.hget("USER_PARAM", userInfoModel.getHighUser().getPhone())); || 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) { } catch (Exception e) {
log.error("CommonController --> getDictionaryByCodeTypeAndValue() error!", e); log.error("CommonController --> setCacheParam() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value="/getUserParam",method = RequestMethod.GET) @RequestMapping(value="/getCacheParam",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "获取设置用户参数") @ApiOperation(value = "获取设置用户参数")
public ResponseData getUserParam(HttpServletRequest request) { public ResponseData getCacheParam(@RequestParam(name = "key", required = true) String key) {
try { 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) { } catch (Exception e) {
log.error("CommonController --> getDictionaryByCodeTypeAndValue() error!", e); log.error("CommonController --> getCacheParam() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }

@ -90,11 +90,11 @@ public class HighUserDiscountController {
@ResponseBody @ResponseBody
@ApiOperation(value = "获取用户的优惠券列表") @ApiOperation(value = "获取用户的优惠券列表")
public ResponseData getUserDiscountList(@RequestParam(name = "status", required = false) Integer status, 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 = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize, @RequestParam(name = "pageSize", required = true) Integer pageSize,
HttpServletRequest request) { HttpServletRequest request) {
try { try {
// 用户 // 用户
SessionObject sessionObject = userCenter.getSessionObject(request); SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
@ -132,7 +132,6 @@ public class HighUserDiscountController {
@ApiOperation(value = "根据卡券,查询【可以使用】优惠券列表") @ApiOperation(value = "根据卡券,查询【可以使用】优惠券列表")
public ResponseData getDiscountListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,HttpServletRequest request) { public ResponseData getDiscountListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,HttpServletRequest request) {
try { try {
// 用户 // 用户
SessionObject sessionObject = userCenter.getSessionObject(request); SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
@ -141,7 +140,6 @@ public class HighUserDiscountController {
map.put("userId", userInfoModel.getHighUser().getId()); map.put("userId", userInfoModel.getHighUser().getId());
map.put("status", 1); map.put("status", 1);
List<HighDiscountUserRel> list = new ArrayList<>(); List<HighDiscountUserRel> list = new ArrayList<>();
// 查询用户的优惠券 // 查询用户的优惠券
List<HighDiscountUserRel> userRels = highDiscountUserRelService.getDiscountList(map); List<HighDiscountUserRel> userRels = highDiscountUserRelService.getDiscountList(map);

@ -8,6 +8,7 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder; import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.XppDriver; import com.thoughtworks.xstream.io.xml.XppDriver;
import net.sf.cglib.beans.BeanMap; 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.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.SSLContexts;
@ -247,7 +248,7 @@ public class WxUtils {
} }
} }
public static String generateSignature(final Map<String, Object> data, String key) throws Exception { public static String generateSignature(final Map<String, Object> data) throws Exception {
Set<String> keySet = data.keySet(); Set<String> keySet = data.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]); String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray); Arrays.sort(keyArray);
@ -256,11 +257,11 @@ public class WxUtils {
if (k.equals(WXPayConstants.FIELD_SIGN)) { if (k.equals(WXPayConstants.FIELD_SIGN)) {
continue; continue;
} }
if (data.get(k) != null) // 参数值为空,则不参与签名 if (StringUtils.isBlank(sb.toString())) {
sb.append(k).append("").append(data.get(k)).append(""); sb.append(k).append("=").append(data.get(k));
} } else {
if (key != null) { sb.append("&").append(k).append("=").append(data.get(k));
//sb.append("app_secret=").append(key); }
} }
return sb.toString(); return sb.toString();
} }

Loading…
Cancel
Save