Search in sources :

Example 1 with HttpResult

use of com.github.liuweijw.commons.pay.beans.HttpResult 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("获取微信签名数据失败!");
}
Also used : WxJsapiSignature(me.chanjar.weixin.common.bean.WxJsapiSignature) HttpResult(com.github.liuweijw.commons.pay.beans.HttpResult) WxErrorException(me.chanjar.weixin.common.error.WxErrorException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with HttpResult

use of com.github.liuweijw.commons.pay.beans.HttpResult in project fw-cloud-framework by liuweijw.

the class WxInfoController method getWechatInfoByOpenId.

@RequestMapping(value = "/{wechatId}/{openId}")
public HttpResult getWechatInfoByOpenId(@PathVariable("wechatId") String wechatId, @PathVariable("openId") String openId) {
    WechatInfo wechatInfo = wechatInfoService.findByWechatId(wechatId);
    if (null == wechatInfo) {
        log.error("公众号wechatId[" + wechatId + "]不存在");
        return new HttpResult().failure("公众号wechatId[" + wechatId + "]不存在");
    }
    AuthInfo authInfo = authInfoService.findByOpenIdAndWechatId(openId, wechatId);
    if (null == authInfo) {
        log.error("公众号openId[" + openId + "]不存在");
        return new HttpResult().failure("公众号openId[" + openId + "]不存在");
    }
    return new HttpResult().data(authInfo).success();
}
Also used : AuthInfo(com.github.liuweijw.business.wechat.domain.AuthInfo) WechatInfo(com.github.liuweijw.business.wechat.domain.WechatInfo) HttpResult(com.github.liuweijw.commons.pay.beans.HttpResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with HttpResult

use of com.github.liuweijw.commons.pay.beans.HttpResult 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("消息发送失败!");
}
Also used : WechatInfo(com.github.liuweijw.business.wechat.domain.WechatInfo) MsgBean(com.github.liuweijw.commons.pay.beans.MsgBean) HttpResult(com.github.liuweijw.commons.pay.beans.HttpResult) WxErrorException(me.chanjar.weixin.common.error.WxErrorException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with HttpResult

use of com.github.liuweijw.commons.pay.beans.HttpResult 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("消息发送失败!");
}
Also used : WechatInfo(com.github.liuweijw.business.wechat.domain.WechatInfo) MsgBean(com.github.liuweijw.commons.pay.beans.MsgBean) HttpResult(com.github.liuweijw.commons.pay.beans.HttpResult) WxTemplateEnum(com.github.liuweijw.commons.pay.enums.WxTemplateEnum) WxErrorException(me.chanjar.weixin.common.error.WxErrorException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HttpResult (com.github.liuweijw.commons.pay.beans.HttpResult)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 WechatInfo (com.github.liuweijw.business.wechat.domain.WechatInfo)3 WxErrorException (me.chanjar.weixin.common.error.WxErrorException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 MsgBean (com.github.liuweijw.commons.pay.beans.MsgBean)2 AuthInfo (com.github.liuweijw.business.wechat.domain.AuthInfo)1 WxTemplateEnum (com.github.liuweijw.commons.pay.enums.WxTemplateEnum)1 WxJsapiSignature (me.chanjar.weixin.common.bean.WxJsapiSignature)1