Search in sources :

Example 1 with WxMpQrCodeTicket

use of me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket in project weixin-java-tools by chanjarster.

the class WxMpQrCodeAPITest method testQrCodePicture.

public void testQrCodePicture() throws WxErrorException {
    WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1);
    File file = wxService.qrCodePicture(ticket);
    Assert.assertNotNull(file);
}
Also used : WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket) File(java.io.File)

Example 2 with WxMpQrCodeTicket

use of me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket in project weixin-java-tools by chanjarster.

the class WxMpQrCodeAPITest method testQrCodeCreateTmpTicket.

public void testQrCodeCreateTmpTicket() throws WxErrorException {
    WxMpQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null);
    Assert.assertNotNull(ticket.getUrl());
    Assert.assertNotNull(ticket.getTicket());
    Assert.assertTrue(ticket.getExpire_seconds() != -1);
}
Also used : WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket)

Example 3 with WxMpQrCodeTicket

use of me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket in project weixin-java-tools by chanjarster.

the class WxQrCodeTicketAdapter method deserialize.

public WxMpQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    WxMpQrCodeTicket ticket = new WxMpQrCodeTicket();
    JsonObject ticketJsonObject = json.getAsJsonObject();
    if (ticketJsonObject.get("ticket") != null && !ticketJsonObject.get("ticket").isJsonNull()) {
        ticket.setTicket(GsonHelper.getAsString(ticketJsonObject.get("ticket")));
    }
    if (ticketJsonObject.get("expire_seconds") != null && !ticketJsonObject.get("expire_seconds").isJsonNull()) {
        ticket.setExpire_seconds(GsonHelper.getAsPrimitiveInt(ticketJsonObject.get("expire_seconds")));
    }
    if (ticketJsonObject.get("url") != null && !ticketJsonObject.get("url").isJsonNull()) {
        ticket.setUrl(GsonHelper.getAsString(ticketJsonObject.get("url")));
    }
    return ticket;
}
Also used : WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket)

Example 4 with WxMpQrCodeTicket

use of me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket 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)

Example 5 with WxMpQrCodeTicket

use of me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket in project summer by foxsugar.

the class WechatAction method handleLoginAgent.

private void handleLoginAgent(WxMpUser wxMpUser, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Long agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(wxMpUser.getUnionId());
    if (agentId == null || agentId == 0) {
        // 不是代理
        try {
            wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(wxMpUser.getOpenId()).content("您还不是代理").build());
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        System.out.println(request.getRequestURL());
        response.getOutputStream().write("您不是代理".getBytes());
        return;
    }
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    if (agentBean != null) {
        if (agentBean.getOpenId() == null || agentBean.getQrTicket() == null || "".equals(agentBean.getQrTicket())) {
            agentBean.setImage(wxMpUser.getHeadImgUrl());
            agentBean.setOpenId(wxMpUser.getOpenId());
            // 根据unionId生成二维码 todo 加上游戏key
            WxMpQrCodeTicket ticket = null;
            try {
                ticket = wxMpService.getQrcodeService().qrCodeCreateLastTicket(serverConfig.getDomainMapKey() + "|" + wxMpUser.getUnionId());
            } catch (WxErrorException e) {
                e.printStackTrace();
            }
            agentBean.setQrTicket(ticket.getTicket());
            RedisManager.getAgentRedisService().updateAgentBean(agentBean);
        }
    }
    // 设置cookie
    Map<String, String> agent = getAgentByToken(request);
    if (agent == null) {
        setTokenCookie2Redis(wxMpUser, response, agentId);
    }
    String url = "http://" + serverConfig.getDomain() + "/agent/#/";
    response.sendRedirect(url);
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Aggregations

WxMpQrCodeTicket (me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket)6 AgentBean (com.code.server.constant.game.AgentBean)2 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)2 TextBuilder (com.code.server.login.wechat.builder.TextBuilder)1 File (java.io.File)1 Random (java.util.Random)1 WxMpXmlOutNewsMessage (me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage)1 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)1