提交代码

dev-discount
袁野 2 years ago
parent 3ed726289c
commit 70d5334e2a
  1. 10
      hai-service/src/main/java/com/hai/service/ApiIpAddressService.java
  2. 10
      hai-service/src/main/java/com/hai/service/ApiProductService.java
  3. 11
      hai-service/src/main/java/com/hai/service/impl/ApiIpAddressServiceImpl.java
  4. 4
      hai-service/src/main/java/com/hai/service/impl/SecConfigServiceImpl.java
  5. 116
      v1/src/main/java/com/v1/controller/ApiOrderController.java
  6. 17
      v1/src/main/java/com/v1/controller/ThirdPartyController.java

@ -65,4 +65,14 @@ public interface ApiIpAddressService {
*/ */
List<ApiIpAddress> getApiIpAddressByList(Map<String , Object> map); List<ApiIpAddress> getApiIpAddressByList(Map<String , Object> map);
/**
* @Author Sum1Dream
* @Name validationIpAddressLegal
* @Description // 验证IP地址合法性
* @Date 09:49 2022/12/13
* @Param [mchId, ipAddress]
* @Return java.lang.Boolean
*/
Boolean validationIpAddressLegal(String mchId , String ipAddress);
} }

@ -148,8 +148,10 @@ public interface ApiProductService {
*/ */
List<ApiStarbucksProducts> findStarbucksByCategoryName(String categoryName); List<ApiStarbucksProducts> findStarbucksByCategoryName(String categoryName);
// 配置产品
void ProductConfig(JSONObject object); void ProductConfig(JSONObject object);
// 更新产品配置
void updateProductConfig(JSONObject object); void updateProductConfig(JSONObject object);
/** /**
@ -224,6 +226,14 @@ public interface ApiProductService {
*/ */
void insertCity(ApiCity apiCity); void insertCity(ApiCity apiCity);
/**
* @Author Sum1Dream
* @Name updateCity
* @Description // 更新城市
* @Date 09:20 2022/12/13
* @Param [apiCity]
* @Return void
*/
void updateCity(ApiCity apiCity); void updateCity(ApiCity apiCity);
/** /**

@ -50,4 +50,15 @@ public class ApiIpAddressServiceImpl implements ApiIpAddressService {
public List<ApiIpAddress> getApiIpAddressByList(Map<String, Object> map) { public List<ApiIpAddress> getApiIpAddressByList(Map<String, Object> map) {
return null; return null;
} }
@Override
public Boolean validationIpAddressLegal(String mchId, String ipAddress) {
ApiIpAddressExample example = new ApiIpAddressExample();
example.createCriteria().andMchIdEqualTo(mchId).andIpAddressEqualTo(ipAddress);
List<ApiIpAddress> list = apiIpAddressMapper.selectByExample(example);
return list.size()>0;
}
} }

@ -5,18 +5,14 @@ import com.hai.common.utils.WxUtils;
import com.hai.dao.SecConfigMapper; import com.hai.dao.SecConfigMapper;
import com.hai.entity.SecConfig; import com.hai.entity.SecConfig;
import com.hai.entity.SecConfigExample; import com.hai.entity.SecConfigExample;
import com.hai.entity.SecDictionary;
import com.hai.entity.SecDictionaryExample;
import com.hai.service.ApiMerchantsService; import com.hai.service.ApiMerchantsService;
import com.hai.service.SecConfigService; import com.hai.service.SecConfigService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedMap;
@Service("secConfigServiceImpl") @Service("secConfigServiceImpl")
public class SecConfigServiceImpl implements SecConfigService { public class SecConfigServiceImpl implements SecConfigService {

@ -1,12 +1,128 @@
package com.v1.controller; package com.v1.controller;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.ApiMerchants;
import com.hai.entity.ApiProductConfig;
import com.hai.model.ResponseData;
import com.hai.service.*;
import com.v1.config.ToolConfig;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
@Controller @Controller
@RequestMapping(value = "/apiOrder") @RequestMapping(value = "/apiOrder")
@Api(value = "API订单接口") @Api(value = "API订单接口")
public class ApiOrderController { public class ApiOrderController {
private static Logger log = LoggerFactory.getLogger(RechargeProductController.class);
@Resource
private ApiMerchantsService apiMerchantsService;
@Resource
private SecConfigService secConfigService;
@Resource
private ApiProductService apiProductService;
@Resource
private ApiOpenService apiOpenService;
@RequestMapping(value = "/createOrder", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "充值预下单")
public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) {
try {
String ip = "";
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for");
}
if (!secConfigService.isConfig("IP_WHITE" , ip)) {
log.error("createOrder error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
if (StringUtils.isBlank(object.getString("mobile")) ||
StringUtils.isBlank(object.getString("apiProductId")) ||
StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("orderType")) ||
StringUtils.isBlank(object.getString("timetable")) ||
StringUtils.isBlank(object.getString("orderNo")) ||
StringUtils.isBlank(object.getString("notifyUrl")) ||
StringUtils.isBlank(object.getString("sign")) ||
StringUtils.isBlank(object.getString("merchId"))
) {
log.error("createOrder error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
if (apiMerchants == null) {
log.error("createOrder error!", "商户错误!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
}
Map<String, Object> productMap = new HashMap<>();
productMap.put("id" , object.getString("apiConfigProductId"));
productMap.put("merchantsId" , apiMerchants.getId());
ApiProductConfig apiProductConfig = apiProductService.findMchProduct(productMap);
if (apiProductConfig == null) {
log.error("createOrder error!", " 商品错误!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PRODUCT_ERROR);
}
Map<String , Object> map = new HashMap<>();
map.put("mobile" , object.getString("mobile"));
map.put("apiConfigProductId" , object.getString("apiConfigProductId"));
map.put("timetable" , object.getString("timetable"));
map.put("orderNo" , object.getString("orderNo"));
map.put("notifyUrl" , object.getString("notifyUrl"));
map.put("apiKey" , object.getString("apiKey"));
map.put("merchId" , object.getString("merchId"));
if (!secConfigService.isSignVerify(map, object.getString("sign"))) {
log.error("createOrder error!", "签名校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
log.error("getRechargeProduct error!", "请求时间超过15分钟!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT);
}
apiOpenService.createOrder(object , apiMerchants , apiProductConfig);
return ResponseMsgUtil.success("下单成功");
} catch (Exception e) {
log.error("HighOpenApiController --> createOrder() error!", e);
return ResponseMsgUtil.exception(e);
}
}
} }

@ -45,9 +45,12 @@ public class ThirdPartyController {
@Resource @Resource
private SecConfigService secConfigService; private SecConfigService secConfigService;
@Resource
private ApiIpAddressService apiIpAddressService;
@RequestMapping(value = "/getAllCities", method = RequestMethod.POST) @RequestMapping(value = "/getAllCities", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询所有城市") @ApiOperation(value = "查询可用城市")
public ResponseData getAllCities(@RequestBody JSONObject object , HttpServletRequest request ) { public ResponseData getAllCities(@RequestBody JSONObject object , HttpServletRequest request ) {
try { try {
@ -59,10 +62,6 @@ public class ThirdPartyController {
ip = request.getHeader("x-forwarded-for"); ip = request.getHeader("x-forwarded-for");
} }
if (!secConfigService.isConfig("IP_WHITE" , ip)) {
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
if (StringUtils.isBlank(object.getString("apiKey")) || if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("merchId")) ||
@ -72,6 +71,12 @@ public class ThirdPartyController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
} }
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) {
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!");
}
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
if (apiMerchants == null) { if (apiMerchants == null) {
@ -214,8 +219,6 @@ public class ThirdPartyController {
Map<String , Object> map = new HashMap<>(); Map<String , Object> map = new HashMap<>();
map.put("apiKey" , object.getString("apiKey")); map.put("apiKey" , object.getString("apiKey"));
map.put("merchId" , object.getString("merchId")); map.put("merchId" , object.getString("merchId"));
map.put("pageSize" , object.getString("pageSize"));
map.put("pageIndex" , object.getString("pageIndex"));
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { if (!secConfigService.isSignVerify(map , object.getString("sign"))) {
log.error("getRechargeProduct error!", "签名校验失败!"); log.error("getRechargeProduct error!", "签名校验失败!");

Loading…
Cancel
Save