MessageUtil.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.yihu.jw.care.util;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.yihu.jw.sms.service.TXYSmsService;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Component;
  10. /**
  11. * Created by Bing on 2021/5/29.
  12. */
  13. @Component
  14. public class MessageUtil {
  15. @Autowired
  16. private TXYSmsService txySmsService;
  17. private static Logger logger = LoggerFactory.getLogger(MessageUtil.class);
  18. public String sendTXYSJson(String templateCode,String mobile,String ...params)throws Exception{
  19. JSONObject sendObj = new JSONObject();
  20. sendObj.put("templateCode",templateCode);
  21. if (params.length>0){
  22. JSONArray paramArr =JSONArray.parseArray(JSON.toJSONString(params));
  23. sendObj.put("templateParamArr",paramArr);
  24. }else {
  25. JSONArray paramArr =new JSONArray();
  26. sendObj.put("templateParamArr",paramArr);
  27. }
  28. return txySmsService.sendMessageJson(mobile,sendObj);
  29. }
  30. }