use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class WxJsdkController method wechatParam.
@RequestMapping(value = "/wechatParam")
@ResponseBody
public HttpResult wechatParam(@RequestParam("url") String url) {
long start = System.currentTimeMillis();
if (StringHelper.isBlank(url))
return new HttpResult().failure("url 参数验证失败!");
String jsdkUrl = WebUtils.buildURLDecoder(url);
try {
WxJsapiSignature jsapi = wxService.createJsapiSignature(WebUtils.buildURLDecoder(jsdkUrl));
log.info("[微信jsdk],请求{},获取耗时{}", jsdkUrl, (System.currentTimeMillis() - start));
return new HttpResult().data(jsapi).success();
} catch (WxErrorException e) {
e.printStackTrace();
}
return new HttpResult().failure("获取微信签名数据失败!");
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class WxAuthorizeController method openId.
// 如果用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE
@RequestMapping(value = "/openId", method = RequestMethod.GET)
public String openId(HttpServletRequest request, @RequestParam("code") String code, @RequestParam("state") String state, @RequestParam("from") Integer from, @RequestParam("wechatId") String wechatId, @RequestParam("t") Long t) {
long start = System.currentTimeMillis();
String openId = "";
try {
boolean isSopeBase = from.intValue() == 1;
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
openId = wxMpOAuth2AccessToken.getOpenId();
log.info("【wxauth.openId】:state|" + state);
// 采用异步方式拉取用户信息
// taskExecutor.execute(() -> {})
long mqStart = System.currentTimeMillis();
log.info("【wxauth.openId】发送MQ:" + mqStart);
WechatNotifyBean wechatNotifyBean = new WechatNotifyBean();
wechatNotifyBean.setSopeBase(isSopeBase);
wechatNotifyBean.setWechatId(wechatId);
wechatNotifyBean.setWxMpOAuth2AccessToken(wxMpOAuth2AccessToken);
rabbitTemplate.convertAndSend(MqQueueConstant.WECHAT_QUEUE, wechatNotifyBean);
log.info("【wxauth.openId】发送MQ耗时:" + (System.currentTimeMillis() - mqStart));
log.info("【wxauth.openId】:openId|" + openId);
} catch (WxErrorException ex) {
ex.printStackTrace();
log.info("【wxauth.openId】exception:" + ex.getError().getErrorMsg());
}
String returnUrl = "";
if (state.length() == 32 && !state.startsWith("http")) {
// key
UrlInfoBean urlInfoBean = urlInfoService.findFromCacheByUuid(state);
returnUrl = urlInfoBean.getUrl();
} else {
returnUrl = state;
}
String redirectUrl = RequestUtil.buildAppendURLParams(RequestUtil.buildURLParams(returnUrl, OPENID), OPENID + "=" + openId, "t=" + t);
log.info("【wxauth.openId】:redirect|" + redirectUrl);
long end = System.currentTimeMillis();
log.info("【wxauth.openId】耗时:" + (end - start));
log.info("【wxauth.authorize】请求从第三方应用到跳转授权开始[" + t + "],耗时:" + (end - t));
return "redirect:" + redirectUrl;
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class WxAuthorizeController method refreshToken.
@RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
public R<WxMpOAuth2AccessToken> refreshToken(HttpServletRequest request, @RequestParam("refreshToken") String refreshToken) {
if (StringHelper.isBlank(refreshToken))
return new R<WxMpOAuth2AccessToken>().failure("请求参数[refreshToken]不存在!");
log.info("【wxauth】:refreshToken|" + refreshToken);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken;
try {
wxMpOAuth2AccessToken = wxService.oauth2refreshAccessToken(refreshToken);
return new R<WxMpOAuth2AccessToken>().data(wxMpOAuth2AccessToken).success();
} catch (WxErrorException e) {
e.printStackTrace();
}
return new R<WxMpOAuth2AccessToken>().failure("微信refreshToken刷新失败!");
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class WxMessageController method sendWeixinCurrencyTemplateMessage.
@ResponseBody
@RequestMapping(value = "/sendCurrency/{wechatId}")
public HttpResult sendWeixinCurrencyTemplateMessage(@PathVariable("wechatId") String wechatId, @RequestParam("message") String message) {
if (StringHelper.isBlank(message))
return new HttpResult().failure("发送消息内容不能为空");
WechatInfo wechatInfo = wechatInfoService.findByWechatId(wechatId);
if (null == wechatInfo)
return new HttpResult().failure("公众号wechatId[" + wechatId + "]不存在");
log.info("公众号消息发送:|wechatId[{}]|reqKey[{}]|message[{}]", wechatId, wechatInfo.getReqKey(), message);
String decryptMessage = Crypt.getInstance().decrypt(message, wechatInfo.getReqKey());
if (StringHelper.isBlank(decryptMessage))
return new HttpResult().failure("发送消息内容签名不正确");
MsgBean msgBean = JSONObject.parseObject(decryptMessage, MsgBean.class);
if (null == msgBean)
return new HttpResult().failure("发送消息内容转换失败");
try {
boolean isOk = messageService.sendWeixinCurrencyTemplateMessage(msgBean);
if (isOk)
return new HttpResult().success("SUCCESS");
} catch (WxErrorException e) {
e.printStackTrace();
return new HttpResult().failure("发送消息失败[" + e.getMessage() + "]");
}
return new HttpResult().failure("消息发送失败!");
}
use of me.chanjar.weixin.common.error.WxErrorException in project fw-cloud-framework by liuweijw.
the class WxMessageController method sendWeixinTemplateMessage.
@ResponseBody
@Deprecated
@RequestMapping(value = "/send/{wechatId}")
public HttpResult sendWeixinTemplateMessage(@PathVariable("wechatId") String wechatId, @RequestParam("message") String message) {
if (StringHelper.isBlank(message))
return new HttpResult().failure("发送消息内容不能为空");
WechatInfo wechatInfo = wechatInfoService.findByWechatId(wechatId);
if (null == wechatInfo)
return new HttpResult().failure("公众号wechatId[" + wechatId + "]不存在");
log.info("公众号消息发送:|wechatId[{}]|reqKey[{}]|message[{}]", wechatId, wechatInfo.getReqKey(), message);
String decryptMessage = Crypt.getInstance().decrypt(message, wechatInfo.getReqKey());
if (StringHelper.isBlank(decryptMessage))
return new HttpResult().failure("发送消息内容签名不正确");
MsgBean msgBean = JSONObject.parseObject(decryptMessage, MsgBean.class);
if (null == msgBean)
return new HttpResult().failure("发送消息内容转换失败");
WxTemplateEnum wxTemplateEnum = WxTemplateEnum.of(msgBean.getTemplateId());
try {
boolean isOk = messageService.sendWeixinTemplateMessage(wxTemplateEnum, msgBean);
if (isOk)
return new HttpResult().success("SUCCESS");
} catch (WxErrorException e) {
e.printStackTrace();
return new HttpResult().failure("发送消息失败[" + e.getMessage() + "]");
}
return new HttpResult().failure("消息发送失败!");
}
Aggregations