| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.hx.common.BaseController; |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.mp.util.CorpMpUtil; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.model.BaseEntity; |
| | |
| | | import com.platform.resultTool.PlatformCode; |
| | | import com.platform.resultTool.PlatformResult; |
| | | import com.platform.resultTool.SystemCode; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | @RequestMapping("/corp/message") |
| | | public class CorpMessageController extends BaseController { |
| | | private static Logger logger = LoggerFactory.getLogger(CorpMessageController.class.getName()); |
| | | /**营销助手企业应用密钥*/ |
| | | @Value("${marketing.assistant}") |
| | | private String marketingAssistant; |
| | | /**营销助手 appid*/ |
| | | @Value("${mar.appId}") |
| | | private String marAppid; |
| | | /**CRM appid*/ |
| | | @Value("${crm.appId}") |
| | | private String crmAppid; |
| | | /**企业消息发送,返回消息key*/ |
| | | private static final String RETURN_KEY = "errcode"; |
| | | /**企业消息发送,返回消息value*/ |
| | |
| | | if (applyParameter == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS, "corpId or mpId is error"); |
| | | } |
| | | //获取企业微信应用access_token |
| | | SysParameter sysParameter = null; |
| | | //CRM企业应用消息默认使用营销助手的应用信息 |
| | | if (crmAppid.equals(parameter.getMpId())) { |
| | | sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService, applyParameter.getCorpId(), marketingAssistant); |
| | | //小程序appid改为营销助手的 |
| | | JSONObject jsonData = JSONObject.parseObject(parameter.getSendData()); |
| | | if (jsonData.getString("appid").equals(crmAppid)) { |
| | | jsonData.put("appid", marAppid); |
| | | } |
| | | } else { |
| | | //正常获取对应的应用信息 |
| | | sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService, applyParameter.getCorpId(), AesUtil.aesDecryp(applyParameter.getApplySecretKey())); |
| | | } |
| | | |
| | | //通过应用数据获取企业微信应用access_token |
| | | SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService, applyParameter.getCorpId(), AesUtil.aesDecryp(applyParameter.getApplySecretKey())); |
| | | if (sysParameter == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "服务错误" + SystemCode.ERROR_GET_CORP_TOKEN); |
| | | } |
| | |
| | | if (StringUtils.isEmpty(sysParameter.getParamValue())) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "服务错误" + SystemCode.ERROR_GET_CORP_TOKEN); |
| | | } |
| | | |
| | | //发送数据 |
| | | logger.info("企业消息发送小程序appid为:" + parameter.getMpId() + "发送数据" + parameter.getSendData()); |
| | | net.sf.json.JSONObject returnData = CorpMpUtil.messageSend(sysParameter.getParamValue(), parameter.getSendData()); |
| | | logger.info("企业消息发送小程序appid为:" + parameter.getMpId() + "返回数据" + returnData); |
| | | logger.info("企业消息发送小程序appid为:" + parameter.getMpId() + "发送数据:" + parameter.getSendData()); |
| | | net.sf.json.JSONObject returnData = CorpMpUtil.messageSend(sysParameter.getParamValue(),parameter.getSendData()); |
| | | logger.info("企业消息发送小程序appid为:" + parameter.getMpId() + "返回数据:" + returnData); |
| | | //key不为0的时候发送不成功 |
| | | if (returnData.optInt(RETURN_KEY, DEFAULT_VALUE) != 0) { |
| | | logger.error("appId:" + parameter.getMpId() + "企业消息发送失败:" + returnData); |