| @@ -1,11 +1,18 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMerchantBUser; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.pay.WxPayConstant; | |||||
| import com.iformall.pay.WxPayment; | |||||
| import com.iformall.utils.PosUtil; | import com.iformall.utils.PosUtil; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -33,7 +40,7 @@ public class WxPosController extends BaseController { | |||||
| PosUtil posUtil = new PosUtil(); | PosUtil posUtil = new PosUtil(); | ||||
| @ApiOperation(value = "检查POSServer是否正常", notes = "") | |||||
| @ApiOperation(value = "检查POS Server是否正常", notes = "") | |||||
| @GetMapping("checkAvaiable") | @GetMapping("checkAvaiable") | ||||
| public ResultData checkAvaiable() { | public ResultData checkAvaiable() { | ||||
| try { | try { | ||||
| @@ -50,7 +57,321 @@ public class WxPosController extends BaseController { | |||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(Result.ERROR, e.getMessage()); | return new ResultData(Result.ERROR, e.getMessage()); | ||||
| } | } | ||||
| } | |||||
| @ApiOperation(value = "商户POS用户/B端用户登录检查") | |||||
| @PostMapping("checkUserPassword") | |||||
| public ResultData checkUserPassword() { | |||||
| WxMerchantBUser user = getUser(); | |||||
| try { | |||||
| String resStr = posUtil.checkUserPassword(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), user.getPhone(), user.getUserPwd()); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "获取会员折扣/优惠券/消费卡是否启用") | |||||
| @PostMapping("getPosMemConfig") | |||||
| public ResultData getPosMemConfig() { | |||||
| try { | |||||
| String resStr = posUtil.getPosMemConfig(posUrl, posDevId, posReqKey, | |||||
| getTenantId()); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "获取注册二维码及小票二维码规则") | |||||
| @PostMapping("getQrCode") | |||||
| public ResultData getQrCode() { | |||||
| try { | |||||
| String resStr = posUtil.getQrCode(posUrl, posDevId, posReqKey, | |||||
| getTenantId()); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "会员识别") | |||||
| @PostMapping("checkMem") | |||||
| public ResultData checkMem(@RequestBody Map<String, String> params) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID | |||||
| String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 | |||||
| String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID | |||||
| String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) | |||||
| if (StringUtils.isBlank(posOrderIdStr)) { | |||||
| String errMessage = "request params[pos_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posAmountStr)) { | |||||
| String errMessage = "request params[pos_amount] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { | |||||
| String errMessage = "please give one value for mem_id or mem_phone"; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| try { | |||||
| String resStr = posUtil.checkMem(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), String.valueOf(user.getMerchantId()), | |||||
| memIdStr, memPhoneStr, posOrderIdStr, posAmountStr); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "券核销检查") | |||||
| @PostMapping("checkCouponOrderForVerify") | |||||
| public ResultData checkCouponOrderForVerify(@RequestBody Map<String, String> params) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID | |||||
| String verifyType = params.get(WxPayConstant.VERIFY_TYPE); // 核销类型 | |||||
| String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID | |||||
| String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| String errMessage = "request params[coupon_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(verifyType)) { | |||||
| String errMessage = "request params[verify_type] error."; | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posOrderIdStr)) { | |||||
| String errMessage = "request params[pos_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posAmountStr)) { | |||||
| String errMessage = "request params[pos_amount] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| try { | |||||
| String resStr = posUtil.checkCouponOrderForVerify(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), | |||||
| couponOrderIdStr, verifyType, posOrderIdStr, posAmountStr); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "券预核销") | |||||
| @PostMapping("couponOrderPreVerify") | |||||
| public ResultData couponOrderPreVerify(@RequestBody Map<String, String> params) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID | |||||
| String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID | |||||
| String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| String errMessage = "request params[coupon_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posOrderIdStr)) { | |||||
| String errMessage = "request params[pos_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posAmountStr)) { | |||||
| String errMessage = "request params[pos_amount] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| try { | |||||
| String resStr = posUtil.couponOrderPreVerify(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), | |||||
| couponOrderIdStr, posOrderIdStr, posAmountStr); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "券预核销取消") | |||||
| @PostMapping("couponOrderPreVerifyCancel") | |||||
| public ResultData couponOrderPreVerifyCancel(@RequestBody Map<String, String> params) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID | |||||
| String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID | |||||
| String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| String errMessage = "request params[coupon_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posOrderIdStr)) { | |||||
| String errMessage = "request params[pos_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posAmountStr)) { | |||||
| String errMessage = "request params[pos_amount] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| try { | |||||
| String resStr = posUtil.couponOrderPreVerifyCancel(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), | |||||
| couponOrderIdStr, posOrderIdStr, posAmountStr); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "券独立核销") | |||||
| @PostMapping("couponOrderIndependentVerify") | |||||
| public ResultData couponOrderIndependentVerify(@RequestBody Map<String, String> params) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID | |||||
| String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| String errMessage = "request params[coupon_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| if (StringUtils.isBlank(posOrderIdStr)) { | |||||
| String errMessage = "request params[pos_order_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| try { | |||||
| String resStr = posUtil.couponOrderIndependentVerify(posUrl, posDevId, posReqKey, | |||||
| user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), | |||||
| couponOrderIdStr, posOrderIdStr); | |||||
| if (resStr != null) { | |||||
| JSONObject retObj = JSON.parseObject(resStr); | |||||
| Map options = retObj; | |||||
| if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } else { | |||||
| return new ResultData(resStr); | |||||
| } | |||||
| } else { | |||||
| return new ResultData(Result.ERROR, "无返回值"); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") | @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") | ||||