package com.starry.admin.modules.weichat.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.common.exception.ServiceException;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserReviewInfoEntity;
import com.starry.admin.modules.clerk.module.enums.ListingStatus;
import com.starry.admin.modules.clerk.module.enums.OnboardingStatus;
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
import com.starry.admin.modules.order.module.constant.OrderMessageLabelResolver;
import com.starry.admin.modules.order.module.entity.PlayOrderComplaintInfoEntity;
import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity;
import com.starry.admin.modules.personnel.module.entity.PlayPersonnelAdminInfoEntity;
import com.starry.admin.modules.personnel.service.IPlayPersonnelAdminInfoService;
import com.starry.admin.modules.system.module.entity.SysTenantEntity;
import com.starry.admin.modules.system.service.impl.SysTenantServiceImpl;
import com.starry.admin.utils.SecurityUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

/**
 * @author admin
 */
@Slf4j
@Service
public class WxCustomMpService {

    @Resource
    private WxMpService wxMpService;

    @Resource
    private SysTenantServiceImpl tenantService;
    @Resource
    private IPlayCustomUserInfoService customUserInfoService;
    @Resource
    private IPlayPersonnelAdminInfoService playPersonnelAdminInfoService;
    @Resource
    private IPlayClerkUserInfoService clerkUserInfoService;
    @Resource
    private ThreadPoolTaskExecutor executor;


    /**
     * 支付成功回调地址
     */
    public static String NOTIFY_URL = "https://julyharbor.com/api/wx/pay/jsCallback";

    public WxMpService proxyWxMpService() {
        String tenantId = SecurityUtils.getTenantId();
        if (StrUtil.isBlankIfStr(tenantId)) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        SysTenantEntity entity = tenantService.selectSysTenantByTenantId(tenantId);
        if (entity == null) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        WxMpMapConfigImpl config = new WxMpMapConfigImpl();
        config.setAppId(entity.getAppId());
        config.setSecret(entity.getSecret());
        wxMpService.addConfigStorage(entity.getAppId(), config);
        return wxMpService.switchoverTo(entity.getAppId());
    }

    public WxMpService proxyWxMpService(String tenantId) {
        if (StrUtil.isBlankIfStr(tenantId)) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        SysTenantEntity entity = tenantService.selectSysTenantByTenantId(tenantId);
        if (entity == null) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        WxMpMapConfigImpl config = new WxMpMapConfigImpl();
        config.setAppId(entity.getAppId());
        config.setSecret(entity.getSecret());
        wxMpService.addConfigStorage(entity.getAppId(), config);
        return wxMpService.switchoverTo(entity.getAppId());
    }

    public WxPayService getWxPay() {
        String tenantId = SecurityUtils.getTenantId();
        if (StrUtil.isBlankIfStr(tenantId)) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        SysTenantEntity entity = tenantService.selectSysTenantByTenantId(tenantId);
        if (entity == null) {
            throw new CustomException("系统错误,租户ID不能为空");
        }
        if (StringUtils.isEmpty(entity.getMchId())) {
            throw new CustomException("商户号不能为空，请联系平台方进行配置");
        }
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(StringUtils.trimToNull(entity.getAppId()));
        payConfig.setMchId(StringUtils.trimToNull(entity.getMchId()));
        payConfig.setMchKey(StringUtils.trimToNull(entity.getMchKey()));

        payConfig.setNotifyUrl(StringUtils.trimToNull(NOTIFY_URL));
        payConfig.setTradeType("JSAPI");
        payConfig.setSignType("MD5");
        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(false);
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }

    /**
     * 充值成功-发送微信消息
     *
     * @param order 订单信息
     */
    public void sendBalanceMessage(PlayOrderInfoEntity order) {
        PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(order.getPurchaserBy());
        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(order.getTenantId());
        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getChongzhichenggongTemplateId(),
                customUserInfo.getOpenid(), "https://" + tenant.getTenantKey() + ".julyharbor.com/user/");
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("time4", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        data.add(new WxMpTemplateData("amount2", order.getOrderMoney().toString()));
        data.add(new WxMpTemplateData("amount17", "0"));
        data.add(new WxMpTemplateData("thing10", tenant.getTenantName()));
        templateMessage.setData(data);
        try {
            proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error("充值成功发送消息异常", e);
        }
    }

    public void sendCreateOrderMessageBatch(List<PlayClerkUserInfoEntity> clerkList, String orderNo, String string,
                                            String commodityName, String orderId, String placeType, String rewardType) {
        if (CollectionUtils.isEmpty(clerkList)) {
            return;
        }

        executor.execute(() -> clerkList.parallelStream()
                .filter(Objects::nonNull)
                .filter(ca -> OnboardingStatus.isActive(ca.getOnboardingState()))
                .filter(ca -> ListingStatus.isListed(ca.getListingState()))
                .forEach(ca -> sendCreateOrderMessage(ca.getTenantId(), ca.getOpenid(), orderNo, string, commodityName,
                        orderId, placeType, rewardType)));
    }

    /**
     * 顾客下指定单后，给店员发新订单通知 通过微信公众号发送消息
     *
     * @param tenantId      租户ID
     * @param openId        消息接收人openID
     * @param orderNo       消息内容-订单编号
     * @param money
     * @param commodityName
     * @param orderId
     */
    public void sendCreateOrderMessage(String tenantId, String openId, String orderNo, String money,
                                       String commodityName, String orderId, String placeType, String rewardType) {

        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(tenantId);
        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getXindingdanshoulitongzhiTemplateId(),
                openId, "https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/orderDetail/" + orderId);
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("time6", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        data.add(new WxMpTemplateData("character_string9", orderNo));
        data.add(new WxMpTemplateData("short_thing5", OrderMessageLabelResolver.resolve(placeType, rewardType)));
        data.add(new WxMpTemplateData("thing11", commodityName));
        data.add(new WxMpTemplateData("amount8", money));
        templateMessage.setData(data);
        PlayClerkUserInfoEntity clerkUserInfo =
                StringUtils.isBlank(openId) ? null : clerkUserInfoService.selectByOpenid(openId);
        String clerkId = clerkUserInfo == null ? null : clerkUserInfo.getId();
        String clerkNickname = clerkUserInfo == null ? null : clerkUserInfo.getNickname();
        try {
            proxyWxMpService(tenantId).getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error(
                    "接单成功发送消息异常, tenantId={}, tenantName={}, orderId={}, orderNo={}, recipientType=clerk, clerkId={}, openId={}, nickname={}",
                    tenantId, tenant.getTenantName(), orderId, orderNo, clerkId, openId, clerkNickname, e);
        }

    }
    /**
     * 店员接单后，通过微信公众号发送消息
     *
     * @param orderInfo
     * @author admin
     * @since 2024/7/31 10:51
     **/
    private void sendOrderMessage(PlayOrderInfoEntity orderInfo) {
        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(orderInfo.getTenantId());
        PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService.selectById(orderInfo.getAcceptBy());
        PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(orderInfo.getPurchaserBy());

        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getJiedanchenggongtongzhiTemplateId(),
                clerkUserInfo.getOpenid(),
                "https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/orderDetail/" + orderInfo.getId());
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("character_string1", orderInfo.getOrderNo()));
        data.add(new WxMpTemplateData("time2", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        templateMessage.setData(data);
        try {
            if (clerkUserInfo != null) {
                log.info("发送接单成功通知，orderId={}, orderNo={}, recipientType=clerk, openId={}, nickname={}",
                        orderInfo.getId(), orderInfo.getOrderNo(), clerkUserInfo.getOpenid(), clerkUserInfo.getNickname());
            }
            proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error(e.getMessage(), e);
        }

        templateMessage.setToUser(customUserInfo.getOpenid());
        templateMessage
                .setUrl("https://" + tenant.getTenantKey() + ".julyharbor.com/user/#/orderDetail/" + orderInfo.getId());
        try {
            if (customUserInfo != null) {
                log.info("发送接单成功通知，orderId={}, orderNo={}, recipientType=customer, openId={}, nickname={}",
                        orderInfo.getId(), orderInfo.getOrderNo(), customUserInfo.getOpenid(), customUserInfo.getNickname());
            }
            proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error(e.getMessage(), e);
        }

    }

    public void sendCheckMessage(PlayClerkUserReviewInfoEntity entity, PlayClerkUserInfoEntity userInfo,
                                 String reviewState) {
        String touser = userInfo.getOpenid();

        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(userInfo.getTenantId());
        String template_id = tenant.getRzsqshtxTemplateId();
        String tenantKey = tenant.getTenantKey();
        String url = "https://" + tenantKey + ".julyharbor.com/clerk/";

        WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
        templateMessage.setTemplateId(template_id);
        templateMessage.setToUser(touser);
        templateMessage.setUrl(url);
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("short_thing7", reviewState.equals("1") ? "通过" : "拒绝"));
        data.add(new WxMpTemplateData("thing2", entity.getNickname()));
        data.add(new WxMpTemplateData("thing11", entity.getWeiChatCode()));
        data.add(new WxMpTemplateData("time8", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        templateMessage.setData(data);
        try {
            proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error(e.getMessage(), e);

        }

    }

    public void sendClerkApplyNoticeForAdmin(PlayClerkUserReviewInfoEntity entity, String tenantId) {
        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(tenantId);
        String template_id = tenant.getRzsqAdminTemplateId();
        String tenantKey = tenant.getTenantKey();
        String url = "https://" + tenantKey + ".julyharbor.com/clerk/#/admin/clerk-apply-list";
        List<PlayPersonnelAdminInfoEntity> adminInfoEntityList = playPersonnelAdminInfoService.list(Wrappers
                .lambdaQuery(PlayPersonnelAdminInfoEntity.class).select(PlayPersonnelAdminInfoEntity::getSysUserId));
        for (PlayPersonnelAdminInfoEntity adminInfoEntity : adminInfoEntityList) {
            PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService
                    .getOne(Wrappers.lambdaQuery(PlayClerkUserInfoEntity.class)
                            .eq(PlayClerkUserInfoEntity::getSysUserId, adminInfoEntity.getSysUserId()), false);
            if (Objects.isNull(clerkUserInfo)) {
                continue;
            }
            WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
            templateMessage.setTemplateId(template_id);
            templateMessage.setToUser(clerkUserInfo.getOpenid());
            templateMessage.setUrl(url);
            List<WxMpTemplateData> data = new ArrayList<>();
            data.add(new WxMpTemplateData("phone_number15", entity.getPhone()));
            data.add(new WxMpTemplateData("thing11", entity.getNickname()));
            // data.add(new WxMpTemplateData("thing3", "有新的店员提交了审核，请前去查看"));
            data.add(new WxMpTemplateData("thing2", "有新的店员提交了审核，请前去查看"));
            templateMessage.setData(data);
            try {
                proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
            } catch (WxErrorException e) {
                log.error(e.getMessage(), e);

            }
        }

    }

    /**
     * 获取微信发啥消息模板
     *
     * @param templateId 消息模板ID
     * @param toUser     发送目标用户ID
     * @param url        消息回调地址
     * @return WxMpTemplateMessage
     */
    public WxMpTemplateMessage getWxMpTemplateMessage(String templateId, String toUser, String url) {
        WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
        templateMessage.setTemplateId(templateId);
        templateMessage.setToUser(toUser);
        templateMessage.setUrl(url);
        return templateMessage;
    }

    public void sendComplaintMessage(PlayOrderComplaintInfoEntity info, PlayOrderInfoEntity orderInfo) {

        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(info.getTenantId());
        List<PlayPersonnelAdminInfoEntity> adminInfoEntityList = playPersonnelAdminInfoService.list(Wrappers
                .lambdaQuery(PlayPersonnelAdminInfoEntity.class).select(PlayPersonnelAdminInfoEntity::getSysUserId));

        for (PlayPersonnelAdminInfoEntity adminInfo : adminInfoEntityList) {
            PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService
                    .getOne(Wrappers.lambdaQuery(PlayClerkUserInfoEntity.class)
                            .eq(PlayClerkUserInfoEntity::getSysUserId, adminInfo.getSysUserId()), false);
            if (Objects.isNull(clerkUserInfo)) {
                continue;
            }
            WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdantousuchuliTemplateId(),
                    clerkUserInfo.getOpenid(),
                    "https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/admin/order/complain-list");
            List<WxMpTemplateData> data = new ArrayList<>();
            data.add(new WxMpTemplateData("character_string", orderInfo.getOrderNo()));
            data.add(new WxMpTemplateData("time2", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
            templateMessage.setData(data);
            try {
                proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
            } catch (WxErrorException e) {
                log.error("发送投诉消息异常", e);
            }
        }

    }

    public void sendOrderFinishMessage(PlayOrderInfoEntity order) {
        if (order.getPlaceType().equals("1") || order.getPlaceType().equals("2")) {
            SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(order.getTenantId());
            PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(order.getPurchaserBy());
            PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService.selectById(order.getAcceptBy());
            this.sendUserOrderFinishMessage(order, customUserInfo, tenant);
            this.sendClerkOrderFinishMessage(order, clerkUserInfo, tenant);

        }

    }

    private void sendClerkOrderFinishMessage(PlayOrderInfoEntity order, PlayClerkUserInfoEntity clerkUserInfo, SysTenantEntity tenant) {
        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdanwanchengtongzhiTemplateId(),
                clerkUserInfo.getOpenid(),
                "https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/orderDetail/" + order.getId());
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        data.add(new WxMpTemplateData("character_string8", order.getOrderNo()));
        data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
        templateMessage.setData(data);
        try {
            proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error("订单完成发送消息异常", e);
        }
    }

    private void sendUserOrderFinishMessage(PlayOrderInfoEntity order, PlayCustomUserInfoEntity customUserInfo, SysTenantEntity tenant) {
        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdanwanchengtongzhiTemplateId(),
                customUserInfo.getOpenid(),
                "https://" + tenant.getTenantKey() + ".julyharbor.com/user/#/orderDetail/" + order.getId());
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        data.add(new WxMpTemplateData("character_string8", order.getOrderNo()));
        data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
        templateMessage.setData(data);
        try {
            proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error("订单完成发送消息异常", e);
        }
    }

    public void sendOrderCancelMessage(PlayOrderInfoEntity orderInfo, String refundReason) {
        SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(orderInfo.getTenantId());

        PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(orderInfo.getPurchaserBy());

        WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getQuxiaodingdantongzhiTemplateId(),
                customUserInfo.getOpenid(),
                "https://" + tenant.getTenantKey() + ".julyharbor.com/user/#/orderDetail/" + orderInfo.getId());
        List<WxMpTemplateData> data = new ArrayList<>();
        data.add(new WxMpTemplateData("character_string2", orderInfo.getOrderNo()));
        data.add(new WxMpTemplateData("thing5", StringUtils.isEmpty(refundReason) ? "已取消" : refundReason));
        data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        templateMessage.setData(data);
        try {
            if (customUserInfo != null) {
                log.info("发送取消订单通知，orderId={}, orderNo={}, recipientType=customer, openId={}, nickname={}",
                        orderInfo.getId(), orderInfo.getOrderNo(), customUserInfo.getOpenid(), customUserInfo.getNickname());
            }
            proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            log.error(e.getMessage(), e);
        }

        if (StringUtils.isNotEmpty(orderInfo.getAcceptBy())) {
            PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService.selectById(orderInfo.getAcceptBy());

            templateMessage.setToUser(clerkUserInfo.getOpenid());
            templateMessage.setUrl(
                    "https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/orderDetail/" + orderInfo.getId());
            try {
                if (clerkUserInfo != null) {
                    log.info("发送取消订单通知，orderId={}, orderNo={}, recipientType=clerk, openId={}, nickname={}",
                            orderInfo.getId(), orderInfo.getOrderNo(), clerkUserInfo.getOpenid(), clerkUserInfo.getNickname());
                }
                proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
            } catch (WxErrorException e) {
                log.error(e.getMessage(), e);
            }
        }

    }

    /**
     * 异步发送订单接单通知
     */
    public void sendOrderMessageAsync(PlayOrderInfoEntity order) {
        executor.execute(() -> {
            try {
                sendOrderMessage(order);
            } catch (Exception e) {
                log.error("发送订单接单通知失败，orderId={}", order.getId(), e);
            }
        });
    }

    /**
     * 异步发送订单完成通知
     */
    public void sendOrderFinishMessageAsync(PlayOrderInfoEntity order) {
        executor.execute(() -> {
            try {
                sendOrderFinishMessage(order);
            } catch (Exception e) {
                log.error("发送订单完成通知失败，orderId={}", order.getId(), e);
            }
        });
    }

    /**
     * 异步发送订单取消通知
     */
    public void sendOrderCancelMessageAsync(PlayOrderInfoEntity order, String refundReason) {
        executor.execute(() -> {
            try {
                sendOrderCancelMessage(order, refundReason);
            } catch (Exception e) {
                log.error("发送订单取消通知失败，orderId={}", order.getId(), e);
            }
        });
    }

    public void checkSubscribeThrowsExp(String openId, String tenantId) {
        if (StrUtil.isBlankIfStr(openId)) {
            throw new ServiceException("openId不能为空");
        }
        try {
            WxMpUser wxMpUser = proxyWxMpService(tenantId).getUserService().userInfo(openId);
            if (!wxMpUser.getSubscribe()) {
                log.info("检测到用户未关注公众号：" + JSONObject.toJSONString(wxMpUser));
                throw new ServiceException("请先关注公众号然后再来使用系统~");
            }
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    public Boolean checkSubscribe(String openId, String tenantId) {
        if (StrUtil.isBlankIfStr(openId)) {
            throw new ServiceException("openId不能为空");
        }
        try {
            WxMpUser wxMpUser = proxyWxMpService(tenantId).getUserService().userInfo(openId);
            return wxMpUser.getSubscribe();
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

}
