| | |
| | | //package com.lunhan.water.host.controller.pay; |
| | | // |
| | | //import com.alipay.api.AlipayApiException; |
| | | //import com.lunhan.water.common.ExecutedResult; |
| | | //import com.lunhan.water.common.util.ParameterUtil; |
| | | //import com.lunhan.water.common.validator.ParameterValidateResult; |
| | | //import com.lunhan.water.common.validator.ParameterValidator; |
| | | //import com.lunhan.water.entity.enums.EBusinessType; |
| | | //import com.lunhan.water.entity.request.pay.ReqCreatePay; |
| | | //import com.lunhan.water.entity.request.pay.ReqOrderPay; |
| | | //import com.lunhan.water.entity.request.pay.ReqPayRefund; |
| | | //import com.lunhan.water.host.BasicController; |
| | | //import com.lunhan.water.service.PaymentServices; |
| | | //import lombok.extern.slf4j.Slf4j; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //import org.springframework.web.bind.annotation.PostMapping; |
| | | //import org.springframework.web.bind.annotation.RequestBody; |
| | | //import org.springframework.web.bind.annotation.RequestMapping; |
| | | //import org.springframework.web.bind.annotation.RestController; |
| | | // |
| | | //import java.util.Map; |
| | | // |
| | | ///** |
| | | // * 50.支付服务 |
| | | // * |
| | | // * @author li。ling。yu |
| | | // * @date 2023/10/19 |
| | | // * @order 50 |
| | | // */ |
| | | //@Slf4j |
| | | //@RestController |
| | | //@RequestMapping(value = "/pay/service") |
| | | //public class PaymentServicesController extends BasicController { |
| | | // |
| | | // @Autowired |
| | | // private PaymentServices services; |
| | | // |
| | | // /** |
| | | // * 发起微信支付 |
| | | // * @param request 请求参数 |
| | | // * |
| | | // * @return 返回微信jsapi支付参数 |
| | | // */ |
| | | // @PostMapping(value = "wxPay") |
| | | // public ExecutedResult<Map<String, Object>> wxPay(@RequestBody ReqCreatePay request) { |
| | | // //#region 参数验证 |
| | | // ParameterValidator validator = new ParameterValidator() |
| | | // // 必须是枚举值 |
| | | // .addMustEnum(ParameterUtil.named("业务类型"), request.getBusinessType(), EBusinessType.class) |
| | | // // 必须大于0 |
| | | // //.addNotNullOrEmpty(ParameterUtil.named("订单号"), request.getBusinessNo()) |
| | | // ; |
| | | // ParameterValidateResult result = validator.validate(); |
| | | // if (result.getIsFiled()) { |
| | | // return ExecutedResult.failed(result.getErrorMsg()); |
| | | // } |
| | | // //#endregion |
| | | // return services.weiXinPay(this.getTokenUser(), request); |
| | | // } |
| | | // |
| | | // |
| | | // |
| | | // /** |
| | | // * 发起微信退款 |
| | | // * @param request 请求参数 |
| | | // * |
| | | // * @return 返回退款流水号 |
| | | // */ |
| | | // @PostMapping(value = "wxRefund") |
| | | // public ExecutedResult<String> wxRefund(@RequestBody ReqPayRefund request) { |
| | | // //PaymentMerchantPO merchant = super.getTokenUser(); |
| | | // return services.weiXinRefund(request); |
| | | // } |
| | | //} |
| | | package com.lunhan.water.host.controller.pay; |
| | | |
| | | import com.lunhan.water.common.ExecutedResult; |
| | | import com.lunhan.water.common.util.ParameterUtil; |
| | | import com.lunhan.water.common.util.StringUtil; |
| | | import com.lunhan.water.common.validator.ParameterValidateResult; |
| | | import com.lunhan.water.common.validator.ParameterValidator; |
| | | import com.lunhan.water.entity.enums.EBusinessType; |
| | | import com.lunhan.water.entity.request.pay.ReqCreatePay; |
| | | import com.lunhan.water.entity.request.pay.ReqOrderPay; |
| | | import com.lunhan.water.entity.request.pay.ReqPayRefund; |
| | | import com.lunhan.water.host.BasicController; |
| | | import com.lunhan.water.service.PaymentServices; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 50.支付服务 |
| | | * |
| | | * @author li。ling。yu |
| | | * @date 2023/10/19 |
| | | * @order 50 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/pay/service") |
| | | public class PaymentServicesController extends BasicController { |
| | | |
| | | @Autowired |
| | | private PaymentServices services; |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | /** |
| | | * 发起微信支付 |
| | | * @param request 请求参数 |
| | | * |
| | | * @return 返回微信jsapi支付参数 |
| | | */ |
| | | @PostMapping(value = "wxPay") |
| | | public ExecutedResult<Map<String, Object>> wxPay(@RequestBody ReqCreatePay request) { |
| | | //#region 参数验证 |
| | | ParameterValidator validator = new ParameterValidator() |
| | | // 必须是枚举值 |
| | | .addMustEnum(ParameterUtil.named("业务类型"), request.getBusinessType(), EBusinessType.class) |
| | | // 必须大于0 |
| | | .addGreater(ParameterUtil.named("交易金额"), request.getTradeAmount(), BigDecimal.ZERO) |
| | | //水表编号不能为空 |
| | | .addNotNullOrEmpty(ParameterUtil.named("支付token"), request.getPayToken()); |
| | | ; |
| | | ParameterValidateResult result = validator.validate(); |
| | | if (result.getIsFiled()) { |
| | | return ExecutedResult.failed(result.getErrorMsg()); |
| | | } |
| | | //#endregion |
| | | return services.weiXinPay(this.getTokenUser(), request); |
| | | } |
| | | |
| | | @PostMapping("/getPayToken") |
| | | public ExecutedResult<String>getPayToken(){ |
| | | String token = UUID.randomUUID().toString(); |
| | | redisTemplate.opsForValue().set(token,token,5, TimeUnit.MINUTES); |
| | | return ExecutedResult.success(token); |
| | | } |
| | | @GetMapping("/getRedisToken") |
| | | public ExecutedResult<String>getRedisToken(String token){ |
| | | String string = redisTemplate.opsForValue().get(token).toString(); |
| | | if(StringUtil.isNullOrEmpty(string)){ |
| | | return ExecutedResult.failed("请勿重复提交订单"); |
| | | } |
| | | redisTemplate.delete(string); |
| | | return ExecutedResult.success(string); |
| | | } |
| | | |
| | | /** |
| | | * 发起微信退款 |
| | | * @param request 请求参数 |
| | | * |
| | | * @return 返回退款流水号 |
| | | */ |
| | | @PostMapping(value = "wxRefund") |
| | | public ExecutedResult<String> wxRefund(@RequestBody ReqPayRefund request) { |
| | | //PaymentMerchantPO merchant = super.getTokenUser(); |
| | | return services.weiXinRefund(request); |
| | | } |
| | | } |