尚医通(二十四)微信退款(取消预约功能)
生活随笔
收集整理的這篇文章主要介紹了
尚医通(二十四)微信退款(取消预约功能)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一、取消預約
- 1、需求描述
- 2、開發取消預約接口
一、取消預約
1、需求描述
取消訂單分兩種情況:
(1)未支付取消訂單,直接通知醫院更新取消預約狀態
(2)已支付取消訂單,先退款給用戶,然后通知醫院更新取消預約狀態
2、開發取消預約接口
參考文檔:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
該接口需要使用證書,詳情參考文檔并下載證書
(1)配置證書
請下載的證書放在service-order模塊/resources/cert文件夾下
記得修改HttpClient里面的方法,改成證書所放的路徑
(2)添加退款記錄
添加RefundInfoMapper
添加RefundInfoService方法和實現
//RefundInfoService public interface RefundInfoService extends IService<RefundInfo> {RefundInfo saveRefundInfo(PaymentInfo paymentInfo); }//RefundInfoServiceImpl @Service public class RefundInfoServiceImpl extends ServiceImpl<RefundInfoMapper, RefundInfo> implements RefundInfoService {@Overridepublic RefundInfo saveRefundInfo(PaymentInfo paymentInfo) {Long orderId = paymentInfo.getOrderId();QueryWrapper<RefundInfo> queryWrapper=new QueryWrapper<RefundInfo>();queryWrapper.eq("order_id",orderId);RefundInfo refundInfo1 = baseMapper.selectOne(queryWrapper);if(refundInfo1 != null){return refundInfo1;}RefundInfo refundInfo=new RefundInfo();refundInfo.setOutTradeNo(paymentInfo.getOutTradeNo());refundInfo.setOrderId(paymentInfo.getOrderId());refundInfo.setPaymentType(PaymentTypeEnum.WEIXIN.getStatus());refundInfo.setTotalAmount(paymentInfo.getTotalAmount());refundInfo.setSubject("想退款...");refundInfo.setRefundStatus(RefundStatusEnum.UNREFUND.getStatus());baseMapper.insert(refundInfo);return refundInfo;} }(3)添加微信退款方法
在WeixinService添加方法
在WeixinServiceImpl添加實現
@Overridepublic boolean refund(Long orderId) {QueryWrapper<PaymentInfo> queryWrapper=new QueryWrapper<PaymentInfo>();queryWrapper.eq("order_id",orderId);PaymentInfo paymentInfo = paymentService.getOne(queryWrapper);RefundInfo refundInfo=refundInfoService.saveRefundInfo(paymentInfo);//已退款if(refundInfo.getRefundStatus().intValue() == RefundStatusEnum.REFUND.getStatus().intValue()){return true;}//執行微信退款HttpClient httpClient=new HttpClient("https://api.mch.weixin.qq.com/secapi/pay/refund");Map<String,String> paramMap = new HashMap<>(8);paramMap.put("appid",weiPayProperties.getAppid()); //公眾賬號IDparamMap.put("mch_id",weiPayProperties.getPartner()); //商戶編號paramMap.put("nonce_str",WXPayUtil.generateNonceStr());paramMap.put("transaction_id",paymentInfo.getTradeNo()); //微信支付訂單號paramMap.put("out_trade_no",paymentInfo.getOutTradeNo()); //商戶訂單編號paramMap.put("out_refund_no","tk"+paymentInfo.getOutTradeNo()); //商戶退款單號// paramMap.put("total_fee",paymentInfoQuery.getTotalAmount().multiply(new BigDecimal("100")).longValue()+"");// paramMap.put("refund_fee",paymentInfoQuery.getTotalAmount().multiply(new BigDecimal("100")).longValue()+"");paramMap.put("total_fee","1");paramMap.put("refund_fee","1");try {String paramXml = WXPayUtil.generateSignedXml(paramMap,weiPayProperties.getPartnerkey());httpClient.setXmlParam(paramXml);httpClient.setHttps(true);httpClient.setCert(true); //設置證書支持httpClient.setCertPassword(weiPayProperties.getPartner()); //設置證書密碼httpClient.post();String content = httpClient.getContent();Map<String, String> resultMap = WXPayUtil.xmlToMap(content);if("SUCCESS".equals(resultMap.get("result_code"))){ //微信退款成功refundInfo.setTradeNo(resultMap.get("refund_id"));//微信退款交易號refundInfo.setRefundStatus(RefundStatusEnum.REFUND.getStatus());refundInfo.setCallbackTime(new Date());refundInfo.setCallbackContent(JSONObject.toJSONString(resultMap));refundInfoService.updateById(refundInfo);return true;}return false;}catch (Exception ex){ex.printStackTrace();}return false;}(4)完成取消預約方法
在OrderService添加和實現
(5)在WeixinService添加方法
在OrderInfoController添加方法
(6)修改監聽器方法
service-hosp
修改OrderMqListener類
取消預約了,把可預約人數加回去
void cancelSchedule(String scheduleId);@Overridepublic void cancelSchedule(String scheduleId) {Schedule schedule=scheduleRepository.findByHosScheduleId(scheduleId);schedule.setAvailableNumber(schedule.getAvailableNumber()+1);scheduleRepository.save(schedule);} @Repository public interface ScheduleRepository extends MongoRepository<Schedule,String> {Schedule findByHosScheduleId(String scheduleId); }3、開發微信退款前端
(1)添加wx.js添加方法
(2)修改show.vue組件
//取消預約方法cancelOrder() {this.$confirm('確定取消預約嗎, 是否繼續?', '提示', {confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning'}).then(() => {wxApi.cancelOrder(this.orderId).then(resp=>{this.$message.success("取消成功")this.init()})}).catch(() => {this.$message({type: 'info',message: '已取消操作'}); });},總結
以上是生活随笔為你收集整理的尚医通(二十四)微信退款(取消预约功能)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络规划设计师 视频笔记
- 下一篇: YOLOv5实现吸烟行为检测