ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/inner/MemberGoodsCollectionController.java
@@ -6,6 +6,8 @@ import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; @@ -34,6 +36,8 @@ import com.ruoyi.system.api.feignClient.MemberClient; import me.chanjar.weixin.common.error.WxErrorException; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.util.EntityUtils; import org.springframework.web.bind.annotation.*; @@ -107,8 +111,8 @@ } catch (AlipayApiException e) { throw new RuntimeException(e); } }if (data.getWxOpenid()!=null){ push(data.getWxOpenid(),li.getFormId(),goodsSku.getSkuName(),goodsSeckill.getSeckillPrice(),goodsSeckill.getStartTime()); }if (data.getMiniOpenid()!=null){ push(data.getMiniOpenid(),li.getFormId(),goodsSku.getSkuName(),goodsSeckill.getSeckillPrice(),goodsSeckill.getStartTime()); } } @@ -150,11 +154,50 @@ return null; } /** * 发送消息 * @param template_id 所需下发的订阅模板id * @param page 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转 * @param touser 接收者(用户)的 openid * @param data 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }的object * @param miniprogram_state 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版 * @param lang 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN * @return */ public String push(String openid, String formid, String skuName, BigDecimal seckillPrice, LocalDateTime startTime) { //1,配置小程序信息 WxMaInMemoryConfig wxConfig = new WxMaInMemoryConfig(); String accessToken = null; try { accessToken = getAccessTokenByWX(); } catch (Exception e) { throw new RuntimeException(e); } JSONObject jsonObject = JSONObject.parseObject(accessToken); String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+jsonObject.get("access_token"); Map<String, Object> params = new HashMap<>(); params.put("template_id", "NHmHEbK8SjzafWgnErAxNR0b2XJzSehv2kPqbQefolU"); params.put("page", null); params.put("touser", openid); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm"); String data = "{\"thing1\":{\"value\":\""+skuName+"\"},\"amount3\":{\"value\":\""+seckillPrice.toString()+"\"}"+ ",\"time4\":{\"value\":\""+startTime.format(formatter)+"\"}"+ ",\"thing5\":{\"value\":\"优质老酒限时秒杀即将开始!点击参与秒杀哈\"}}"; params.put("data", JSON.parseObject(data)); params.put("miniprogram_state", "trial"); params.put("lang", "zh_CN"); try { Map<String, Object> payloadMapData = JSONObject.parseObject(HttpUtils.httpPost(url, JSONObject.toJSONString(params))); if (payloadMapData.containsKey("errCode")) { System.out.println("返回code码:"+payloadMapData.get("errCode").toString()); } } catch (Exception e) { throw new RuntimeException(e); } /* WxMaInMemoryConfig wxConfig = new WxMaInMemoryConfig(); wxConfig.setAppid("wx69e3ac6e13a889b7");//小程序appid wxConfig.setSecret("1b8bcfcb681524ac553e72054e5271ef");//小程序AppSecret @@ -223,7 +266,7 @@ return e.getMessage(); } */ return "推送成功"; } ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java
@@ -325,6 +325,8 @@ goodsGroupPurchaseInfoVO.setCoverPic(byId.getCoverPic()); goodsGroupPurchaseInfoVO.setPrice(byId.getPrice()); goodsGroupPurchaseInfoVO.setShareTitle(one.getShareTitle()); goodsGroupPurchaseInfoVO.setGroupStatus(one.getGroupStatus()); goodsGroupPurchaseInfoVO.setStartStatus(one.getStartStatus()); goodsGroupPurchaseInfoVO.setSharePic(one.getSharePic()); goodsGroupPurchaseInfoVO.setGroupPurchasePrice(one.getGroupPurchasePrice()); goodsGroupPurchaseInfoVO.setGroupSize(one.getGroupSize()); ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSeckillAppointmentServiceImpl.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.goods.domain.GoodsSeckillAppointment; import com.ruoyi.goods.mapper.GoodsSeckillAppointmentMapper; @@ -38,26 +39,31 @@ private RedisService redisService; @Override public R goodsSeckillAppointment(HomeGoodsSkuDTO homeGoodsSkuDTO) { GoodsSeckillAppointment goodsSeckillAppointment=new GoodsSeckillAppointment(); goodsSeckillAppointment.setGoodsSeckillId(homeGoodsSkuDTO.getGoodsSkuId()); goodsSeckillAppointment.setMemberId(homeGoodsSkuDTO.getMemberId()); goodsSeckillAppointment.setFormId(homeGoodsSkuDTO.getFormId()); this.save(goodsSeckillAppointment); GoodsSeckill byId = goodsSeckillMapper.selectById(homeGoodsSkuDTO.getGoodsSkuId()); DelayTask delayTask = new DelayTask(); delayTask.setDelFlag(0); delayTask.setCreateTime(LocalDateTime.now()); delayTask.setExecuteTime(byId.getStartTime().minusMinutes(5)); delayTask.setExecuteTime(byId.getStartTime().minusMinutes(30)); delayTask.setRedisKey(DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId()); sysUserClient.addDelayTask(delayTask, SecurityConstants.INNER); Duration duration = Duration.between(LocalDateTime.now(), byId.getStartTime().minusMinutes(5)); Duration duration = Duration.between(LocalDateTime.now(), byId.getStartTime().minusMinutes(30)); try { redisService.setCacheObject( DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId(), byId.getStartTime().minusMinutes(30), duration.getSeconds(), TimeUnit.SECONDS); }catch (Exception e){ throw new ServiceException("即将开始已无法遇约"); } redisService.setCacheObject( DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId(), byId.getStartTime().minusMinutes(30), duration.getSeconds(), TimeUnit.SECONDS); GoodsSeckillAppointment goodsSeckillAppointment=new GoodsSeckillAppointment(); goodsSeckillAppointment.setGoodsSeckillId(homeGoodsSkuDTO.getGoodsSkuId()); goodsSeckillAppointment.setMemberId(homeGoodsSkuDTO.getMemberId()); goodsSeckillAppointment.setFormId(homeGoodsSkuDTO.getFormId()); this.save(goodsSeckillAppointment); return R.ok(); } ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/utli/HttpUtils.java
@@ -1,22 +1,23 @@ package com.ruoyi.goods.utli; import com.ruoyi.common.core.utils.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.*; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; @@ -180,6 +181,29 @@ return httpClient.execute(request); } public static String httpPost(String url, String json) throws Exception { //初始HttpClient CloseableHttpClient httpClient = HttpClients.createDefault(); //创建Post对象 HttpPost httpPost = new HttpPost(url); //设置Content-Type /* httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");*/ StringEntity se = new StringEntity(json,"UTF-8"); se.setContentType("application/x-www-form-urlencoded"); httpPost.setEntity(se); //发起请求,获取response对象 CloseableHttpResponse response = httpClient.execute(httpPost); //获取请求码 //response.getStatusLine().getStatusCode(); //获取返回数据实体对象 HttpEntity entity = response.getEntity(); //转为字符串 String result = EntityUtils.toString(entity, "UTF-8"); return result; } /** * Put String * @param host