Search in sources :

Example 1 with TextBuilder

use of com.code.server.login.wechat.builder.TextBuilder in project summer by foxsugar.

the class MenuHandler method handle_clear.

private WxMpXmlOutMessage handle_clear(WxMpXmlMessage wxMessage, WxMpService wxService) {
    WxMpUser wxMpUser = null;
    try {
        wxMpUser = wxService.getUserService().userInfo(wxMessage.getFromUser());
        String unionId = wxMpUser.getUnionId();
        String openId = wxMpUser.getOpenId();
        Long agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(unionId);
        if (agentId == null || agentId == 0) {
            return new TextBuilder().build("代理不存在", wxMessage, wxService);
        }
        // gameAgent 是否已经生成ticket
        AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
        // 金额小于 100 不能提
        if (agentBean.getRebate() < 100) {
            return new TextBuilder().build("金额小于100,不能提现", wxMessage, wxService);
        }
        double rebate = agentBean.getRebate();
        // 不能大于20000
        if (rebate > 20000) {
            rebate = 20000;
        }
        Double amount = rebate * 100;
        DecimalFormat df = new DecimalFormat("######0.00");
        // 到账金额
        double amountInt = Double.valueOf(df.format(amount / 100));
        // 手续费
        // double poundage =  Double.valueOf(df.format((rebate *100 - amountInt *100)/100));
        double poundage = 0;
        long tradeId = createOrderId();
        String ip = Utils.getLocalIp();
        EntPayRequest wxEntPayRequest = new EntPayRequest();
        wxEntPayRequest.setAppid(wechatConfig.getMpAppId());
        wxEntPayRequest.setMchId(wechatConfig.getMchId());
        wxEntPayRequest.setNonceStr(Sha1Util.getNonceStr());
        wxEntPayRequest.setPartnerTradeNo("" + tradeId);
        wxEntPayRequest.setOpenid(openId);
        wxEntPayRequest.setCheckName("NO_CHECK");
        // 金额 为分
        wxEntPayRequest.setAmount(amount.intValue());
        wxEntPayRequest.setDescription("提现");
        wxEntPayRequest.setSpbillCreateIp(ip);
        try {
            EntPayResult wxEntPayResult = payService.getEntPayService().entPay(wxEntPayRequest);
            if ("SUCCESS".equals(wxEntPayResult.getResultCode().toUpperCase()) && "SUCCESS".equals(wxEntPayResult.getReturnCode().toUpperCase())) {
                this.logger.info("企业对个人付款成功!\n付款信息:\n" + wxEntPayResult.toString());
                RedisManager.getAgentRedisService().addRebate(agentId, -rebate, null, null);
                // 充值记录
                Charge charge = new Charge();
                charge.setOrderId("" + tradeId);
                charge.setUserid(agentId);
                charge.setMoney(rebate);
                charge.setMoney_point(rebate);
                charge.setStatus(1);
                charge.setSp_ip(ip);
                charge.setRecharge_source("11");
                // 充值类型
                charge.setChargeType(0);
                charge.setCreatetime(new Date());
                chargeService.save(charge);
                // redis 提现记录
                RedisManager.getLogRedisService().logTakeOutNum(rebate);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(wxMpUser.getOpenId()).templateId("fT9wgjkN5Wfm8dtbPQiozDg7uftEaE6AoMq3YLDeUxc").url("").build();
                String date = dateFormat.format(new Date());
                templateMessage.addData(new WxMpTemplateData("first", "您申请的提现金额已到帐.")).addData(new WxMpTemplateData("keyword1", date)).addData(new WxMpTemplateData("keyword2", "提现到零钱")).addData(new WxMpTemplateData("keyword3", "" + amountInt)).addData(new WxMpTemplateData("remark", "感谢您的使用"));
                wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
                // 发送消息
                return null;
            // {{first.DATA}}{{fi
            // 申请时间:{{keyword1.DATA}}
            // 提现方式:{{keyword2.DATA}}
            // 提现金额:{{keyword3.DATA}}
            // 手续费用:{{keyword4.DATA}}
            // 到账金额:{{keyword5.DATA}}
            // {{remark.DATA}}
            } else {
                this.logger.error("err_code: " + wxEntPayResult.getErrCode() + "  err_code_des: " + wxEntPayResult.getErrCodeDes());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (WxErrorException e) {
        logger.error("提现出错", e);
        return new TextBuilder().build(e.getMessage(), wxMessage, wxService);
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SocketException(java.net.SocketException) WxMpTemplateData(me.chanjar.weixin.mp.bean.template.WxMpTemplateData) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) DecimalFormat(java.text.DecimalFormat) Charge(com.code.server.db.model.Charge) Date(java.util.Date) SocketException(java.net.SocketException) IOException(java.io.IOException) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException) EntPayRequest(com.github.binarywang.wxpay.bean.entpay.EntPayRequest) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException) AgentBean(com.code.server.constant.game.AgentBean) TextBuilder(com.code.server.login.wechat.builder.TextBuilder) WxMpTemplateMessage(me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage) EntPayResult(com.github.binarywang.wxpay.bean.entpay.EntPayResult) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with TextBuilder

use of com.code.server.login.wechat.builder.TextBuilder in project summer by foxsugar.

the class SubscribeHandler method handle.

@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) throws WxErrorException {
    this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
    // 获取微信用户基本信息
    WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
    if (userWxInfo != null) {
        // TODO 可以添加关注用户到本地
        GameAgentWx gameAgentWx = new GameAgentWx();
        gameAgentWx.setUnionId(userWxInfo.getUnionId());
        gameAgentWx.setOpenId(userWxInfo.getOpenId());
        gameAgentWxService.getGameAgentWxDao().save(gameAgentWx);
    }
    WxMpXmlOutMessage responseResult = null;
    try {
        responseResult = handleSpecial(wxMessage, userWxInfo, weixinService);
    } catch (Exception e) {
        this.logger.error(e.getMessage(), e);
    }
    if (responseResult != null) {
        return responseResult;
    }
    try {
        return new TextBuilder().build("感谢关注", wxMessage, weixinService);
    } catch (Exception e) {
        this.logger.error(e.getMessage(), e);
    }
    return null;
}
Also used : GameAgentWx(com.code.server.db.model.GameAgentWx) TextBuilder(com.code.server.login.wechat.builder.TextBuilder) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxMpXmlOutMessage(me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Example 3 with TextBuilder

use of com.code.server.login.wechat.builder.TextBuilder in project summer by foxsugar.

the class MenuHandler method handle_link.

/**
 * 处理链接
 *
 * @param wxMessage
 * @param wxService
 * @return
 */
private WxMpXmlOutMessage handle_link(WxMpXmlMessage wxMessage, WxMpService wxService) {
    Long agentId = null;
    try {
        WxMpUser wxMpUser = wxService.getUserService().userInfo(wxMessage.getFromUser());
        String unionId = wxMpUser.getUnionId();
        agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(unionId);
        if (agentId == null || agentId == 0) {
            return new TextBuilder().build("代理不存在", wxMessage, wxService);
        }
        // gameAgent 是否已经生成ticket
        AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
        if (agentBean.getOpenId() == null || agentBean.getQrTicket() == null || "".equals(agentBean.getQrTicket())) {
            agentBean.setImage(wxMpUser.getHeadImgUrl());
            agentBean.setOpenId(wxMpUser.getOpenId());
            // 根据unionId生成二维码 todo 加上游戏key
            WxMpQrCodeTicket ticket = wxService.getQrcodeService().qrCodeCreateLastTicket(serverConfig.getDomainMapKey() + "|" + unionId);
            agentBean.setQrTicket(ticket.getTicket());
            RedisManager.getAgentRedisService().updateAgentBean(agentBean);
        }
        RedisManager.getAgentRedisService().updateAgentBean(agentBean);
    } catch (WxErrorException e) {
        e.printStackTrace();
    }
    WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
    item.setTitle("您有如下专属代理链接");
    item.setDescription("点击进入专属界面");
    WxMpXmlOutNewsMessage.Item item1 = new WxMpXmlOutNewsMessage.Item();
    // todo 展示二维码 链接
    item1.setPicUrl("https://mmbiz.qpic.cn/mmbiz_png/wj1STzkg04h46BuribmuoJnsMQgc2m70558p3mE91j6zq4sph6RavCicfUiahTSRj4CVRSRN9ecdJKic6ysZeBCZiag/0?wx_fmt=png");
    item1.setTitle("棋牌");
    item1.setDescription("点击进入专属界面");
    // String url = "http://" + serverConfig.getDomain() + "/game/wechat/clickLink";
    String sid = "" + System.currentTimeMillis() + "_" + new Random().nextInt(999999);
    String url = MessageFormat.format("http://" + serverConfig.getDomain() + "/agent/#/sharelink?id={0}&sid={1}&in=1", "" + agentId, sid);
    // String url = MessageFormat.format("http://" + serverConfig.getDomain() +"/game/wechat/showLink?agentId={0}&sid={1}", ""+agentId, sid);
    logger.info("设置专属链接地址 : " + url);
    item1.setUrl(url);
    item1.setDescription("");
    WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).addArticle(item, item1).build();
    return m;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket) TextBuilder(com.code.server.login.wechat.builder.TextBuilder) Random(java.util.Random) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxMpXmlOutNewsMessage(me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Aggregations

TextBuilder (com.code.server.login.wechat.builder.TextBuilder)3 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)3 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)3 AgentBean (com.code.server.constant.game.AgentBean)2 Charge (com.code.server.db.model.Charge)1 GameAgentWx (com.code.server.db.model.GameAgentWx)1 EntPayRequest (com.github.binarywang.wxpay.bean.entpay.EntPayRequest)1 EntPayResult (com.github.binarywang.wxpay.bean.entpay.EntPayResult)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1 WxMpXmlOutMessage (me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage)1 WxMpXmlOutNewsMessage (me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage)1 WxMpQrCodeTicket (me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket)1 WxMpTemplateData (me.chanjar.weixin.mp.bean.template.WxMpTemplateData)1 WxMpTemplateMessage (me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage)1