use of me.chanjar.weixin.common.error.WxErrorException in project weixin-java-mp-demo-springboot by binarywang.
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());
// 获取微信用户基本信息
try {
WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
if (userWxInfo != null) {
// TODO 可以添加关注用户到本地数据库
}
} catch (WxErrorException e) {
if (e.getError().getErrorCode() == 48001) {
this.logger.info("该公众号没有获取用户信息权限!");
}
}
WxMpXmlOutMessage responseResult = null;
try {
responseResult = this.handleSpecial(wxMessage);
} 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;
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
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 可以添加关注用户到本地
}
WxMpXmlOutMessage responseResult = null;
try {
responseResult = handleSpecial(wxMessage);
} 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;
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class MessageServiceImpl method sendWeixinCurrencyTemplateMessage.
@Override
public boolean sendWeixinCurrencyTemplateMessage(MsgBean msgBean) throws WxErrorException {
if (null == msgBean)
throw new WxErrorException(WxError.builder().errorCode(500).errorMsg("消息内容不能为空").build());
if (StringHelper.isBlank(msgBean.getTemplateId()))
throw new WxErrorException(WxError.builder().errorCode(500).errorMsg("消息内容不能为空").build());
WxMpTemplateMessageBuilder templateMessage = WxMpTemplateMessage.builder();
templateMessage.templateId(msgBean.getTemplateId());
if (!StringHelper.isBlank(msgBean.getLinkUrl()))
templateMessage.url(msgBean.getLinkUrl());
List<WxMpTemplateData> data = new ArrayList<WxMpTemplateData>();
if (StringHelper.isNotBlank(msgBean.getFirst()))
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword1()))
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword2()))
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword3()))
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword4()))
data.add(new WxMpTemplateData("keyword4", msgBean.getKeyword4(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword5()))
data.add(new WxMpTemplateData("keyword5", msgBean.getKeyword5(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getRemark()))
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
templateMessage.data(data);
WxMpTemplateMessage toMessage = null;
List<String> toUsers = msgBean.getToUser();
if (null != toUsers && toUsers.size() > 0) {
for (String toUser : toUsers) {
templateMessage.toUser(toUser.trim());
toMessage = templateMessage.build();
log.info("|send template msg start|" + toMessage.toString());
String returnMsg = wxMpService.getTemplateMsgService().sendTemplateMsg(toMessage);
log.info("|send template msg end |" + returnMsg);
}
}
return true;
}
use of me.chanjar.weixin.common.error.WxErrorException in project weixin-java-mp-demo-springboot by binarywang.
the class WxRedirectController method greetUser.
@RequestMapping("/greet")
public String greetUser(@PathVariable String appid, @RequestParam String code, ModelMap map) {
if (!this.wxService.switchover(appid)) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}
try {
WxOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
WxOAuth2UserInfo user = wxService.getOAuth2Service().getUserInfo(accessToken, null);
map.put("user", user);
} catch (WxErrorException e) {
e.printStackTrace();
}
return "greet_user";
}
use of me.chanjar.weixin.common.error.WxErrorException in project weixin-java-mp-multi-demo by binarywang.
the class SubscribeHandler method handle.
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
BaseWxService weixinService = (BaseWxService) wxMpService;
// 获取微信用户基本信息
WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
if (userWxInfo != null) {
// TODO 可以添加关注用户到本地
}
WxMpXmlOutMessage responseResult = null;
try {
responseResult = handleSpecial(wxMessage);
} 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;
}
Aggregations