配置文件
This commit is contained in:
parent
1d0bba6f73
commit
569837f536
|
|
@ -62,26 +62,26 @@ public class WashClothingOrderServiceImpl extends ServiceImpl<WashClothingOrderM
|
|||
private WashClothingPriceMapper washClothingPriceMapper;
|
||||
|
||||
|
||||
@Value("${niu.niupayurl}")
|
||||
private String niupayurl;
|
||||
|
||||
@Value("${niu.niusearchuserurl}")
|
||||
private String niusearchuserurl;
|
||||
|
||||
@Value("${niu.niupayreturnurl}")
|
||||
private String niupayreturnurl;
|
||||
|
||||
@Value("${niu.applicationid}")
|
||||
private String applicationid;
|
||||
|
||||
@Value("${niu.applicationidpsw}")
|
||||
private String applicationidpsw;
|
||||
|
||||
@Value("${niu.sncode}")
|
||||
private String sncode;
|
||||
|
||||
@Value("${niu.serialnum}")
|
||||
private String serialnum;
|
||||
// @Value("${niu.niupayurl}")
|
||||
// private String niupayurl;
|
||||
//
|
||||
// @Value("${niu.niusearchuserurl}")
|
||||
// private String niusearchuserurl;
|
||||
//
|
||||
// @Value("${niu.niupayreturnurl}")
|
||||
// private String niupayreturnurl;
|
||||
//
|
||||
// @Value("${niu.applicationid}")
|
||||
// private String applicationid;
|
||||
//
|
||||
// @Value("${niu.applicationidpsw}")
|
||||
// private String applicationidpsw;
|
||||
//
|
||||
// @Value("${niu.sncode}")
|
||||
// private String sncode;
|
||||
//
|
||||
// @Value("${niu.serialnum}")
|
||||
// private String serialnum;
|
||||
|
||||
@Resource
|
||||
private BaseService baseService;
|
||||
|
|
@ -226,151 +226,151 @@ public class WashClothingOrderServiceImpl extends ServiceImpl<WashClothingOrderM
|
|||
//流水号
|
||||
greenOrder.setOrdno(OrderNumberGeneratorUtils.generateOrderNumber());
|
||||
//
|
||||
return payByNiu(userInfo, greenOrder);
|
||||
return null;
|
||||
//新增绿植订单
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付相关接入第三方小牛支付
|
||||
*
|
||||
* @param userInfo
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
private AjaxResult payByNiu(GreenUserInfo userInfo, WashClothingOrder dto) {
|
||||
//1 先查询人员对应的卡号
|
||||
//应用秘钥
|
||||
String appsecret = applicationidpsw;
|
||||
//传参
|
||||
HashMap<Object, Object> bodyMap = new HashMap<>(2);
|
||||
if (StringUtils.isEmpty(userInfo.getMobile())) {
|
||||
log.info("下单没有配置手机号,无法下单,请联系管理员配置");
|
||||
return AjaxResult.error("用户信息获取失败!");
|
||||
}
|
||||
//根据手机号查询
|
||||
bodyMap.put("mobile", userInfo.getMobile());
|
||||
// bodyMap.put("mobile", "15996330508");
|
||||
//请求内容字典排序,转换为String
|
||||
String content = JSON.toJSONString(bodyMap, SerializerFeature.MapSortField, SerializerFeature.WriteMapNullValue);
|
||||
log.info("请求内容转换为JSON字符串,字典排序:{}", content);
|
||||
//构造请求验签参数方法
|
||||
|
||||
Map<String, Object> map = makeSign(content, appsecret, bodyMap);
|
||||
HttpRequest request = HttpUtil.createPost(niusearchuserurl);
|
||||
log.info("request=" + JSONUtil.toJsonStr(map));
|
||||
request.body(JSONUtil.toJsonStr(map), ContentType.JSON.toString());
|
||||
HttpResponse response = request.execute();
|
||||
log.info("response={}", response.body());
|
||||
//转成实体类
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
ApiResponse apiResponse = objectMapper.readValue(response.body(), ApiResponse.class);
|
||||
ResponseDatad data = apiResponse.getData();
|
||||
List<Customer> customerList = data.getCustomerList();
|
||||
if (StringUtils.isEmpty(customerList)) {
|
||||
log.info("没有找到对应餐卡,无法下单,请联系管理员配置");
|
||||
return AjaxResult.error("没有找到对应餐卡,无法下单,请联系管理员配置");
|
||||
}
|
||||
Customer customer = customerList.get(0);
|
||||
//传参
|
||||
HashMap<Object, Object> bodyMapForPayContent = new HashMap<>(2);
|
||||
//构建 content
|
||||
intoMapEnity(bodyMapForPayContent, dto, customer);
|
||||
String payContent = JSON.toJSONString(bodyMapForPayContent, SerializerFeature.MapSortField, SerializerFeature.WriteMapNullValue);
|
||||
log.info("content: " + payContent);
|
||||
Map<String, Object> payBodyMap = makeSign(payContent, appsecret, bodyMapForPayContent);
|
||||
|
||||
HttpRequest requestForPay = HttpUtil.createPost(niupayurl);
|
||||
log.info("request=" + JSONUtil.toJsonStr(payBodyMap));
|
||||
requestForPay.body(JSONUtil.toJsonStr(payBodyMap), ContentType.JSON.toString());
|
||||
HttpResponse responseForPay = requestForPay.execute();
|
||||
log.info("responseForPay={}", responseForPay.body());
|
||||
//转成实体类响应数据
|
||||
ApiResponseForPay apiResponseForPay = objectMapper.readValue(responseForPay.body(), ApiResponseForPay.class);
|
||||
if (apiResponseForPay == null) {
|
||||
log.error("扣款食堂卡失败,请检查");
|
||||
return AjaxResult.error("扣款食堂卡失败,请检查");
|
||||
}
|
||||
if (StringUtils.isNotNull(apiResponseForPay) && apiResponseForPay.getCode() == 10000) {
|
||||
boolean b = saveOrUpdate(dto);
|
||||
Double moneyCount = 0.00;
|
||||
if (StringUtils.isNotNull(dto.getId())) {
|
||||
//增加 绿植订单信息品类
|
||||
if (StringUtils.isNotEmpty(dto.getOrderInfoList())) {
|
||||
for (WashClothingOrderInfo greenOrderInfo : dto.getOrderInfoList()) {
|
||||
greenOrderInfo.setOrderId(dto.getId());
|
||||
int insert = washClothingOrderInfoMapper.insert(greenOrderInfo);
|
||||
if (insert == 1) {
|
||||
// 统计这一单的金额
|
||||
moneyCount = moneyCount + (greenOrderInfo.getGreenPrice() * greenOrderInfo.getClothingNum());
|
||||
}
|
||||
}
|
||||
return AjaxResult.success("选购成功,消费金额为: " + moneyCount);
|
||||
} else {
|
||||
return AjaxResult.error("请选购对应洗衣项目");
|
||||
}
|
||||
}
|
||||
return AjaxResult.error("洗衣项目新增失败");
|
||||
}
|
||||
if (StringUtils.isNotNull(apiResponseForPay)) {
|
||||
return AjaxResult.error("小牛支付提示:" + apiResponseForPay.getMsg());
|
||||
}
|
||||
return AjaxResult.error("支付有误,请联系管理员");
|
||||
} catch (Exception e) {
|
||||
log.error("下单失败");
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("下单失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void intoMapEnity(HashMap bodyMap, WashClothingOrder dto, Customer customer) {
|
||||
//金额
|
||||
Double usePrice = dto.getUsePrice();
|
||||
int convertedPrice = (int) (usePrice * 100);
|
||||
bodyMap.put("amount", convertedPrice);
|
||||
//人员 id
|
||||
bodyMap.put("custId", Long.valueOf(customer.getCustId()));
|
||||
//流水号
|
||||
bodyMap.put("macOrdId", dto.getOrdno());
|
||||
//sn码
|
||||
bodyMap.put("machineSn", sncode);
|
||||
//
|
||||
bodyMap.put("nuClearMode", 2);
|
||||
|
||||
bodyMap.put("ordTime", DateUtils.formatDate(dto.getOrderTime()));
|
||||
|
||||
bodyMap.put("deliveryType", "2");
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Object> makeSign(String content, String appsecret, HashMap<Object, Object> bodyMap) {
|
||||
Map<String, Object> map = new TreeMap<>();
|
||||
map.put("appid", applicationid);
|
||||
map.put("version", "1.0.0");
|
||||
map.put("signtype", "md5");
|
||||
map.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
||||
map.put("nonce", RandomUtil.randomNumbers(10));
|
||||
map.put("content", content);
|
||||
//生成sign,防篡改
|
||||
String toSignStr = Joiner.on("&")
|
||||
.useForNull("")
|
||||
.withKeyValueSeparator("=")
|
||||
.join(map) + "&appsecret=" + appsecret;
|
||||
log.info("所有参数字典排序,待加签String:{}", toSignStr);
|
||||
|
||||
// md5/sha256 加签(其他方式待提供)
|
||||
String sign = DigestUtils.md5Hex(toSignStr).toUpperCase();
|
||||
System.err.println("sign: " + sign);
|
||||
log.info("加签String:{}", sign);
|
||||
map.put("sign", sign);
|
||||
|
||||
//post请求
|
||||
map.replace("content", bodyMap);
|
||||
return map;
|
||||
}
|
||||
// /**
|
||||
// * 支付相关接入第三方小牛支付
|
||||
// *
|
||||
// * @param userInfo
|
||||
// * @param dto
|
||||
// * @return
|
||||
// */
|
||||
// private AjaxResult payByNiu(GreenUserInfo userInfo, WashClothingOrder dto) {
|
||||
// //1 先查询人员对应的卡号
|
||||
// //应用秘钥
|
||||
// String appsecret = applicationidpsw;
|
||||
// //传参
|
||||
// HashMap<Object, Object> bodyMap = new HashMap<>(2);
|
||||
// if (StringUtils.isEmpty(userInfo.getMobile())) {
|
||||
// log.info("下单没有配置手机号,无法下单,请联系管理员配置");
|
||||
// return AjaxResult.error("用户信息获取失败!");
|
||||
// }
|
||||
// //根据手机号查询
|
||||
// bodyMap.put("mobile", userInfo.getMobile());
|
||||
//// bodyMap.put("mobile", "15996330508");
|
||||
// //请求内容字典排序,转换为String
|
||||
// String content = JSON.toJSONString(bodyMap, SerializerFeature.MapSortField, SerializerFeature.WriteMapNullValue);
|
||||
// log.info("请求内容转换为JSON字符串,字典排序:{}", content);
|
||||
// //构造请求验签参数方法
|
||||
//
|
||||
// Map<String, Object> map = makeSign(content, appsecret, bodyMap);
|
||||
// HttpRequest request = HttpUtil.createPost(niusearchuserurl);
|
||||
// log.info("request=" + JSONUtil.toJsonStr(map));
|
||||
// request.body(JSONUtil.toJsonStr(map), ContentType.JSON.toString());
|
||||
// HttpResponse response = request.execute();
|
||||
// log.info("response={}", response.body());
|
||||
// //转成实体类
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// try {
|
||||
// ApiResponse apiResponse = objectMapper.readValue(response.body(), ApiResponse.class);
|
||||
// ResponseDatad data = apiResponse.getData();
|
||||
// List<Customer> customerList = data.getCustomerList();
|
||||
// if (StringUtils.isEmpty(customerList)) {
|
||||
// log.info("没有找到对应餐卡,无法下单,请联系管理员配置");
|
||||
// return AjaxResult.error("没有找到对应餐卡,无法下单,请联系管理员配置");
|
||||
// }
|
||||
// Customer customer = customerList.get(0);
|
||||
// //传参
|
||||
// HashMap<Object, Object> bodyMapForPayContent = new HashMap<>(2);
|
||||
// //构建 content
|
||||
// intoMapEnity(bodyMapForPayContent, dto, customer);
|
||||
// String payContent = JSON.toJSONString(bodyMapForPayContent, SerializerFeature.MapSortField, SerializerFeature.WriteMapNullValue);
|
||||
// log.info("content: " + payContent);
|
||||
// Map<String, Object> payBodyMap = makeSign(payContent, appsecret, bodyMapForPayContent);
|
||||
//
|
||||
// HttpRequest requestForPay = HttpUtil.createPost(niupayurl);
|
||||
// log.info("request=" + JSONUtil.toJsonStr(payBodyMap));
|
||||
// requestForPay.body(JSONUtil.toJsonStr(payBodyMap), ContentType.JSON.toString());
|
||||
// HttpResponse responseForPay = requestForPay.execute();
|
||||
// log.info("responseForPay={}", responseForPay.body());
|
||||
// //转成实体类响应数据
|
||||
// ApiResponseForPay apiResponseForPay = objectMapper.readValue(responseForPay.body(), ApiResponseForPay.class);
|
||||
// if (apiResponseForPay == null) {
|
||||
// log.error("扣款食堂卡失败,请检查");
|
||||
// return AjaxResult.error("扣款食堂卡失败,请检查");
|
||||
// }
|
||||
// if (StringUtils.isNotNull(apiResponseForPay) && apiResponseForPay.getCode() == 10000) {
|
||||
// boolean b = saveOrUpdate(dto);
|
||||
// Double moneyCount = 0.00;
|
||||
// if (StringUtils.isNotNull(dto.getId())) {
|
||||
// //增加 绿植订单信息品类
|
||||
// if (StringUtils.isNotEmpty(dto.getOrderInfoList())) {
|
||||
// for (WashClothingOrderInfo greenOrderInfo : dto.getOrderInfoList()) {
|
||||
// greenOrderInfo.setOrderId(dto.getId());
|
||||
// int insert = washClothingOrderInfoMapper.insert(greenOrderInfo);
|
||||
// if (insert == 1) {
|
||||
// // 统计这一单的金额
|
||||
// moneyCount = moneyCount + (greenOrderInfo.getGreenPrice() * greenOrderInfo.getClothingNum());
|
||||
// }
|
||||
// }
|
||||
// return AjaxResult.success("选购成功,消费金额为: " + moneyCount);
|
||||
// } else {
|
||||
// return AjaxResult.error("请选购对应洗衣项目");
|
||||
// }
|
||||
// }
|
||||
// return AjaxResult.error("洗衣项目新增失败");
|
||||
// }
|
||||
// if (StringUtils.isNotNull(apiResponseForPay)) {
|
||||
// return AjaxResult.error("小牛支付提示:" + apiResponseForPay.getMsg());
|
||||
// }
|
||||
// return AjaxResult.error("支付有误,请联系管理员");
|
||||
// } catch (Exception e) {
|
||||
// log.error("下单失败");
|
||||
// e.printStackTrace();
|
||||
// return AjaxResult.error("下单失败");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void intoMapEnity(HashMap bodyMap, WashClothingOrder dto, Customer customer) {
|
||||
// //金额
|
||||
// Double usePrice = dto.getUsePrice();
|
||||
// int convertedPrice = (int) (usePrice * 100);
|
||||
// bodyMap.put("amount", convertedPrice);
|
||||
// //人员 id
|
||||
// bodyMap.put("custId", Long.valueOf(customer.getCustId()));
|
||||
// //流水号
|
||||
// bodyMap.put("macOrdId", dto.getOrdno());
|
||||
// //sn码
|
||||
// bodyMap.put("machineSn", sncode);
|
||||
// //
|
||||
// bodyMap.put("nuClearMode", 2);
|
||||
//
|
||||
// bodyMap.put("ordTime", DateUtils.formatDate(dto.getOrderTime()));
|
||||
//
|
||||
// bodyMap.put("deliveryType", "2");
|
||||
// //
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private Map<String, Object> makeSign(String content, String appsecret, HashMap<Object, Object> bodyMap) {
|
||||
// Map<String, Object> map = new TreeMap<>();
|
||||
// map.put("appid", applicationid);
|
||||
// map.put("version", "1.0.0");
|
||||
// map.put("signtype", "md5");
|
||||
// map.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
||||
// map.put("nonce", RandomUtil.randomNumbers(10));
|
||||
// map.put("content", content);
|
||||
// //生成sign,防篡改
|
||||
// String toSignStr = Joiner.on("&")
|
||||
// .useForNull("")
|
||||
// .withKeyValueSeparator("=")
|
||||
// .join(map) + "&appsecret=" + appsecret;
|
||||
// log.info("所有参数字典排序,待加签String:{}", toSignStr);
|
||||
//
|
||||
// // md5/sha256 加签(其他方式待提供)
|
||||
// String sign = DigestUtils.md5Hex(toSignStr).toUpperCase();
|
||||
// System.err.println("sign: " + sign);
|
||||
// log.info("加签String:{}", sign);
|
||||
// map.put("sign", sign);
|
||||
//
|
||||
// //post请求
|
||||
// map.replace("content", bodyMap);
|
||||
// return map;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Reference in New Issue