| | |
| | | package com.doumee.core.wx; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.HttpsUtil; |
| | | import com.doumee.dao.business.model.Goodsorder; |
| | | import com.doumee.dao.business.model.GoodsorderDetail; |
| | | import com.doumee.dao.business.model.Member; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by IntelliJ IDEA. |
| | |
| | | private static String programUserUrl = "pages/balanceDetails/balanceDetails"; |
| | | |
| | | |
| | | public static void createSendData(Constants.WxNotice wxNotice, Goodsorder goodsorder, List<GoodsorderDetail> gdetailList, Member member){ |
| | | Map<String, TemplateData> m = new HashMap<>(); |
| | | String jumpUrl = wxNotice.getJumpUrl(); |
| | | if(Constants.equalsInteger(wxNotice.getType(),Constants.ZERO)){ |
| | | //发货通知 |
| | | m.put("character_string1}",new TemplateData(goodsorder.getCode().toString()));//订单编号 |
| | | m.put("thing7}",new TemplateData(String.join(",", gdetailList.stream().map(i->i.getName()).collect(Collectors.toList()))));//商品名称 |
| | | m.put("thing10}",new TemplateData(goodsorder.getKdName()));//快递公司 |
| | | m.put("character_string3}",new TemplateData(goodsorder.getKdCode()));//快递单号 |
| | | jumpUrl = jumpUrl+"?id="+goodsorder.getId(); |
| | | }else if(Constants.equalsInteger(wxNotice.getType(),Constants.ONE)){ |
| | | //订单核销 |
| | | m.put("character_string3}",new TemplateData(goodsorder.getCode().toString()));//订单编号 |
| | | m.put("time2}",new TemplateData(DateUtil.formatDate(goodsorder.getDoneDate(),"yyyy年MM月dd HH:mm")));//核销时间 |
| | | m.put("phrase1}",new TemplateData("已核销"));//核销状态 |
| | | jumpUrl = jumpUrl+"?id="+goodsorder.getId(); |
| | | }else if(Constants.equalsInteger(wxNotice.getType(),Constants.TWO)){ |
| | | //订单退款 |
| | | m.put("character_string1}",new TemplateData(goodsorder.getCode().toString()));//订单编号 |
| | | m.put("thing2}",new TemplateData(String.join(",", gdetailList.stream().map(i->i.getName()).collect(Collectors.toList()))));//商品名称 |
| | | m.put("date9}",new TemplateData(DateUtil.formatDate(goodsorder.getRefundTime(),"yyyy年MM月dd HH:mm")));//退款时间 |
| | | m.put("phrase1}",new TemplateData(goodsorder.getRefundMoney()+"元"));//退款金额 |
| | | jumpUrl = jumpUrl+"?id="+goodsorder.getId(); |
| | | } |
| | | SendWxMessage.sendWxMessage(wxNotice.getTempId(),m,member.getOpenId(),jumpUrl); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送消息 |
| | | * @param tempId |
| | | * @param m |
| | | * @param openid |
| | | * @param jumpUrl |
| | | */ |
| | | public static void sendWxMessage(String tempId,Map<String, TemplateData> m,String openid,String jumpUrl){ |
| | | try{ |
| | | String accessToken = WxMiniConfig.wxMaService.getAccessToken(); |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | //这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取) |
| | | String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken; |
| | | //拼接推送的模版 |
| | | WxMsgVO wxMsgVo = new WxMsgVO(); |
| | | //用户的openid(要发送给那个用户) |
| | | wxMsgVo.setTouser(openid); |
| | | wxMsgVo.setTemplate_id(tempId); |
| | | wxMsgVo.setPage(jumpUrl); |
| | | ResponseEntity<String> responseEntity = |
| | | restTemplate.postForEntity(url, wxMsgVo, String.class); |
| | | log.info("微信小程序->发送订阅消息:{}",JSONObject.toJSONString(responseEntity)); |
| | | }catch (WxErrorException wxErrorException){ |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 取消订单 通知 |
| | | * @param member 会员信息 |