parent
a04ed18fb7
commit
3ed726289c
@ -0,0 +1,158 @@ |
|||||||
|
package com.bweb.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.security.SessionObject; |
||||||
|
import com.hai.common.security.UserCenter; |
||||||
|
import com.hai.common.utils.RedisUtil; |
||||||
|
import com.hai.common.utils.ResponseMsgUtil; |
||||||
|
import com.hai.entity.ApiIpAddress; |
||||||
|
import com.hai.entity.ApiMerchants; |
||||||
|
import com.hai.model.ResponseData; |
||||||
|
import com.hai.model.UserInfoModel; |
||||||
|
import com.hai.service.ApiIpAddressService; |
||||||
|
import com.hai.service.ApiMerchantsService; |
||||||
|
import com.hai.service.CommonService; |
||||||
|
import com.hai.service.SecConfigService; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(value = "/apiIpAddress") |
||||||
|
@Api(value = "Ip地址管理") |
||||||
|
public class ApiIpAddressController { |
||||||
|
|
||||||
|
Logger log = LoggerFactory.getLogger(ApiMemberProductController.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiIpAddressService apiIpAddressService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private UserCenter userCenter; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private SecConfigService secConfigService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value="/editApiIpAddress",method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "编辑ip地址") |
||||||
|
public ResponseData editApiIpAddress(@RequestBody ApiIpAddress apiIpAddress, HttpServletRequest request) { |
||||||
|
try { |
||||||
|
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||||
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||||
|
if (userInfoModel.getBsCompany() == null) { |
||||||
|
log.error("HighMerchantController -> updateMerchant() error!","该主角色没有权限"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); |
||||||
|
} |
||||||
|
|
||||||
|
if (apiIpAddress.getMchId() == null) { |
||||||
|
log.error("ApiMemberProductController -> insertMemberProduct() error!","参数错误"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||||
|
} |
||||||
|
|
||||||
|
ApiIpAddress apiIpAddressEdit = apiIpAddressService.findByMchId(apiIpAddress.getMchId()); |
||||||
|
|
||||||
|
// 判断是否存在ip地址内容
|
||||||
|
if (apiIpAddressEdit == null ) { |
||||||
|
apiIpAddress.setCreateTime(new Date()); |
||||||
|
apiIpAddress.setUpdateTime(new Date()); |
||||||
|
apiIpAddressService.insertApiIpAddress(apiIpAddress); |
||||||
|
} else { |
||||||
|
apiIpAddressEdit.setUpdateTime(new Date()); |
||||||
|
apiIpAddressEdit.setIpAddress(apiIpAddress.getIpAddress()); |
||||||
|
apiIpAddressService.updateApiIpAddress(apiIpAddressEdit); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseMsgUtil.success("新增成功"); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("ApiMerchantsController -> insertMerchant() error!",e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/findByMchId", method = RequestMethod.GET) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "根据商户号查询详情") |
||||||
|
public ResponseData findByMchId(@RequestParam(value = "mchId", required = true) String mchId) { |
||||||
|
try { |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(apiIpAddressService.findByMchId(mchId)); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("OutRechargePriceController --> findById() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping(value = "/getSecConfigList", method = RequestMethod.GET) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "根据商户号查询已配置接口") |
||||||
|
public ResponseData getSecConfigList(@RequestParam(value = "mchId", required = true) String mchId) { |
||||||
|
try { |
||||||
|
|
||||||
|
Map<String , Object> map = new HashMap<>(); |
||||||
|
map.put("codeValue", mchId); |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(secConfigService.getSecConfigList(map)); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("OutRechargePriceController --> findById() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping(value="/configMerchant",method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "配置门店可用接口") |
||||||
|
public ResponseData configMerchant(@RequestBody JSONObject object, HttpServletRequest request) { |
||||||
|
try { |
||||||
|
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||||
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||||
|
if (userInfoModel.getBsCompany() == null) { |
||||||
|
log.error("HighMerchantController -> updateMerchant() error!","该主角色没有权限"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); |
||||||
|
} |
||||||
|
|
||||||
|
if (object.getString("mchId") == null || object.getString("configProduct") == null) { |
||||||
|
log.error("ApiMemberProductController -> insertMemberProduct() error!","参数错误"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||||
|
} |
||||||
|
|
||||||
|
ApiMerchants merchants = apiMerchantsService.findByMchId(object.getString("mchId")); |
||||||
|
|
||||||
|
if (merchants == null) { |
||||||
|
log.error("ApiMemberProductController -> insertMemberProduct() error!","商户状态错误"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户状态错误"); |
||||||
|
} |
||||||
|
|
||||||
|
secConfigService.configMerchant(object.getString("mchId") , object.getString("configProduct")); |
||||||
|
|
||||||
|
return ResponseMsgUtil.success("配置成功"); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("ApiMerchantsController -> insertMerchant() error!",e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
package com.hai.service; |
||||||
|
|
||||||
|
import com.hai.entity.ApiAmountRecord; |
||||||
|
import com.hai.entity.ApiIpAddress; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @serviceName ApiIpAddressService.java |
||||||
|
* @author Sum1Dream |
||||||
|
* @version 1.0.0 |
||||||
|
* @Description // Api商户IP地址管理
|
||||||
|
* @createTime 14:18 2022/12/6 |
||||||
|
**/ |
||||||
|
public interface ApiIpAddressService { |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name insertApiIpAddress |
||||||
|
* @Description // 新增ip地址内容
|
||||||
|
* @Date 14:21 2022/12/6 |
||||||
|
* @Param [apiIpAddress] |
||||||
|
* @Return void |
||||||
|
*/ |
||||||
|
void insertApiIpAddress(ApiIpAddress apiIpAddress); |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name updateApiIpAddress |
||||||
|
* @Description // 修改IP地址内容
|
||||||
|
* @Date 15:29 2022/12/6 |
||||||
|
* @Param [apiIpAddress] |
||||||
|
* @Return void |
||||||
|
*/ |
||||||
|
void updateApiIpAddress(ApiIpAddress apiIpAddress); |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name findById |
||||||
|
* @Description // 查询ip地址详情
|
||||||
|
* @Date 14:19 2022/12/6 |
||||||
|
* @Param [id] |
||||||
|
* @Return com.hai.entity.ApiIpAddress |
||||||
|
*/ |
||||||
|
ApiIpAddress findById(Long id); |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name findByMchId |
||||||
|
* @Description // 根据商户号查询IP地址内容
|
||||||
|
* @Date 14:23 2022/12/6 |
||||||
|
* @Param [mchId] |
||||||
|
* @Return com.hai.entity.ApiIpAddress |
||||||
|
*/ |
||||||
|
ApiIpAddress findByMchId(String mchId); |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name getApiIpAddressByList |
||||||
|
* @Description // 查询IP地址列表
|
||||||
|
* @Date 14:19 2022/12/6 |
||||||
|
* @Param [map] |
||||||
|
* @Return java.util.List<com.hai.entity.ApiIpAddress> |
||||||
|
*/ |
||||||
|
List<ApiIpAddress> getApiIpAddressByList(Map<String , Object> map); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package com.hai.service.impl; |
||||||
|
|
||||||
|
import com.hai.dao.ApiIpAddressMapper; |
||||||
|
import com.hai.entity.ApiIpAddress; |
||||||
|
import com.hai.entity.ApiIpAddressExample; |
||||||
|
import com.hai.service.ApiIpAddressService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Service("apiIpAddressService") |
||||||
|
public class ApiIpAddressServiceImpl implements ApiIpAddressService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiIpAddressMapper apiIpAddressMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void insertApiIpAddress(ApiIpAddress apiIpAddress) { |
||||||
|
apiIpAddressMapper.insert(apiIpAddress); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateApiIpAddress(ApiIpAddress apiIpAddress) { |
||||||
|
apiIpAddressMapper.updateByPrimaryKey(apiIpAddress); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ApiIpAddress findById(Long id) { |
||||||
|
return apiIpAddressMapper.selectByPrimaryKey(id); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ApiIpAddress findByMchId(String mchId) { |
||||||
|
ApiIpAddressExample example = new ApiIpAddressExample(); |
||||||
|
ApiIpAddressExample.Criteria criteria = example.createCriteria(); |
||||||
|
criteria.andMchIdEqualTo(mchId); |
||||||
|
|
||||||
|
List<ApiIpAddress> list = apiIpAddressMapper.selectByExample(example); |
||||||
|
|
||||||
|
if (list.size() > 0) { |
||||||
|
return list.get(0); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<ApiIpAddress> getApiIpAddressByList(Map<String, Object> map) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
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.model.ResponseData; |
||||||
|
import com.hai.service.*; |
||||||
|
import com.v1.config.ToolConfig; |
||||||
|
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.web.bind.annotation.RequestBody; |
||||||
|
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 |
||||||
|
@RequestMapping(value = "/apiMerchants") |
||||||
|
@Api(value = "API商户接口") |
||||||
|
public class ApiMerchantsController { |
||||||
|
private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private SecConfigService secConfigService; |
||||||
|
|
||||||
|
@RequestMapping(value = "/checkAccountBalance", method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "查询帐户余额") |
||||||
|
public ResponseData checkAccountBalance(@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("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(object.getString("apiKey")) || |
||||||
|
StringUtils.isBlank(object.getString("merchId")) || |
||||||
|
StringUtils.isBlank(object.getString("timetable")) || |
||||||
|
StringUtils.isBlank(object.getString("sign")) |
||||||
|
) { |
||||||
|
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
if (apiMerchants == null) { |
||||||
|
log.error("getRechargeProduct error!", "商户号错误!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String , Object> map = new HashMap<>(); |
||||||
|
map.put("apiKey" , object.getString("apiKey")); |
||||||
|
map.put("timetable" , object.getString("timetable")); |
||||||
|
map.put("merchId" , object.getString("merchId")); |
||||||
|
|
||||||
|
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||||
|
log.error("getRechargeProduct 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); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(apiMerchants.getAmounts()); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package com.v1.controller; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(value = "/apiOrder") |
||||||
|
@Api(value = "API订单接口") |
||||||
|
public class ApiOrderController { |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue