白羽
2018-06-20
来源 :网络
阅读 2096
评论 0
摘要:本文将带你了解微信小程序转发链接交互逻辑,业务逻辑:用户A转发给用户B,用户A和B都收到一个服务通知,用户B再次点击转发链接双方不会收到服务通知,针对同一封贺卡 同一个用户只能收到一条模版消息,希望本文对大家学微信有所帮助。
/**
* 保存卡券
*/
public void sendAndSave(CouponDTO couponDTO) {
Long cardId = couponDTO.getCardId();
Long userId = SecurityUtils.getCurrentUserId();
//formId不能为空
if (StringUtils.isEmpty(couponDTO.getFormId())) {
throw new BaseAppException("formId不能为空");
}
//当前用户是否是卡的创建人
Card card = cardRepository.findOne(cardId);
if(userId.equals(card.getCreateId())){
return;
}
//如果当前用户已经点开过
List<Coupon> couponForCurrentIds = couponRepository.findByCardIdAndReceiveId(cardId,userId);
//当前用户添加十张卡券(不考虑使用情况)[当前用户]
List<Coupon> sumCouponForCurrentIds = couponRepository.findByReceiveId(userId);
String templateId = applicationProperties.getTemplateId();//模板消息id
String accessToken = getAccessToken().get("accessToken");
Card cardCoupon = new Card();
cardCoupon.setId(couponDTO.getCardId());
if(couponForCurrentIds.size() == 0 && sumCouponForCurrentIds.size() < 10){
//给当前用户发送微信信息
String openIdForCurrentUser = SecurityUtils.getCurrentUser().getOpenId();
String formIdForCurrentUser = couponDTO.getFormId();
templateItem(openIdForCurrentUser, templateId, accessToken, formIdForCurrentUser);
//保存当前用户的券记录
Coupon coupon = new Coupon();
coupon.setReceiveId(SecurityUtils.getCurrentUserId());
coupon.setCard(cardCoupon);
save(coupon);
}
//制卡人是否已收到券信息
List<Coupon> couponForCreateIds = couponRepository.findByCardIdAndReceiveId(cardId,card.getCreateId());
//当前用户添加十张卡券(不考虑使用情况)[当前用户]
List<Coupon> sumCouponForCreateIds = couponRepository.findByReceiveId(userId);
if(couponForCreateIds.size()==0 && sumCouponForCreateIds.size() < 10){
//给制卡人发送微信信息
String openIdForCreateId = userInfoRepository.findOne(card.getCreateId()).getOpenId();
//创建贺卡用户模板 创建者的formId从表单表里面取
Form form = formRepository.findByCreateIdAndCardId(card.getCreateId(),cardId);
//form为空或超过7天,无法发送模板消息
if (form == null || form.getFailureTime().toInstant().toEpochMilli() < ZonedDateTime.now().toInstant().toEpochMilli()) {
return;
}
String formIdForCreateId = form.getFormId();
templateItem(openIdForCreateId, templateId, accessToken, formIdForCreateId);
//保存制卡人的券记录
Coupon couponForCreateId = new Coupon();
couponForCreateId.setReceiveId(card.getId());
couponForCreateId.setCard(cardCoupon);
save(couponForCreateId);
}
//修改分享状态
card.setState(1);
cardRepository.save(card);
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号