Commit e712f029 by wuwenlong

wechat pay callback dev;

parent 53d83141
package com.zbkj.admin.controller;
import com.zbkj.service.service.CallbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* 支付回调
*/
@Slf4j
@RestController
@RequestMapping("api/admin/payment/callback")
@Api(tags = "支付回调")
public class CallbackController {
@Autowired
private CallbackService callbackService;
/**
* 微信支付回调
*/
@ApiOperation(value = "微信支付回调")
@RequestMapping(value = "/wechat", method = RequestMethod.POST)
public String weChat(@RequestBody String request) {
System.out.println("微信支付回调 request ===> " + request);
String response = callbackService.weChat(request);
System.out.println("微信支付回调 response ===> " + response);
return response;
}
/**
* 微信退款回调
*/
@ApiOperation(value = "微信退款回调")
@RequestMapping(value = "/wechat/refund", method = RequestMethod.POST)
public String weChatRefund(@RequestBody String request) {
System.out.println("微信退款回调 request ===> " + request);
String response = callbackService.weChatRefund(request);
System.out.println("微信退款回调 response ===> " + response);
return response;
}
}
......@@ -27,6 +27,8 @@ public class WeChatConfig
private String publicAppSecret;
private String publicSignKey;
private Integer wechatJsApiDebug;
}
......@@ -9,6 +9,7 @@ import io.jsonwebtoken.Claims;
*/
public class Constants
{
public static final String CONFIG_KEY_SITE_URL = "site_url"; //域名
public static final String CONFIG_KEY_API_URL = "api_url"; //admin接口地址
// 订单取消Key
......@@ -40,6 +41,16 @@ public class Constants
public static final int THIRD_LOGIN_TOKEN_TYPE_ANDROID_WX = 6; //android微信
public static final int THIRD_LOGIN_TOKEN_TYPE_IOS = 7; //ios
/** 订单支付成功后Task */
public static final String ORDER_TASK_PAY_SUCCESS_AFTER = "orderPaySuccessTask";
//订单操作redis队列
public static final String ORDER_TASK_REDIS_KEY_AFTER_DELETE_BY_USER = "alterOrderDeleteByUser"; // 用户删除订单后续操作
public static final String ORDER_TASK_REDIS_KEY_AFTER_COMPLETE_BY_USER = "alterOrderCompleteByUser"; // 用户完成订单后续操作
public static final String ORDER_TASK_REDIS_KEY_AFTER_CANCEL_BY_USER = "alterOrderCancelByUser"; // 用户取消订单后续操作
public static final String ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER = "alterOrderRefundByUser"; // 用户订单退款后续操作
public static final int NUM_ZERO = 0;
public static final int NUM_ONE = 1;
public static final int NUM_TWO = 2;
......
package share.common.enums;
import share.common.utils.StringUtils;
/**
* @Author wwl
* @Date 2023/10/20 10:57
*/
public enum OrderTypeEnum {
RESERVER(1,"预定"),
RENEW(2,"续费"),
RECHARGE(3,"充值");
RESERVER(1,"reserver","预定"),
RENEW(2,"renew","续费"),
RECHARGE(3,"recharge","充值");
private Integer code;
private String value;
private String name;
OrderTypeEnum(Integer code, String name) {
OrderTypeEnum(Integer code, String value, String name) {
this.code = code;
this.value = value;
this.name = name;
}
......@@ -26,10 +30,25 @@ public enum OrderTypeEnum {
return null;
}
public static OrderTypeEnum getEnumByValue(String value){
if(StringUtils.isNotBlank(value)) {
for (OrderTypeEnum type : OrderTypeEnum.values()) {
if (type.value.equals(value)) {
return type;
}
}
}
return null;
}
public Integer getCode(){
return code;
}
public String getValue() {
return value;
}
public String getName() {
return name;
}
......
package share.system.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 支付附加对象
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="AttachVo对象", description="支付附加对象")
public class AttachVo {
public AttachVo() {
}
public AttachVo(String type, Long userId) {
this.type = type;
this.userId = userId;
}
@ApiModelProperty(value = "业务类型, 订单 = order, 充值 = recharge", required = true)
private String type = "order";
@ApiModelProperty(value = "用户id", required = true)
private Long userId;
}
package com.zbkj.common.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 微信回调对象
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="CallbackVo对象", description="微信回调")
public class CallbackVo {
@ApiModelProperty(value = "调用接口提交的公众账号ID")
@JsonProperty(value = "appid")
private String appId;
@ApiModelProperty(value = "调用接口提交的商户号")
@JsonProperty(value = "mch_id")
private String mchId;
@ApiModelProperty(value = "调用接口提交的终端设备号")
@JsonProperty(value = "device_info")
private String deviceInfo;
@ApiModelProperty(value = "微信返回的随机字符串")
@JsonProperty(value = "nonce_str")
private String nonceStr;
@ApiModelProperty(value = "微信返回的签名")
private String sign;
@ApiModelProperty(value = "SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断")
@JsonProperty(value = "return_code")
private String returnCode;
@ApiModelProperty(value = "当return_code为FAIL时返回信息为错误原因 ,例如 签名失败 参数格式校验错误")
@JsonProperty(value = "return_msg")
private String returnMsg;
@ApiModelProperty(value = "SUCCESS/FAIL 业务结果")
@JsonProperty(value = "result_code")
private String resultCode;
@ApiModelProperty(value = "详细参见错误列表")
@JsonProperty(value = "err_code")
private String errCode;
@ApiModelProperty(value = "错误返回的信息描述")
@JsonProperty(value = "err_code_des")
private String errCodeDes;
@ApiModelProperty(value = "用户在商户appid下的唯一标识")
private String openid;
@ApiModelProperty(value = "微信支付订单号")
@JsonProperty(value = "transaction_id")
private String transactionId;
@ApiModelProperty(value = "微信支付订单号")
@JsonProperty(value = "out_trade_no")
private String outTradeNo;
@ApiModelProperty(value = "商家数据包,原样返回")
private String attach;
@ApiModelProperty(value = "支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则")
@JsonProperty(value = "time_end")
private String timeEnd;
@ApiModelProperty(value = "用户是否关注公众账号,Y-关注,N-未关注")
@JsonProperty(value = "is_subscribe")
private String isSubscribe;
@ApiModelProperty(value = "银行类型")
@JsonProperty(value = "bank_type")
private String bankType;
@ApiModelProperty(value = "现金支付金额")
@JsonProperty(value = "cash_fee")
private Integer cashFee;
@ApiModelProperty(value = "总代金券金额")
@JsonProperty(value = "coupon_fee")
private Integer couponFee;
}
package com.zbkj.service.service;
import javax.servlet.http.HttpServletRequest;
/**
* 订单支付回调 service
*/
public interface CallbackService {
/**
* 微信支付回调
* @param xmlInfo 微信回调json
* @return String
*/
String weChat(String xmlInfo);
/**
* 微信退款回调
* @param request 微信回调json
* @return String
*/
String weChatRefund(String request);
}
......@@ -96,4 +96,6 @@ public interface ISOrderService extends IService<SOrder>
* @return
*/
SOrder getByOrderNo(String orderNo);
SOrder getInfoByEntity(SOrder orderParam);
}
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -8,6 +9,7 @@ import org.springframework.stereotype.Service;
import share.common.config.WeChatConfig;
import share.common.constant.Constants;
import share.common.constant.PayConstants;
import share.common.enums.OrderTypeEnum;
import share.common.enums.PayTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
......@@ -16,6 +18,7 @@ import share.common.utils.DateUtil;
import share.common.utils.JsonConvertUtil;
import share.system.domain.SConsumerToken;
import share.system.domain.SOrder;
import share.system.domain.vo.AttachVo;
import share.system.domain.vo.CreateOrderRequestVo;
import share.system.domain.vo.CreateOrderResponseVo;
import share.system.domain.vo.WxPayJsResultVo;
......@@ -117,11 +120,14 @@ public class OrderPayServiceImpl implements OrderPayService {
private CreateOrderRequestVo getUnifiedorderVo(SOrder sOrder, String openid, String appId, String mchId, String signKey) {
// 获取域名
String apiDomain = Constants.CONFIG_KEY_API_URL;
AttachVo attachVo = new AttachVo(OrderTypeEnum.getEnumByCode(sOrder.getOrderType()).getValue(), sOrder.getConsumerId());
CreateOrderRequestVo vo = new CreateOrderRequestVo();
vo.setAppid(appId);
vo.setMch_id(mchId);
vo.setNonce_str(WxPayUtil.getNonceStr());
vo.setSign_type(PayConstants.WX_PAY_SIGN_TYPE_MD5);
vo.setAttach(JSONObject.toJSONString(attachVo));
vo.setOut_trade_no(BaseUtil.getOrderNo("wxNo"));
// 订单中使用的是BigDecimal,这里要转为Integer类型
vo.setTotal_fee(sOrder.getPayPrice().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue());
......
......@@ -269,6 +269,13 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
return getOne(lqw);
}
@Override
public SOrder getInfoByEntity(SOrder orderParam) {
LambdaQueryWrapper<SOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.setEntity(orderParam);
return getOne(lambdaQueryWrapper);
}
private BigDecimal computeTotalPrice(BigDecimal unitPrice, Date startTime, Date endTime){
return DateUtils.differentHour(startTime,endTime).multiply(unitPrice);
}
......@@ -298,10 +305,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
if (ObjectUtil.isNull(consumerCoupon) || !consumerCoupon.getCouponId().equals(user.getId())) {
throw new BaseException("优惠券领取记录不存在!");
}
if (CouponStatusEnum.USED.getValue().compareTo(Integer.parseInt(consumerCoupon.getUseStatus())) == 0) {
if (CouponStatusEnum.USED.getValue().compareTo(consumerCoupon.getUseStatus()) == 0) {
throw new BaseException("此优惠券已使用!");
}
if (CouponStatusEnum.EXPIRED.getValue().compareTo(Integer.parseInt(consumerCoupon.getUseStatus())) == 0) {
if (CouponStatusEnum.EXPIRED.getValue().compareTo(consumerCoupon.getUseStatus()) == 0) {
throw new BaseException("此优惠券已失效!");
}
//判断是否在使用时间内
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment