|
|
@ -2,10 +2,12 @@ package com.ccsens.wechatutil.wxofficial; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.util.*; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.ccsens.wechatutil.bean.dto.WxTemplateMessage; |
|
|
|
import com.ccsens.wechatutil.bean.po.WxBaseEntity; |
|
|
|
import com.ccsens.wechatutil.bean.vo.wxmini.Custom; |
|
|
|
import com.ccsens.wechatutil.util.WxCodeError; |
|
|
|
import com.ccsens.wechatutil.util.WxConstant; |
|
|
|
import com.ccsens.wechatutil.wxcommon.WxCommonUtil; |
|
|
@ -120,4 +122,39 @@ public class OfficialAccountMessageUtil { |
|
|
|
throw new BaseException(wxBaseEntity.getErrcode(), wxBaseEntity.getErrmsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static WxBaseEntity send(String openId, Custom.Type type, Object data, String appId, String secret){ |
|
|
|
log.info("发送客服消息:{},{},{}", openId, type, data); |
|
|
|
if (StrUtil.isEmpty(openId) || type == null || data == null) { |
|
|
|
throw new BaseException(CodeError.PARAM_ERROR); |
|
|
|
} |
|
|
|
String url = String.format(WxConstant.OFFICIAL_MESSAGE_SEND, WxCommonUtil.getAccessToken(appId, secret)); |
|
|
|
Custom.Message message = new Custom.Message(); |
|
|
|
message.setTouser(openId); |
|
|
|
message.setMsgtype(type.getType()); |
|
|
|
switch (type) { |
|
|
|
case IMAGE: |
|
|
|
message.setImage((Custom.Image) data); |
|
|
|
break; |
|
|
|
case TEXT: |
|
|
|
message.setText((Custom.Text) data); |
|
|
|
break; |
|
|
|
case LINK: |
|
|
|
message.setLink((Custom.Link) data); |
|
|
|
break; |
|
|
|
case MINI_PROGRAM_PAGE: |
|
|
|
message.setMiniprogrampage((Custom.MiniProgramPage) data); |
|
|
|
break; |
|
|
|
default: |
|
|
|
throw new BaseException(CodeError.PARAM_ERROR); |
|
|
|
} |
|
|
|
log.info("发送客服消息路径:{}, 请求:{}", url, message); |
|
|
|
String result = RestTemplateUtil.postBody(url, message); |
|
|
|
log.info("发送客服消息结果:{}", result); |
|
|
|
WxBaseEntity wxBaseEntity = JSONObject.parseObject(result, WxBaseEntity.class); |
|
|
|
return wxBaseEntity; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|