Search in sources :

Example 1 with GameAgentWx

use of com.code.server.db.model.GameAgentWx 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 2 with GameAgentWx

use of com.code.server.db.model.GameAgentWx in project summer by foxsugar.

the class WechatAction method becomeAgent.

@RequestMapping("/becomeAgent")
@ResponseBody
public AgentResponse becomeAgent(long userId) {
    AgentResponse agentResponse = new AgentResponse();
    AgentBean agentBean = agentRedisService.getAgentBean(userId);
    // todo 之前是代理
    if (agentBean != null) {
        return new AgentResponse().setCode(ErrorCode.ALREADY_AGENT);
    }
    // 之前不是代理
    GameAgent gameAgent = new GameAgent();
    gameAgent.setId(userId);
    // 推荐
    String unionId = userService.getUserDao().getOpenIdById(userId);
    Recommend recommend = recommendService.getRecommendDao().findOne(unionId);
    GameAgentWx gameAgentWx = gameAgentWxService.getGameAgentWxDao().findOne(unionId);
    if (gameAgentWx == null) {
        return new AgentResponse().setCode(ErrorCode.NOT_WX_USER);
    }
    String openId = gameAgentWx.getOpenId();
    gameAgent.setOpenId(openId);
    gameAgent.setId(userId);
    gameAgent.setUnionId(unionId);
    // 有推荐
    if (recommend != null) {
        long parentId = recommend.getAgentId();
        AgentBean parent = agentRedisService.getAgentBean(parentId);
        // 上级代理存在
        if (parent != null) {
            // 和上级的partner是同一个
            gameAgent.setPartnerId(parent.getPartnerId());
            gameAgent.setParentId(parentId);
            gameAgent.setIsPartner(0);
            // 上级代理加一个child
            parent.getChildList().add(userId);
        }
    }
    // 保存到数据库
    gameAgentService.getGameAgentDao().save(gameAgent);
    agentBean = AgentService.gameAgent2AgentBean(gameAgent);
    // 保存的reids
    agentRedisService.setAgent2Redis(agentBean);
    return agentResponse;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) GameAgent(com.code.server.db.model.GameAgent) GameAgentWx(com.code.server.db.model.GameAgentWx) Recommend(com.code.server.db.model.Recommend) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

GameAgentWx (com.code.server.db.model.GameAgentWx)2 AgentBean (com.code.server.constant.game.AgentBean)1 GameAgent (com.code.server.db.model.GameAgent)1 Recommend (com.code.server.db.model.Recommend)1 TextBuilder (com.code.server.login.wechat.builder.TextBuilder)1 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)1 WxMpXmlOutMessage (me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage)1 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1