package cn.huge.module.wechat.miniapp.handler;
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
|
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Map;
|
|
/**
|
* @title: 图片消息处理
|
* @description: 图片消息处理
|
* @company: hugeinfo
|
* @author: liyj
|
* @time: 2021/02/02
|
* @version: 1.0.0
|
**/
|
@Component
|
public class PicMaHandler extends AbstractHandler {
|
@Override
|
public void handle(WxMaMessage wxMaMessage, Map<String, Object> map, WxMaService wxMaService, WxSessionManager wxSessionManager) throws WxErrorException {
|
try {
|
WxMediaUploadResult uploadResult = wxMaService.getMediaService()
|
.uploadMedia("image", "png",
|
ClassLoader.getSystemResourceAsStream("tmp.png"));
|
wxMaService.getMsgService().sendKefuMsg(
|
WxMaKefuMessage
|
.newImageBuilder()
|
.mediaId(uploadResult.getMediaId())
|
.toUser(wxMaMessage.getFromUser())
|
.build());
|
} catch (WxErrorException e) {
|
logger.error(e.getMessage(), e);
|
}
|
}
|
}
|
/**
|
* -------------------_ooOoo_-------------------
|
* ------------------o8888888o------------------
|
* ------------------88" . "88------------------
|
* ------------------(| -_- |)------------------
|
* ------------------O\ = /O------------------
|
* ---------------____/`---'\____---------------
|
* -------------.' \\| |// `.-------------
|
* ------------/ \\||| : |||// \------------
|
* -----------/ _||||| -:- |||||- \-----------
|
* -----------| | \\\ - /// | |-----------
|
* -----------| \_| ''\---/'' | |-----------
|
* -----------\ .-\__ `-` ___/-. /-----------
|
* ---------___`. .' /--.--\ `. . __----------
|
* ------."" '< `.___\_<|>_/___.' >'"".-------
|
* -----| | : `- \`.;`\ _ /`;.`/ - ` : | |-----
|
* -----\ \ `-. \_ __\ /__ _/ .-` / /-----
|
* ======`-.____`-.___\_____/___.-`____.-'======
|
* -------------------`=---='
|
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
* ---------佛祖保佑---hugeinfo---永无BUG----------
|
*/
|