Althars123 %!s(int64=3) %!d(string=hai) anos
pai
achega
740f631dd7

+ 47 - 1
zzjs-admin/src/main/java/com/miaxis/app/controller/film/FilmNotifyController.java

@@ -4,11 +4,16 @@ package com.miaxis.app.controller.film;
 import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.config.WxpayConfig;
 import com.miaxis.common.constant.Constants;
+import com.miaxis.common.enums.OrderStatusEnum;
+import com.miaxis.common.exception.CustomException;
+import com.miaxis.feign.dto.WxSend;
+import com.miaxis.feign.service.IWxSendService;
 import com.miaxis.wx.domain.WxOrder;
 import com.miaxis.wx.dto.FilmWxOrderJsonData;
 import com.miaxis.wx.dto.WxOrderNotifyDTO;
 import com.miaxis.wx.service.IRefundRecordService;
 import com.miaxis.wx.service.IWxOrderService;
+import com.miaxis.wx.service.IWxXcxMessageService;
 import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -44,6 +49,12 @@ public class FilmNotifyController {
     @Autowired
     private  IRefundRecordService  refundRecordService;
 
+    @Autowired
+    IWxXcxMessageService wxXcxMessageService;
+
+    @Autowired
+    private IWxSendService wxSendService;
+
 
 
     /**
@@ -75,9 +86,20 @@ public class FilmNotifyController {
         wxOrderJsonData.setWxOrderNotifyDTO(dbWxOrderNotifyDTO);
         wxOrder.setOrderDataJson(JSONObject.toJSONString(wxOrderJsonData));
         //UserInfo student = SecurityUtils.getLoginUser().getStudent();
+        //如果订单状态成功,则调用小程序推送服务
+        if ("TICKET_SUCCESS".equals(wxOrderNotifyDTO.getEventName())){
+            wxOrder.setOrderStatus(OrderStatusEnum.SUCCESS.getCode());
+            sendXcxMessage();
+
+
+        }
+
+
+
         //如果回调回来的订单关闭,则调用退款
         if ("ORDER_CLOSE".equals(wxOrderNotifyDTO.getEventName())){
             String refundCode = getOrderCode(null);
+            wxOrder.setOrderStatus(OrderStatusEnum.FAILD.getCode());
             wxOrder.setOutRefundNo(refundCode);
             threadPoolTaskExecutor.execute(new Runnable() {
             @Override
@@ -85,7 +107,7 @@ public class FilmNotifyController {
                     try {
                         refundRecordService.refund(wxOrder,refundCode);
                     } catch (Exception e) {
-                        log.info(e.getMessage());
+                        throw new CustomException("订单:"+wxOrder.getOutTradeNo()+"退款失败");
                     }
                 }
             });
@@ -101,6 +123,30 @@ public class FilmNotifyController {
         return filmNotifyReturnDTO;
     }
 
+    private void sendXcxMessage() {
+        String xcxMessageToken = wxXcxMessageService.getXcxMessageToken();
+        WxSend wxSend = new WxSend();
+        //wxSend.setAccess_token(xcxMessageToken);
+        wxSend.setTouser("oO7PJ5JxqYj0kVYLb1e3FG55mD8E");
+        wxSend.setTemplate_id("NlZAFJj1p5aHFOg6BBesP7xFAJh5kIZ0kp_YwtJje0g");
+        wxSend.setPage("/pages/index/index?active=user");
+
+        JSONObject jsonObject = new JSONObject();
+        JSONObject jsonObject1 = new JSONObject();
+        JSONObject jsonObject2 = new JSONObject();
+        JSONObject jsonObject3 = new JSONObject();
+        jsonObject1.put("value","2019年10月1日");
+        jsonObject2.put("value","林霖强");
+        jsonObject3.put("value","3");
+        jsonObject.put("time3",jsonObject1);
+        jsonObject.put("name1",jsonObject2);
+        jsonObject.put("thing2",jsonObject3);
+
+        wxSend.setData(jsonObject);
+        wxSend.setMiniprogram_state("developer");
+        wxSend.setLang("zh_CN");
+        String result = wxSendService.sendMessage(xcxMessageToken,wxSend);
+    }
 
 
     @Data

+ 18 - 0
zzjs-admin/src/main/java/com/miaxis/app/controller/fulu/FuluNotifyController.java

@@ -4,6 +4,8 @@ package com.miaxis.app.controller.fulu;
 import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.config.WxpayConfig;
 import com.miaxis.common.constant.Constants;
+import com.miaxis.common.enums.OrderStatusEnum;
+import com.miaxis.common.exception.CustomException;
 import com.miaxis.wx.domain.WxOrder;
 import com.miaxis.wx.dto.FilmWxOrderJsonData;
 import com.miaxis.wx.dto.FuluWxOrderJsonData;
@@ -62,6 +64,22 @@ public class FuluNotifyController {
             dbWxFuluOrderDetailDTO.setCharge_finish_time(wxFuluOrderDetailDTO.getCharge_finish_time());
         }
         dbWxFuluOrderDetailDTO.setOrder_status(wxFuluOrderDetailDTO.getOrder_status());
+        //如果订单失败,则调用微信退款
+        if ("failed".equals(wxFuluOrderDetailDTO.getOrder_status())){
+            String refundCode = getOrderCode(null);
+            wxOrder.setOutRefundNo(refundCode);
+            wxOrder.setOrderStatus(OrderStatusEnum.FAILD.getCode());
+            threadPoolTaskExecutor.execute(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        refundRecordService.refund(wxOrder,refundCode);
+                    } catch (Exception e) {
+                        throw new CustomException("订单:"+wxOrder.getOutTradeNo()+"退款失败");
+                    }
+                }
+            });
+        }
         fuluWxOrderJsonData.setWxFuluOrderDetailDTO(dbWxFuluOrderDetailDTO);
         wxOrder.setOrderDataJson(fuluWxOrderJsonData.toString());
         wxOrderService.updateById(wxOrder);

+ 6 - 6
zzjs-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -73,13 +73,13 @@ public class WxNotifyController {
      */
     @PostMapping(value = "/wxpay")
     @ApiOperation("微信支付回调")
-    public WxNotifyReturnDTO wxpayNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
+    public WxNotifyReturnDTO wxpayNotify(@RequestBody WxpayNotifyDTO wxpayNotifyDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
 
         String bodyString = getBodyString(request);
         if (!validate(request,bodyString)){
             throw new CustomException("签名失败");
         }
-        String resourceString = getSourString(filmWxpayDTO);
+        String resourceString = getSourString(wxpayNotifyDTO);
         log.info(resourceString);
         JSONObject jsonObject = JSONObject.parseObject(resourceString);
         //将回调数据写入数据库
@@ -154,12 +154,12 @@ public class WxNotifyController {
      */
     @PostMapping(value = "/refund")
     @ApiOperation("微信退款回调")
-    public WxNotifyReturnDTO refundNotify(@RequestBody FilmWxpayDTO filmWxpayDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
+    public WxNotifyReturnDTO refundNotify(@RequestBody WxpayNotifyDTO wxpayNotifyDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
         String bodyString = getBodyString(request);
 //        if (!validate(request,bodyString)){
 //            throw new CustomException("签名失败");
 //        }
-        String resourceString = getSourString(filmWxpayDTO);
+        String resourceString = getSourString(wxpayNotifyDTO);
         log.info(resourceString);
         JSONObject jsonObject = JSONObject.parseObject(resourceString);
         //将回调数据写入数据库
@@ -230,9 +230,9 @@ public class WxNotifyController {
 
     }
 
-    private String getSourString(FilmWxpayDTO filmWxpayDTO) throws GeneralSecurityException, IOException {
+    private String getSourString(WxpayNotifyDTO wxpayNotifyDTO) throws GeneralSecurityException, IOException {
         AesUtil aesUtil = new AesUtil(wxpayConfig.getV3key().getBytes());
-        FilmWxpayDTO.WxpaySource wxpaySource = filmWxpayDTO.getResource();
+        WxpayNotifyDTO.WxpaySource wxpaySource = wxpayNotifyDTO.getResource();
         return aesUtil.decryptToString(wxpaySource.getAssociated_data().getBytes(), wxpaySource.getNonce().getBytes(), wxpaySource.getCiphertext());
     }
 

+ 5 - 0
zzjs-common/src/main/java/com/miaxis/common/constant/Constants.java

@@ -67,6 +67,11 @@ public class Constants
     public static final String SMS_LOGIN_CODE_COUNT = "sms:login:code:count:";
 
 
+    /**
+     * 小程序消息推送 token
+     */
+    public static final String XCX_MESSAGE_TOKEN = "xcx:message:token:";
+
     /**
      * 登录用户 redis key
      */

+ 30 - 0
zzjs-common/src/main/java/com/miaxis/common/enums/OrderStatusEnum.java

@@ -0,0 +1,30 @@
+package com.miaxis.common.enums;
+
+/**
+ * 订单状态
+ *
+ * @author miaxis
+ */
+public enum OrderStatusEnum
+{
+    PROCESSING("1", "进行中"), SUCCESS("2", "停用"), FAILD("3", "失败");
+
+    private final String code;
+    private final String info;
+
+    OrderStatusEnum(String code, String info)
+    {
+        this.code = code;
+        this.info = info;
+    }
+
+    public String getCode()
+    {
+        return code;
+    }
+
+    public String getInfo()
+    {
+        return info;
+    }
+}

+ 0 - 116
zzjs-service/src/main/java/com/miaxis/wx/controller/RefundRecordController.java

@@ -1,116 +0,0 @@
-package com.miaxis.wx.controller;
-
-import java.util.List;
-import java.util.Arrays;
-import io.swagger.annotations.*;
-import com.miaxis.common.core.domain.Response;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import com.miaxis.common.annotation.Log;
-import com.miaxis.common.core.controller.BaseController;
-import com.miaxis.common.enums.BusinessTypeEnum;
-import com.miaxis.wx.domain.RefundRecord;
-import com.miaxis.wx.service.IRefundRecordService;
-import com.miaxis.common.utils.poi.ExcelUtil;
-import com.miaxis.common.core.page.ResponsePageInfo;
-
-/**
- * 【微信退款记录】Controller
- *
- * @author miaxis
- * @date 2021-05-18
- */
-@RestController
-@RequestMapping("/film/record")
-@Api(tags={"【小程序-微信退款记录】"})
-public class RefundRecordController extends BaseController{
-    @Autowired
-    private IRefundRecordService refundRecordService;
-
-    /**
-     * 查询微信退款记录列表
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:list')")
-    @GetMapping("/list")
-    @ApiOperation("查询微信退款记录列表")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
-    })
-    public ResponsePageInfo<RefundRecord> list(@ModelAttribute RefundRecord refundRecord){
-        startPage();
-        List<RefundRecord> list = refundRecordService.selectRefundRecordList(refundRecord);
-        return toResponsePageInfo(list);
-    }
-
-    /**
-     * 导出微信退款记录列表
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:export')")
-    @Log(title = "微信退款记录", businessType = BusinessTypeEnum.EXPORT)
-    @GetMapping("/export")
-    @ApiOperation("导出微信退款记录列表Excel")
-    public Response<String> export(@ModelAttribute RefundRecord refundRecord){
-        List<RefundRecord> list = refundRecordService.selectRefundRecordList(refundRecord);
-        ExcelUtil<RefundRecord> util = new ExcelUtil<RefundRecord>(RefundRecord.class);
-        return util.exportExcel(list, "record");
-    }
-
-    /**
-     * 获取微信退款记录详细信息
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:query')")
-    @GetMapping(value = "/{id}")
-    @ApiOperation("获取微信退款记录详细信息")
-    public Response<RefundRecord> getInfo(
-            @ApiParam(name = "id", value = "微信退款记录参数", required = true)
-            @PathVariable("id") Long id
-    ){
-        return Response.success(refundRecordService.getById(id));
-    }
-
-    /**
-     * 新增微信退款记录
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:add')")
-    @Log(title = "微信退款记录", businessType = BusinessTypeEnum.INSERT)
-    @PostMapping
-    @ApiOperation("新增微信退款记录")
-    public Response<Integer> add(@RequestBody RefundRecord refundRecord){
-        return toResponse(refundRecordService.save(refundRecord) ? 1 : 0);
-    }
-
-    /**
-     * 修改微信退款记录
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:edit')")
-    @Log(title = "微信退款记录", businessType = BusinessTypeEnum.UPDATE)
-    @PutMapping
-    @ApiOperation("修改微信退款记录")
-    public Response<Integer> edit(@RequestBody RefundRecord refundRecord){
-        return toResponse(refundRecordService.updateById(refundRecord) ? 1 : 0);
-    }
-
-    /**
-     * 删除微信退款记录
-     */
-    @PreAuthorize("@ss.hasPermi('film:record:remove')")
-    @Log(title = "微信退款记录", businessType = BusinessTypeEnum.DELETE)
-	@DeleteMapping("/{ids}")
-    @ApiOperation("删除微信退款记录")
-    public  Response<Integer> remove(
-            @ApiParam(name = "ids", value = "微信退款记录ids参数", required = true)
-            @PathVariable Long[] ids
-    ){
-        return toResponse(refundRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
-    }
-}

+ 2 - 2
zzjs-service/src/main/java/com/miaxis/wx/dto/FilmWxpayDTO.java → zzjs-service/src/main/java/com/miaxis/wx/dto/WxpayNotifyDTO.java

@@ -7,7 +7,7 @@ import lombok.Data;
  * 微信支付回调 dto
  */
 @Data
-public class FilmWxpayDTO {
+public class WxpayNotifyDTO {
     private static final long serialVersionUID = 1L;
 
     @ApiModelProperty(value = "通知的唯一ID")
@@ -24,7 +24,7 @@ public class FilmWxpayDTO {
     private String resource_type;
 
 
-    @ApiModelProperty(value = "是否允许调座,1-允许,0-不允许")
+    @ApiModelProperty(value = "数据资源")
     private WxpaySource resource;
 
     @ApiModelProperty(value = "回调摘要")

+ 10 - 0
zzjs-service/src/main/java/com/miaxis/wx/service/IWxXcxMessageService.java

@@ -0,0 +1,10 @@
+package com.miaxis.wx.service;
+
+/**
+ * 小程序消息推送
+ *
+ */
+public interface IWxXcxMessageService {
+    String getXcxMessageToken();
+
+}

+ 8 - 1
zzjs-service/src/main/java/com/miaxis/wx/service/impl/WxOrderServiceImpl.java

@@ -8,6 +8,7 @@ import java.util.stream.Collectors;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.common.enums.OrderStatusEnum;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.sms.MD5Utils;
 import com.miaxis.common.utils.StringUtils;
@@ -311,6 +312,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
                     //如果返回值不是200 ,则调用退款流程
                     if (filmXdResult.getCode()!=200){
                         String refundCode = getOrderCode(null);
+                        wxOrder.setOrderStatus(OrderStatusEnum.FAILD.getCode());
                         wxOrder.setOutRefundNo(refundCode);
                         try {
                             refundRecordService.refund(wxOrder,refundCode);
@@ -318,7 +320,9 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
                             throw new CustomException("退款失败");
                         }
                     }else {
+                        wxOrder.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
                         if (filmXdResult.getData().getTicket()!= null){
+                            wxOrder.setOrderStatus(OrderStatusEnum.SUCCESS.getCode());
                             FilmMcpData filmMcpData = filmXdResult.getData();
                             wxOrderJsonData.setFilmMcpData(filmMcpData);
                             wxOrder.setOrderDataJson(JSONObject.toJSONString(wxOrderJsonData));
@@ -356,15 +360,18 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
                     fuluCommonApiDTO.setBiz_content(jsonObject.toJSONString());
                     FuluResult fuluResult = fuluService.fuluCommonApi(fuluDTO);
                     log.info("福禄下单返回值:"+JSONObject.toJSONString(fuluResult));
-                    //如果返回值不是200 ,则调用退款流程
+                    //如果返回值不是0 ,则调用退款流程
                     if (fuluResult.getCode() != 0){
                         String refundCode = getOrderCode(null);
+                        wxOrder.setOrderStatus(OrderStatusEnum.FAILD.getCode());
                         wxOrder.setOutRefundNo(refundCode);
                         try {
                             refundRecordService.refund(wxOrder,refundCode);
                         } catch (Exception e) {
                             throw new CustomException("退款失败");
                         }
+                    }else {
+                        wxOrder.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
                     }
                     //返回成功,则保存返回福禄订单详情到微信订单json传中
                     WxFuluOrderDetailDTO wxFuluOrderDetailDTO = JSONObject.parseObject(fuluResult.getResult(),WxFuluOrderDetailDTO.class);

+ 90 - 0
zzjs-service/src/main/java/com/miaxis/wx/service/impl/WxXcxMesageServiceImpl.java

@@ -0,0 +1,90 @@
+package com.miaxis.wx.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.redis.RedisCache;
+import com.miaxis.common.exception.CustomException;
+import com.miaxis.common.sms.MD5Utils;
+import com.miaxis.common.utils.StringUtils;
+import com.miaxis.feign.dto.FilmDTO;
+import com.miaxis.feign.dto.FilmMcpData;
+import com.miaxis.feign.dto.FilmXdResult;
+import com.miaxis.feign.dto.fulu.FuluCommonApiDTO;
+import com.miaxis.feign.dto.fulu.FuluDTO;
+import com.miaxis.feign.dto.fulu.FuluGoodsInfo;
+import com.miaxis.feign.dto.fulu.FuluResult;
+import com.miaxis.feign.service.IFuluService;
+import com.miaxis.feign.service.IWxgetTokenService;
+import com.miaxis.system.service.ISysConfigService;
+import com.miaxis.wx.domain.WxOrder;
+import com.miaxis.wx.dto.*;
+import com.miaxis.wx.mapper.WxOrderMapper;
+import com.miaxis.wx.service.IRefundRecordService;
+import com.miaxis.wx.service.IWxOrderService;
+import com.miaxis.wx.service.IWxXcxMessageService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
+
+/**
+ * 电影订单Service业务层处理
+ *
+ * @author miaxis
+ * @date 2021-05-07
+ */
+@Service
+@Slf4j
+public class WxXcxMesageServiceImpl implements IWxXcxMessageService {
+
+
+    @Resource
+    private RedisCache redisCache;
+
+    @Autowired
+    private IWxgetTokenService wxgetTokenService;
+
+    @Value("${app.appid}")
+    private String appid;
+
+    @Value("${app.secret}")
+    private String secret;
+
+
+    @Override
+    public String getXcxMessageToken() {
+        Object cacheObject = redisCache.getCacheObject(Constants.XCX_MESSAGE_TOKEN);
+        //如果过期,重新获取并保存到redis
+        if (cacheObject == null){
+            String result = wxgetTokenService.getAccessToken("client_credential",appid,secret);
+            JSONObject json = JSONObject.parseObject(result);
+            String token = json.getString("access_token");
+            int expiresIn = json.getIntValue("expires_in");
+            redisCache.setCacheObject(Constants.XCX_MESSAGE_TOKEN,token,expiresIn, TimeUnit.SECONDS);
+            return token;
+        }else {
+            return String.valueOf(cacheObject);
+        }
+
+    }
+}