2c742afacff92f19e917d00837765c1d840dd80b.svn-base 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. package com.chinacreator.process.job;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.chinacreator.common.exception.BusinessException;
  5. import com.chinacreator.common.util.DESUtil;
  6. import com.chinacreator.common.util.MD5;
  7. import com.chinacreator.common.util.URLUtil;
  8. import com.chinacreator.process.bean.AreaInfo;
  9. import com.chinacreator.process.dao.*;
  10. import com.chinacreator.process.service.CShandleSmsTempService;
  11. import com.chinacreator.process.util.DesUtil;
  12. import com.chinacreator.process.util.HttpInvoke;
  13. import com.chinacreator.process.util.JsonUtil;
  14. import com.chinacreator.process.util.SHAUtil;
  15. import com.chinacreator.process.util.WriteLogUtil;
  16. import com.chinacreator.video.queue.MessageService;
  17. import com.chinacreator.video.queue.bean.MessagePipe;
  18. import org.apache.commons.lang.StringUtils;
  19. import org.apache.commons.lang.time.DateFormatUtils;
  20. import org.apache.log4j.Logger;
  21. import org.quartz.DisallowConcurrentExecution;
  22. import org.quartz.PersistJobDataAfterExecution;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import java.net.URLEncoder;
  25. import java.sql.SQLException;
  26. import java.text.ParseException;
  27. import java.text.SimpleDateFormat;
  28. import java.util.*;
  29. /**
  30. * 使用短信模板发业务订购退订短信
  31. * @author xu.zhou
  32. * @date 20220415
  33. */
  34. @PersistJobDataAfterExecution
  35. @DisallowConcurrentExecution
  36. public class CShandleSmsTempJob {
  37. private Logger logger = Logger.getLogger("cssms");
  38. //private Logger log = Logger.getLogger(CShandleSmsConfJob.class);
  39. @Autowired
  40. private MqSmsTempConfDao mqSmsConfDao; // = new MqSmsTempConfDao();
  41. @Autowired
  42. private DictionaryDao dictionaryDao; // = new DictionaryDao();
  43. @Autowired
  44. private CallerAreacodeDao callerAreacodeDao; // = new CallerAreacodeDao();
  45. @Autowired
  46. private CommonDao commonDao; // = new CommonDao();
  47. @Autowired
  48. private MessageService messageService;
  49. @Autowired
  50. private CShandleSmsTempService cShandleSmsTempService;
  51. private String getMessageParam(String p){
  52. if(StringUtils.isEmpty(p)){
  53. return "";
  54. }else{
  55. return p;
  56. }
  57. }
  58. /**
  59. * 为空时返回一个空格,短信接口传空串会报错
  60. * @param p
  61. * @return
  62. */
  63. private String fullNullStr(String p){
  64. if(StringUtils.isEmpty(p)){
  65. return " ";
  66. }else{
  67. return p;
  68. }
  69. }
  70. private MessagePipe getTestMessagePipe(){
  71. MessagePipe mp = new MessagePipe();
  72. mp.addBody("userid", "13107418055");
  73. mp.addBody("cpid", "youtu");
  74. mp.addBody("spid", "1167");
  75. mp.addBody("busiType", "cancel_succ");
  76. mp.addBody("channel", "boyuan");
  77. mp.addBody("subchannel", "1234567890");
  78. mp.addBody("province", "湖南");
  79. return mp;
  80. }
  81. public void doProcess() throws Exception {
  82. WriteLogUtil.writeLong("业务短信CShandleSmsTempJob开始执行", logger, "CShandleSmsTempJob");//("业务短信CShandleSmsTempJob开始执行");
  83. //配置的发送开关为启用
  84. if ("0".equals(dictionaryDao.getValue("recivemq"))) {
  85. //logger.info("获取队列数据开始"+new Date().toLocaleString());
  86. List<MessagePipe> list = messageService.reciveBatchMessage("cssms", 500);
  87. //logger.info("获取队列数据结束"+new Date().toLocaleString());
  88. //List<MessagePipe> list = new ArrayList<MessagePipe>();
  89. //list.add(getTestMessagePipe());
  90. if (list != null && list.size() > 0) {
  91. logger.info("CShandleSmsTempJob短信需要发送的条数:" + list.size());
  92. HashMap logmap = new HashMap();
  93. for (MessagePipe messagePipe : list) {
  94. String resultcode = "";
  95. String errorinfo = "";
  96. logmap = new HashMap();
  97. logmap.put("job", "CShandleSmsTempJob");
  98. logmap.put("mqbody", messagePipe.getBody());
  99. String spid = (String) messagePipe.getBody().get("spid");
  100. String cpid = messagePipe.getBody().get("cpid") + "";
  101. String userid = (String) messagePipe.getBody().get("userid");
  102. String times = (String) messagePipe.getBody().get("times");
  103. String style = (String) messagePipe.getBody().get("style");
  104. String busiType = getMessageParam((String)messagePipe.getBody().get("busiType")); //业务类型
  105. String channel = getMessageParam((String)messagePipe.getBody().get("channel")); //渠道
  106. String subchannel = getMessageParam((String)messagePipe.getBody().get("subchannel"));//子渠道
  107. String province = getMessageParam((String)messagePipe.getBody().get("province")); //省份
  108. String param1 = getMessageParam((String)messagePipe.getBody().get("param1"));
  109. String param2 = getMessageParam((String)messagePipe.getBody().get("param2"));
  110. String param3 = getMessageParam((String)messagePipe.getBody().get("param3"));
  111. String staffid = getMessageParam((String)messagePipe.getBody().get("staffid"));//员工工号
  112. try {
  113. //对于没传省份的获取省份
  114. if (StringUtils.isEmpty(province)||"null".equals(province)){
  115. AreaInfo areaInfo = callerAreacodeDao.findByCallerhead(userid.substring(0, 7));
  116. province = areaInfo.getProvince();
  117. logmap.put("province",province);
  118. }
  119. //业务类型不能为空
  120. if(StringUtils.isEmpty(busiType)){
  121. throw new BusinessException("9007","参数busiType为空");
  122. }
  123. /**
  124. //短信表配置
  125. HashMap mqsmsconf = null;
  126. List<HashMap> confList = mqSmsConfDao.getConfListBySpid(spid, busiType);
  127. if(confList == null || confList.size() == 0){
  128. throw new BusinessException("9001","sp产品短信发送无配置");
  129. }
  130. **/
  131. //logmap.put("confList", confList);
  132. //配置表的业务类型
  133. //String confbusitype = "";
  134. /***
  135. * 验证配置数据
  136. * busitype必须相同
  137. * 获取配置信息排序:
  138. * 配置字段:CHANNEL, SUBCHANNEL, PROVCINCE, STARTTIME, ENDTIME
  139. *
  140. * 1. CHANNEL,SUBCHANNEL,PROVINCE,STARTTIME,ENDTIME有配置
  141. * 2. CHANNEL,SUBCHANNEL,PROVINCE有配置,但STARTTIME,ENDTIME无配置
  142. * 3. CHANNEL,PROVINCE,STARTTIME,ENDTIME有配置,SUBCHANNEL无配置
  143. * 4. CHANNEL,PROVINCE有配置,SUBCHANNEL,STARTTIME,ENDTIME无配置
  144. * 5. PROVINCE,STARTTIME,ENDTIME有配置,CHANNEL,SUBCHANNEL无配置
  145. * 6. PROVINCE有配置,CHANNEL,SUBCHANNEL,STARTTIME,ENDTIME无配置
  146. * 7. CHANNEL,SUBCHANNEL,STARTTIME,ENDTIME有配置,PROVINCE无配置
  147. * 8. CHANNEL,SUBCHANNEL有配置,,PROVINCE,STARTTIME,ENDTIME无配置
  148. * 9. CHANNEL,STARTTIME,ENDTIME有配置,PROVINCE,SUBCHANNEL无配置
  149. * 10. CHANNEL有配置,,PROVINCE,SUBCHANNEL,STARTTIME,ENDTIME无配置
  150. * 11. STARTTIME,ENDTIME有配置,CHANNEL,SUBCHANNEL,PROVINCE无配置
  151. * 12. 全都无配置
  152. */
  153. HashMap<String, String> bodyparams = new HashMap<String, String>();
  154. bodyparams.put("busiType", busiType); //业务类型
  155. bodyparams.put("channel", channel); //渠道
  156. bodyparams.put("subchannel", subchannel);//子渠道
  157. bodyparams.put("province", province); //省份
  158. bodyparams.put("param1", param1); //附加参数1
  159. bodyparams.put("param2", param2); //附加参数2
  160. bodyparams.put("param3", param3); //附加参数3
  161. bodyparams.put("userid", userid); //手机号码
  162. bodyparams.put("spid", spid); //SPID
  163. //获取配置信息
  164. //mqsmsconf = cShandleSmsTempService.getMqSmsConfBySort(confList, bodyparams, logmap);
  165. /**
  166. * 1. CHANNEL,SUBCHANNEL,PROVINCE,STARTTIME,ENDTIME有配置
  167. */
  168. /***
  169. if(mqsmsconf == null){
  170. for(HashMap tmphm : confList){
  171. confbusitype = tmphm.get("BUSITYPE").toString();
  172. //busiType完全相同,且有CHANNEL、SUBCHANNEL、PROVINCE都有配置
  173. if(confbusitype.equals(busiType)
  174. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  175. && tmphm.get("SUBCHANNEL") != null && tmphm.get("SUBCHANNEL").equals(subchannel)
  176. && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  177. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )){
  178. //验证当前是否在配置的发送时间内
  179. if(valisendtime(tmphm)){
  180. mqsmsconf = tmphm;
  181. //跳出循环
  182. break;
  183. }else{
  184. logmap.put("valitime", "当前时间不在配置范围内");
  185. }
  186. }
  187. }
  188. }
  189. ***/
  190. /**
  191. * 2. CHANNEL,SUBCHANNEL,PROVINCE有配置,但STARTTIME,ENDTIME无配置
  192. */
  193. /***
  194. if(mqsmsconf == null){
  195. for(HashMap tmphm : confList){
  196. confbusitype = tmphm.get("BUSITYPE").toString();
  197. //busiType完全相同,且有CHANNEL、SUBCHANNEL、PROVINCE都有配置
  198. if(confbusitype.equals(busiType)
  199. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  200. && tmphm.get("SUBCHANNEL") != null && tmphm.get("SUBCHANNEL").equals(subchannel)
  201. && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  202. && tmphm.get("STARTTIME") == null
  203. && tmphm.get("ENDTIME") == null ){
  204. //验证当前是否在配置的发送时间内
  205. if(valisendtime(tmphm)){
  206. mqsmsconf = tmphm;
  207. //跳出循环
  208. break;
  209. }else{
  210. logmap.put("valitime", "当前时间不在配置范围内");
  211. }
  212. }
  213. }
  214. }
  215. ***/
  216. /*
  217. * 3. CHANNEL,PROVINCE,STARTTIME,ENDTIME有配置,SUBCHANNEL无配置
  218. */
  219. /***
  220. if(mqsmsconf == null){
  221. for(HashMap tmphm : confList){
  222. confbusitype = tmphm.get("BUSITYPE").toString();
  223. //busiType完全相同,且有CHANNEL、SUBCHANNEL、PROVINCE都有配置
  224. if(confbusitype.equals(busiType)
  225. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  226. && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  227. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )
  228. && tmphm.get("SUBCHANNEL") == null
  229. ){
  230. //验证当前是否在配置的发送时间内
  231. if(valisendtime(tmphm)){
  232. mqsmsconf = tmphm;
  233. //跳出循环
  234. break;
  235. }else{
  236. logmap.put("valitime", "当前时间不在配置范围内");
  237. }
  238. }
  239. }
  240. }
  241. ***/
  242. /**
  243. * 4. CHANNEL,PROVINCE有配置,SUBCHANNEL,STARTTIME,ENDTIME无配置
  244. */
  245. /***
  246. if(mqsmsconf == null){
  247. for(HashMap tmphm : confList){
  248. confbusitype = tmphm.get("BUSITYPE").toString();
  249. //busiType完全相同,且有CHANNEL、SUBCHANNEL、PROVINCE都有配置
  250. if(confbusitype.equals(busiType)
  251. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  252. && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  253. && tmphm.get("SUBCHANNEL") == null
  254. && tmphm.get("STARTTIME") == null
  255. && tmphm.get("ENDTIME") == null
  256. ){
  257. //验证当前是否在配置的发送时间内
  258. if(valisendtime(tmphm)){
  259. mqsmsconf = tmphm;
  260. //跳出循环
  261. break;
  262. }else{
  263. logmap.put("valitime", "当前时间不在配置范围内");
  264. }
  265. }
  266. }
  267. }
  268. ***/
  269. /**
  270. * 5. PROVINCE,STARTTIME,ENDTIME有配置,CHANNEL,SUBCHANNEL无配置
  271. */
  272. /***
  273. if(mqsmsconf == null){
  274. for(HashMap tmphm : confList){
  275. confbusitype = tmphm.get("BUSITYPE").toString();
  276. //busiType完全相同,且有PROVINCE配置,PROVINCE配置优先
  277. if(confbusitype.equals(busiType) && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  278. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )
  279. && tmphm.get("CHANNEL") == null
  280. && tmphm.get("SUBCHANNEL") == null){
  281. //验证当前是否在配置的发送时间内
  282. if(valisendtime(tmphm)){
  283. mqsmsconf = tmphm;
  284. //跳出循环
  285. break;
  286. }else{
  287. logmap.put("valitime", "当前时间不在配置范围内");
  288. }
  289. }
  290. }
  291. }
  292. ***/
  293. /**
  294. * 6. PROVINCE有配置,CHANNEL,SUBCHANNEL,STARTTIME,ENDTIME无配置
  295. */
  296. /***
  297. if(mqsmsconf == null){
  298. for(HashMap tmphm : confList){
  299. confbusitype = tmphm.get("BUSITYPE").toString();
  300. //busiType完全相同,且有PROVINCE配置,PROVINCE配置优先
  301. if(confbusitype.equals(busiType) && tmphm.get("PROVINCE") != null && tmphm.get("PROVINCE").equals(province)
  302. && tmphm.get("CHANNEL") == null
  303. && tmphm.get("SUBCHANNEL") == null
  304. && tmphm.get("STARTTIME") == null
  305. && tmphm.get("ENDTIME") == null ){
  306. //验证当前是否在配置的发送时间内
  307. if(valisendtime(tmphm)){
  308. mqsmsconf = tmphm;
  309. //跳出循环
  310. break;
  311. }else{
  312. logmap.put("valitime", "当前时间不在配置范围内");
  313. }
  314. }
  315. }
  316. }
  317. ***/
  318. /**
  319. * 7. CHANNEL,SUBCHANNEL,STARTTIME,ENDTIME有配置,PROVINCE无配置
  320. */
  321. /***
  322. if(mqsmsconf == null){
  323. for(HashMap tmphm : confList){
  324. confbusitype = tmphm.get("BUSITYPE").toString();
  325. //busiType完全相同,且有CHANNEL和SUBCHANNEL配置,SUBCHANNEL配置优先
  326. if(confbusitype.equals(busiType)
  327. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  328. && tmphm.get("SUBCHANNEL") != null && tmphm.get("SUBCHANNEL").equals(subchannel)
  329. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )
  330. && tmphm.get("PROVINCE") == null
  331. ){
  332. //验证当前是否在配置的发送时间内
  333. if(valisendtime(tmphm)){
  334. mqsmsconf = tmphm;
  335. //跳出循环
  336. break;
  337. }else{
  338. logmap.put("valitime", "当前时间不在配置范围内");
  339. }
  340. }
  341. }
  342. }
  343. ***/
  344. /**
  345. * 8. CHANNEL,SUBCHANNEL有配置,,PROVINCE,STARTTIME,ENDTIME无配置
  346. */
  347. /***
  348. if(mqsmsconf == null){
  349. for(HashMap tmphm : confList){
  350. confbusitype = tmphm.get("BUSITYPE").toString();
  351. //busiType完全相同,且有CHANNEL和SUBCHANNEL配置,SUBCHANNEL配置优先
  352. if(confbusitype.equals(busiType)
  353. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  354. && tmphm.get("SUBCHANNEL") != null && tmphm.get("SUBCHANNEL").equals(subchannel)
  355. && tmphm.get("PROVINCE") == null
  356. && tmphm.get("STARTTIME") == null
  357. && tmphm.get("ENDTIME") == null
  358. ){
  359. //验证当前是否在配置的发送时间内
  360. if(valisendtime(tmphm)){
  361. mqsmsconf = tmphm;
  362. //跳出循环
  363. break;
  364. }else{
  365. logmap.put("valitime", "当前时间不在配置范围内");
  366. }
  367. }
  368. }
  369. }
  370. ***/
  371. /**
  372. * 9. CHANNEL,STARTTIME,ENDTIME有配置,PROVINCE,SUBCHANNEL无配置
  373. */
  374. /***
  375. if(mqsmsconf == null){
  376. for(HashMap tmphm : confList){
  377. confbusitype = tmphm.get("BUSITYPE").toString();
  378. //busiType完全相同,且有CHANNEL配置,CHANNEL配置优先
  379. if(confbusitype.equals(busiType)
  380. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  381. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )
  382. && tmphm.get("PROVINCE") == null
  383. && tmphm.get("SUBCHANNEL") == null){
  384. //验证当前是否在配置的发送时间内
  385. if(valisendtime(tmphm)){
  386. mqsmsconf = tmphm;
  387. //跳出循环
  388. break;
  389. }else{
  390. logmap.put("valitime", "当前时间不在配置范围内");
  391. }
  392. }
  393. }
  394. }
  395. ***/
  396. /**
  397. * 10. CHANNEL有配置,,PROVINCE,SUBCHANNEL,STARTTIME,ENDTIME无配置
  398. */
  399. /***
  400. if(mqsmsconf == null){
  401. for(HashMap tmphm : confList){
  402. confbusitype = tmphm.get("BUSITYPE").toString();
  403. //busiType完全相同,且有CHANNEL配置,CHANNEL配置优先
  404. if(confbusitype.equals(busiType)
  405. && tmphm.get("CHANNEL") != null && tmphm.get("CHANNEL").equals(channel)
  406. && tmphm.get("PROVINCE") == null
  407. && tmphm.get("SUBCHANNEL") == null
  408. && tmphm.get("STARTTIME") == null
  409. && tmphm.get("ENDTIME") == null
  410. ){
  411. //验证当前是否在配置的发送时间内
  412. if(valisendtime(tmphm)){
  413. mqsmsconf = tmphm;
  414. //跳出循环
  415. break;
  416. }else{
  417. logmap.put("valitime", "当前时间不在配置范围内");
  418. }
  419. }
  420. }
  421. }
  422. ***/
  423. /**
  424. * 11. STARTTIME,ENDTIME有配置,CHANNEL,SUBCHANNEL,PROVINCE无配置
  425. */
  426. /***
  427. if(mqsmsconf == null){
  428. for(HashMap tmphm : confList){
  429. confbusitype = tmphm.get("BUSITYPE").toString();
  430. //busiType完全相同
  431. if(confbusitype.equals(busiType)
  432. && ( tmphm.get("STARTTIME") != null || tmphm.get("ENDTIME") != null )
  433. && tmphm.get("PROVINCE") == null
  434. && tmphm.get("SUBCHANNEL") == null
  435. && tmphm.get("CHANNEL") == null
  436. ){
  437. //验证当前是否在配置的发送时间内
  438. if(valisendtime(tmphm)){
  439. mqsmsconf = tmphm;
  440. //跳出循环
  441. break;
  442. }else{
  443. logmap.put("valitime", "当前时间不在配置范围内");
  444. }
  445. }
  446. }
  447. }
  448. ***/
  449. /**
  450. * 12. 全都无配置
  451. */
  452. /***
  453. if(mqsmsconf == null){
  454. for(HashMap tmphm : confList){
  455. confbusitype = tmphm.get("BUSITYPE").toString();
  456. //busiType完全相同
  457. if(confbusitype.equals(busiType)
  458. && tmphm.get("PROVINCE") == null
  459. && tmphm.get("SUBCHANNEL") == null
  460. && tmphm.get("CHANNEL") == null
  461. && tmphm.get("STARTTIME") == null
  462. && tmphm.get("ENDTIME") == null
  463. ){
  464. //验证当前是否在配置的发送时间内
  465. if(valisendtime(tmphm)){
  466. mqsmsconf = tmphm;
  467. //跳出循环
  468. break;
  469. }else{
  470. logmap.put("valitime", "当前时间不在配置范围内");
  471. }
  472. }
  473. }
  474. }
  475. ***/
  476. //验证业务类型完全相同的数据,优先级最低,默认先第一条,按时间排序
  477. /**
  478. if(mqsmsconf == null){
  479. for(HashMap tmphm : confList){
  480. confbusitype = tmphm.get("BUSITYPE").toString();
  481. //busiType完全相同
  482. if(confbusitype.equals(busiType)){
  483. //验证当前是否在配置的发送时间内
  484. if(valisendtime(tmphm)){
  485. mqsmsconf = tmphm;
  486. //跳出循环
  487. break;
  488. }else{
  489. logmap.put("valitime", "当前时间不在配置范围内");
  490. }
  491. }
  492. }
  493. }
  494. **/
  495. /**
  496. if(mqsmsconf == null || mqsmsconf.size() == 0){
  497. throw new BusinessException("9003","sp产品无对应业务短信配置");
  498. }
  499. //移除时间验证失败标记
  500. logmap.remove("valitime");
  501. //短信模板ID
  502. String smstempid = (String)mqsmsconf.get("SMSTEMPID");
  503. if(StringUtils.isEmpty(smstempid)){
  504. throw new BusinessException("9006","无模板ID配置");
  505. }
  506. logmap.put("mqsmsconf", mqsmsconf);
  507. **/
  508. /*****************发送时间验证开始*****************
  509. //发送时间验证
  510. String sendstarttime = (String)mqsmsconf.get("STARTTIME");
  511. String sendendtime = (String)mqsmsconf.get("ENDTIME");
  512. String currtime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  513. logmap.put("currtime", currtime);
  514. //有配置短信发送开始时间,但当前时间小于开始时间
  515. if(!StringUtils.isEmpty(sendstarttime) && Long.parseLong(currtime) < Long.parseLong(sendstarttime)){
  516. throw new BusinessException("9004","未到短信发送开始时间");
  517. }
  518. //有配置短信发送结束时间,但当前时间大于结束时间
  519. if(!StringUtils.isEmpty(sendendtime) && Long.parseLong(currtime) > Long.parseLong(sendendtime)){
  520. throw new BusinessException("9005","已过短信发送结束时间");
  521. }
  522. *****************发送时间验证结束*****************/
  523. /***************************模板参数设置开始***************************/
  524. //获取调短信接口的模板参数
  525. //HashMap<String, String> invokeparams = cShandleSmsTempService.getInvokeparams(mqsmsconf, bodyparams,logmap);
  526. /****
  527. //短信参数
  528. String [] smsparamsArray = mqsmsconf.get("PARAMS").toString().split("\\|");
  529. //短信参数映射
  530. String [] smsparamsmappArray = mqsmsconf.get("PARAMSMAPP").toString().split("\\|");
  531. //获取mq表的参数映射
  532. String mqparamsmapp = (String)mqsmsconf.get("MQPARAMSMAPP");
  533. //有个性化配置映射,优先级高于TB_SMSTEMP_CONF的MQPARAMSMAPP配置
  534. if(!StringUtils.isEmpty(mqparamsmapp)){
  535. smsparamsmappArray = mqparamsmapp.split("\\|");
  536. }
  537. //调接口模板参数
  538. HashMap<String, String> invokeparams = new HashMap<String, String>();
  539. String param = "";
  540. //组建调接口模板参数
  541. for(int p = 0; p < smsparamsArray.length; p++){
  542. param = smsparamsArray[p];
  543. if("param1".equals(param)){ //自定义预留参数1
  544. if(!param.equals(smsparamsmappArray[p])){
  545. invokeparams.put(param, smsparamsmappArray[p]);
  546. }else{
  547. invokeparams.put(param, fullNullStr(param1));
  548. }
  549. }else if("param2".equals(param)){//自定义预留参数2
  550. if(!param.equals(smsparamsmappArray[p])){
  551. invokeparams.put(param, smsparamsmappArray[p]);
  552. }else{
  553. invokeparams.put(param, fullNullStr(param2));
  554. }
  555. }else if("param3".equals(param)){//自定义预留参数3
  556. if(!param.equals(smsparamsmappArray[p])){
  557. invokeparams.put(param, smsparamsmappArray[p]);
  558. }else{
  559. invokeparams.put(param, fullNullStr(param3));
  560. }
  561. }else if("oriuserid".equals(param)){//原始手机号码
  562. invokeparams.put(param, userid);
  563. }else if("userid".equals(param)){
  564. //模糊化
  565. String fulluserid = userid.substring(0, 3)+"****"+userid.substring(7);
  566. invokeparams.put(param, fulluserid);
  567. }else if("mm".equals(param)){
  568. invokeparams.put(param, DateFormatUtils.format(new Date(), "MM"));
  569. }else if("dd".equals(param)){
  570. invokeparams.put(param, DateFormatUtils.format(new Date(), "dd"));
  571. }else if("spname".equals(param)){
  572. if(!param.equals(smsparamsmappArray[p])){
  573. invokeparams.put(param, smsparamsmappArray[p]);
  574. }else{
  575. invokeparams.put(param, (String)mqsmsconf.get("SPNAME"));
  576. }
  577. }else if("price".equals(param)){
  578. if(!param.equals(smsparamsmappArray[p])){
  579. invokeparams.put(param, smsparamsmappArray[p]);
  580. }else{
  581. invokeparams.put(param, (String)mqsmsconf.get("PRICE"));
  582. }
  583. }else if("cpname".equals(param)){
  584. if(!param.equals(smsparamsmappArray[p])){
  585. invokeparams.put(param, smsparamsmappArray[p]);
  586. }else{
  587. invokeparams.put(param, fullNullStr((String)mqsmsconf.get("SMSCPNAME")));
  588. }
  589. }else if("maxflow".equals(param)){
  590. if(!param.equals(smsparamsmappArray[p])){
  591. invokeparams.put(param, smsparamsmappArray[p]);
  592. }else{
  593. String maxflow = (String)mqsmsconf.get("MAXFLOW");
  594. if(!StringUtils.isEmpty(maxflow)){
  595. try {
  596. //转为G
  597. maxflow = (Integer.parseInt(maxflow)/1024)+"";
  598. } catch (Exception e) {
  599. e.printStackTrace();
  600. }
  601. }
  602. invokeparams.put(param, maxflow);
  603. }
  604. }else if(param.indexOf("expdate") != -1){
  605. if(!param.equals(smsparamsmappArray[p])){
  606. invokeparams.put(param, smsparamsmappArray[p]);
  607. }else{
  608. if(param.split("-").length == 2){
  609. //计算当天时间加上多少天,含多少天,显示开始时间和结束时间
  610. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  611. //当前时间加多少天
  612. int day = Integer.parseInt(param.split("-")[1]);
  613. day = day - 1; //当天也包含
  614. Date currdate = new Date();
  615. Calendar ca = Calendar.getInstance();
  616. ca.setTime(currdate);
  617. ca.add(Calendar.DATE, day);
  618. Date enddate = ca.getTime();
  619. invokeparams.put(param, sdf.format(new Date())+"-"+sdf.format(enddate));
  620. }else{
  621. invokeparams.put(param, DateFormatUtils.format(new Date(), "yyyyMMdd"));
  622. }
  623. }
  624. }else if("mappid".equals(param)){//映射ID
  625. if(!param.equals(smsparamsmappArray[p])){
  626. invokeparams.put(param, smsparamsmappArray[p]);
  627. }else{
  628. //调接口获取mappid
  629. String mappid = getMappidByUserid(userid, logmap);
  630. //如果为空,赋值为空格
  631. if(StringUtils.isEmpty(mappid)) {
  632. mappid = " ";
  633. }
  634. invokeparams.put(param, mappid);
  635. }
  636. }else{//按配置的信息设置
  637. invokeparams.put(param, fullNullStr(smsparamsmappArray[p]));
  638. }
  639. }
  640. ****/
  641. /***************************模板参数设置结束***************************/
  642. /**
  643. logmap.put("invokeparams", JsonUtil.objectToJson(invokeparams));
  644. //调接口参数不为空
  645. if(invokeparams != null && invokeparams.size()>0){
  646. //调接口发送短信
  647. logmap.put("smstype", "sms117");
  648. String sendres = cShandleSmsTempService.sendSMS(userid,smstempid,JsonUtil.objectToJson(invokeparams),"sms117", logmap);
  649. logmap.put("sendres", sendres);
  650. //华胜数据查询小时问隔
  651. String huashengpushhour = dictionaryDao.getValue("huashengpushhour");
  652. //更新华胜推送表数据
  653. boolean updhuasheng = mqSmsConfDao.updHuaShengWaitInfo(userid, spid, busiType, huashengpushhour);
  654. logmap.put("updhuasheng", updhuasheng);
  655. }
  656. **/
  657. //第一条短信
  658. cShandleSmsTempService.sendFirSms(bodyparams,logmap);
  659. //第二条短信
  660. cShandleSmsTempService.sendSecSms(bodyparams,logmap);
  661. //下发退订成功营销短信
  662. cShandleSmsTempService.sendCancelYxSms(bodyparams,logmap);
  663. resultcode = "0";
  664. errorinfo = "ok";
  665. } catch (Exception e) {
  666. if (e instanceof BusinessException) {
  667. resultcode = ((BusinessException) e).getCode();
  668. errorinfo = ((BusinessException) e).getMessage();
  669. //非过期,无配置,走原流程
  670. /**
  671. if(logmap.get("valitime") == null && ("9001".equals(resultcode) || "9003".equals(resultcode) || "9006".equals(resultcode))){
  672. String mqres = inserMqCssms2(messagePipe);
  673. logmap.put("mqres", mqres);
  674. }
  675. **/
  676. }else{
  677. e.printStackTrace();
  678. resultcode = "8000";
  679. errorinfo = e.getMessage();
  680. }
  681. } finally {
  682. logmap.put("resultcode", resultcode);
  683. logmap.put("errorinfo", errorinfo);
  684. //写日志
  685. logger.info(JsonUtil.objectToJson(logmap));
  686. }
  687. }
  688. }
  689. }
  690. }
  691. /**
  692. * 判断当前时间是否在配置的时间范围内,如果有配置
  693. * @param mqsmsconf
  694. * @return true 未限制,false被限制
  695. */
  696. /**
  697. private boolean valisendtime(HashMap mqsmsconf){
  698. //默认为成功
  699. boolean res = true;
  700. //发送时间验证
  701. String sendstarttime = (String)mqsmsconf.get("STARTTIME");
  702. String sendendtime = (String)mqsmsconf.get("ENDTIME");
  703. String currtime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  704. //有配置短信发送开始时间,但当前时间小于开始时间
  705. if(!StringUtils.isEmpty(sendstarttime) && Long.parseLong(currtime) < Long.parseLong(sendstarttime)){
  706. res = false;
  707. }
  708. //有配置短信发送结束时间,但当前时间大于结束时间
  709. if(!StringUtils.isEmpty(sendendtime) && Long.parseLong(currtime) > Long.parseLong(sendendtime)){
  710. res = false;
  711. }
  712. return res;
  713. }
  714. **/
  715. /**
  716. * 根据短信模板发送短信
  717. * @param userid
  718. * @param tempid 模板ID
  719. * @param params 参数变量
  720. * @param smstype 短信网关类型, sms117走117网关,smsjh走聚合网关
  721. * @return
  722. */
  723. /**
  724. private String sendSMS(String userid, String tempid, String params, String smstype) {
  725. String res = "";
  726. try {
  727. //获取发送短信的地址及其他配置
  728. HashMap confhm = commonDao.getInvokeUrlInfo("common", smstype, "2");
  729. if(confhm == null || confhm.size() == 0){
  730. throw new BusinessException("9011","无短信接口配置信息");
  731. }
  732. String invokeurl = confhm.get("INVOKEURL").toString();
  733. JSONObject params1 = JSONObject.parseObject((String)confhm.get("PARAM1"));
  734. String smsid = params1.getString("SMSID");
  735. String key = params1.getString("PWD");
  736. String method = params1.getString("METHOD");
  737. int timeout = params1.getInteger("TIMEOUT");
  738. String tls = params1.getString("TLS");
  739. //String invokeurl = dictionaryDao.getValue("newSmsSendUrl");
  740. //String smsid = dictionaryDao.getValue("mqsmssmsid");
  741. //String key = dictionaryDao.getValue("mqsmspwd");
  742. String contentid = tempid;
  743. String timestamp = System.currentTimeMillis() / 1000 + "";
  744. String usermob = DesUtil.encode(userid, key);
  745. String vars = params;
  746. String sign = SHAUtil.shaEncode(smsid + usermob + timestamp + vars + contentid + key).toLowerCase();
  747. //手机号码和参数转码
  748. usermob = URLEncoder.encode(usermob, "utf-8");
  749. vars = URLEncoder.encode(vars, "utf-8");
  750. String url = invokeurl+"?userid=" + usermob + "&smsid=" + smsid + "&timestamp=" + timestamp + "&sign=" + sign + "&contentid=" + contentid + "&vars=" + vars;
  751. //logmap.put("invokeurl", url);
  752. //res = URLUtil.get(url);
  753. res = HttpInvoke.sendhttpsReqAll(method, url, null, null, timeout*1000, tls);
  754. } catch (Exception e) {
  755. e.printStackTrace();
  756. res = e.getMessage();
  757. }
  758. return res;
  759. }
  760. **/
  761. /**
  762. * 没切换的产品走原流程
  763. * @param messagePipe
  764. */
  765. /****
  766. public String inserMqCssms2(MessagePipe messagePipe) {
  767. String res = "fail";
  768. try {
  769. MessagePipe mpipe = new MessagePipe();
  770. mpipe.setHeader("cssms2");
  771. mpipe.addBody("spid", messagePipe.getBody().get("spid"));
  772. mpipe.addBody("cpid", messagePipe.getBody().get("cpid"));
  773. mpipe.addBody("userid", messagePipe.getBody().get("userid"));
  774. mpipe.addBody("times", messagePipe.getBody().get("times"));
  775. mpipe.addBody("style", messagePipe.getBody().get("style"));
  776. mpipe.addBody("busiType", messagePipe.getBody().get("busiType")); //业务类型
  777. mpipe.addBody("channel", messagePipe.getBody().get("channel")); //渠道
  778. mpipe.addBody("subchannel", messagePipe.getBody().get("subchannel"));//子渠道
  779. mpipe.addBody("province", messagePipe.getBody().get("province")); //省份
  780. mpipe.addBody("param1", messagePipe.getBody().get("param1"));
  781. mpipe.addBody("param2", messagePipe.getBody().get("param2"));
  782. mpipe.addBody("param3", messagePipe.getBody().get("param3"));
  783. mpipe.addBody("staffid", messagePipe.getBody().get("staffid"));//员工工号" +
  784. mpipe.addBody("origin", "tmpjob");//员工工号" +
  785. this.messageService.sendMessage(mpipe);
  786. res = "succ";
  787. } catch (Exception e) {
  788. e.printStackTrace();
  789. logger.error("超时异步重试队列推送出现异常," + e.getMessage());
  790. }
  791. return res;
  792. }
  793. ****/
  794. public static void main(String[] args) throws Exception {
  795. CShandleSmsTempJob job = new CShandleSmsTempJob();
  796. job.doProcess();
  797. }
  798. /**
  799. * 发送退订营销短信
  800. * @param userid 手机嘎巴
  801. * @param spid spid
  802. * @param busitype 业务类型
  803. * @param mainlogmap 主日志对象
  804. */
  805. /***
  806. private void sendCancelYxSms(HashMap<String, String> bodyparams, HashMap mainlogmap){
  807. String userid = bodyparams.get("userid");
  808. String spid = bodyparams.get("spid");
  809. String busitype = bodyparams.get("busiType");
  810. if(busitype.indexOf("cancel_succ") == -1){
  811. return;
  812. }
  813. String resultcode = "5000";
  814. String errorinfo = "";
  815. String phcpid = ""; //偏好CPID
  816. String hyspid = ""; //合约产品SPID
  817. HashMap<String, Object> logmap = new HashMap<String, Object>();
  818. HashMap<String, String> vargs = null;
  819. try {
  820. List<HashMap> dataList = mqSmsConfDao.qryCancelYxConf(busitype);
  821. if(dataList == null || dataList.size() == 0){
  822. throw new BusinessException("9002","业务类型【"+busitype+"】无营销配置");
  823. }
  824. logmap.put("hasconf", "0");//是否有配置
  825. logmap.put("userid", userid);
  826. logmap.put("busitype", busitype);
  827. //调柏源用户偏好接口
  828. String res = this.invokeCancelyx(userid, logmap);
  829. //res = "{\"code\":200,\"success\":true,\"data\":\"aiqy\",\"msg\":\"操作成功\"}";
  830. JSONObject resobj = JSONObject.parseObject(res);
  831. if(resobj.get("code") != null && resobj.getInteger("code") == 200
  832. && resobj.getBoolean("success") == true){ //调接口成功
  833. phcpid = resobj.getString("data");
  834. }
  835. //得到了偏好CP
  836. if(!StringUtils.isEmpty(phcpid)){
  837. //用户是否已订购偏好CP产品
  838. List<HashMap> relList = commonDao.qryRealByUserid(userid, phcpid, null,"2");
  839. //芒果CPID特殊处理,多一次查询
  840. if(relList == null || relList.size() == 0){
  841. //是mangtv,则再查一次mangtv16
  842. if("mangtv".equals(phcpid)){
  843. relList = commonDao.qryRealByUserid(userid, "mangtv16", null,"2");
  844. }else if("mangtv16".equals(phcpid)){//是mangtv16,则再查一次mangtv
  845. relList = commonDao.qryRealByUserid(userid, "mangtv", null,"2");
  846. }
  847. }
  848. //判断是否订购了后向产品,如果是,则剔除
  849. if(relList != null && relList.size()>0){
  850. Iterator<HashMap> it = relList.iterator();;
  851. HashMap hm = null;
  852. HashMap backconf = null;
  853. while(it.hasNext()){
  854. hm = it.next();
  855. //查询是否为后向产品
  856. backconf = commonDao.qryBackBusiBySpid((String)hm.get("SPID"));
  857. if(backconf != null && backconf.size() > 0){
  858. logger.info("后向产品不参与统计=>" + hm.get("SPID"));
  859. it.remove(); //移除对象
  860. }
  861. }
  862. //再次判断
  863. if(relList != null && relList.size()>0){
  864. throw new BusinessException("9013","已有【"+phcpid+"】订购关系");
  865. }
  866. }
  867. HashMap cancelyxconf = null;
  868. for(HashMap tmp : dataList){
  869. if(phcpid.equals(tmp.get("PHCPID"))){//有偏好CP配置
  870. cancelyxconf = tmp;
  871. break;
  872. }
  873. }
  874. //有营销配置
  875. if(cancelyxconf != null){
  876. logmap.put("cancelyxconf", cancelyxconf);
  877. hyspid = cancelyxconf.get("HYSPID").toString();
  878. //获取合约产品的合约期
  879. HashMap hymap = commonDao.qryHyProduct(hyspid);
  880. if(hymap == null || hymap.size() == 0){
  881. throw new BusinessException("9014","合约产品【"+hyspid+"】无有效期配置");
  882. }
  883. int month = Integer.parseInt(hymap.get("MONTH").toString());
  884. //查询是否订购了合约产品
  885. List<HashMap> relList2 = commonDao.qryRealByUserid(userid, null, hyspid, null);
  886. //订购了合约主品,已失效
  887. if(relList2 != null && relList2.size()>0){
  888. boolean hasRetryOrder = mqSmsConfDao.hasRetryOrder(userid, hyspid, month);
  889. if(!hasRetryOrder){
  890. throw new BusinessException("9015","上次订购合约产品的合约期未到期,hyspid【"+hyspid+"】,month【"+month+"】");
  891. }
  892. }
  893. //是否成功发送过营销短信,且已超过合约期的月份
  894. //boolean hasRetrySendSms = mqSmsConfDao.hasRetrySendSms(userid, hyspid, month);
  895. //if(!hasRetrySendSms){
  896. //throw new BusinessException("9016","上次发送营销短信未超过合约期,hyspid【"+hyspid+"】,month【"+month+"】");
  897. //}
  898. //获取调接口参数
  899. vargs = matchParam(cancelyxconf, userid);
  900. logmap.put("营销模板参数", vargs);
  901. if(vargs == null || vargs.size() == 0){
  902. throw new BusinessException("9008","退订营销短信无模板参数匹配");
  903. }
  904. //模板ID
  905. String smstempid = (String)cancelyxconf.get("SMSTEMPID");
  906. logmap.put("营销模板ID", smstempid);
  907. logmap.put("smstype", "smsjh");
  908. //调短信发送接口
  909. String smsres = sendSMS(userid,smstempid,JsonUtil.objectToJson(vargs),"smsjh");
  910. //smsres = "{\"resultcode\":\"0\",\"errorinfo\":\"\",\"taskid\":\"202208191529181184600\",\"ssmsid\":null}";
  911. logmap.put("发送营销短信响应报文", smsres);
  912. JSONObject smsresobj = JSONObject.parseObject(smsres);
  913. if("0".equals(smsresobj.getString("resultcode"))){
  914. resultcode = "0";
  915. errorinfo = "ok";
  916. }else{
  917. resultcode = "9099";
  918. errorinfo = "发送短信失败," + smsres;
  919. }
  920. }else{
  921. throw new BusinessException("9009","偏好CP无模板配置【"+phcpid+"】");
  922. }
  923. }else{
  924. throw new BusinessException("9019","柏源接口无偏好CP返回");
  925. }
  926. } catch (Exception e) {
  927. if (e instanceof BusinessException) {
  928. resultcode = ((BusinessException)e).getCode();
  929. errorinfo = ((BusinessException)e).getMessage();
  930. }else{
  931. e.printStackTrace();
  932. resultcode = "8000";
  933. errorinfo = e.getMessage();
  934. }
  935. } finally {
  936. //有配置则记录数据,输出日志
  937. if("0".equals(logmap.get("hasconf"))){
  938. logmap.put("resultcode", resultcode);
  939. logmap.put("errorinfo", errorinfo);
  940. try {
  941. HashMap<String, String> params = new HashMap<String, String>();
  942. params.put("HYSPID", hyspid);
  943. params.put("SPNAME", commonDao.qrySpinfoBySpid(spid).get("SPNAME")+"");
  944. params.put("PHCPID", phcpid);
  945. params.put("USERID", userid);
  946. params.put("RESULTCODE", resultcode);
  947. params.put("ERRORINFO", errorinfo);
  948. params.put("BUSITYPE", busitype);
  949. params.put("SPID", spid);
  950. params.put("VARGS", (vargs == null ? null : vargs.toString()));
  951. params.put("OUTPARAMS", (String)logmap.get("invokeres"));
  952. boolean flag = mqSmsConfDao.addCancelyxRec(params);
  953. logmap.put("addCancelyxRec", flag);
  954. } catch (Exception e) {
  955. e.printStackTrace();
  956. logmap.put("addCancelyxRec", "false "+e.getMessage());
  957. }
  958. //输出日志
  959. //logger.info(logmap);
  960. mainlogmap.put("cancelyxsms", logmap);
  961. }
  962. }
  963. }
  964. ***/
  965. /**
  966. * 匹配调模板参数
  967. * @param mqsmsconf
  968. * @param userid
  969. * @return
  970. */
  971. /**
  972. private HashMap<String, String> matchParam(HashMap mqsmsconf, String userid){
  973. //短信参数
  974. String [] smsparamsArray = mqsmsconf.get("PARAMS").toString().split("\\|");
  975. //短信参数映射
  976. String [] smsparamsmappArray = mqsmsconf.get("PARAMSMAPP").toString().split("\\|");
  977. //获取mq表的参数映射
  978. String mqparamsmapp = (String)mqsmsconf.get("MQPARAMSMAPP");
  979. //有个性化配置映射,优先级高于TB_SMSTEMP_CONF的MQPARAMSMAPP配置
  980. if(!StringUtils.isEmpty(mqparamsmapp)){
  981. smsparamsmappArray = mqparamsmapp.split("\\|");
  982. }
  983. //调接口模板参数
  984. HashMap<String, String> invokeparams = new HashMap<String, String>();
  985. String param = "";
  986. //组建调接口模板参数
  987. for(int p = 0; p < smsparamsArray.length; p++){
  988. param = smsparamsArray[p];
  989. if("oriuserid".equals(param)){//原始手机号码
  990. invokeparams.put(param, userid);
  991. }else if("userid".equals(param)){
  992. //模糊化
  993. String fulluserid = userid.substring(0, 3)+"****"+userid.substring(7);
  994. invokeparams.put(param, fulluserid);
  995. }else{//按配置的信息设置
  996. invokeparams.put(param, fullNullStr(smsparamsmappArray[p]));
  997. }
  998. }
  999. return invokeparams;
  1000. }
  1001. **/
  1002. /**
  1003. * 调柏源用户偏好接口
  1004. * @param userid
  1005. * @return
  1006. * @throws Exception
  1007. */
  1008. /**
  1009. private String invokeCancelyx(String userid, HashMap<String, Object> logmap) throws Exception{
  1010. String res = "";
  1011. try {
  1012. HashMap confhm = commonDao.getInvokeUrlInfo("activeprocess", "foreigngetCpid", "1");
  1013. if(confhm == null || confhm.size() == 0){
  1014. throw new BusinessException("9012","无柏源接口配置信息");
  1015. }
  1016. logmap.put("invokeconf", confhm);
  1017. String url = confhm.get("INVOKEURL").toString();
  1018. JSONObject params1 = JSONObject.parseObject((String)confhm.get("PARAM1"));
  1019. String method = params1.getString("METHOD");
  1020. int timeout = params1.getInteger("TIMEOUT");
  1021. String tls = params1.getString("TLS");
  1022. String contentttype = params1.getString("CONTENTTYPE");
  1023. String channel = params1.getString("CHANNEL");
  1024. //加密KEY
  1025. String despwd = params1.getString("DESPWD");
  1026. Map reqProperty = new HashMap();
  1027. reqProperty.put("Content-type", contentttype);
  1028. JSONObject content = new JSONObject();
  1029. if(StringUtils.isEmpty(despwd)){ //密钥为空,参数不加密
  1030. content.put("phone", userid);
  1031. }else{
  1032. //content.put("phone", EnDecHelper2.encodeByPwd(userid, despwd));
  1033. content.put("phone", DesUtil.encode(userid, despwd));
  1034. }
  1035. logmap.put("invokeparams", userid+"=>"+content.toJSONString());
  1036. res = HttpInvoke.sendhttpsReqAll(method, url, content.toJSONString(), reqProperty, timeout*1000, tls);
  1037. logmap.put("invokeres", res);
  1038. } catch (Exception e) {
  1039. if (e instanceof BusinessException) {
  1040. throw e;
  1041. }else{
  1042. e.printStackTrace();
  1043. throw new BusinessException("8000","调柏源用户偏好接口出现异常,"+e.getMessage());
  1044. }
  1045. }
  1046. return res;
  1047. }
  1048. **/
  1049. /**
  1050. * 根据手机号码获取映射ID,用于页面自动登录
  1051. * @param userid
  1052. * @return
  1053. */
  1054. /**
  1055. private String getMappidByUserid(String userid, HashMap<String, Object> logmap){
  1056. String mappid = "";
  1057. String resultcode = "5000";
  1058. String errorinfo = "";
  1059. HashMap<String, Object> tmplogmap = new HashMap<String, Object>();
  1060. try {
  1061. HashMap confhm = commonDao.getInvokeUrlInfo("univideo", "usermappqrymappid", "2");
  1062. if(confhm == null || confhm.size() == 0){
  1063. throw new BusinessException("9012","无柏源接口配置信息");
  1064. }
  1065. String url = confhm.get("INVOKEURL").toString();
  1066. JSONObject params1 = JSONObject.parseObject((String)confhm.get("PARAM1"));
  1067. String method = params1.getString("METHOD");
  1068. int timeout = params1.getInteger("TIMEOUT");
  1069. String tls = params1.getString("TLS");
  1070. String contentttype = params1.getString("CONTENTTYPE");
  1071. String channel = params1.getString("CHANNEL");
  1072. //加密KEY
  1073. String pwd = params1.getString("PWD");
  1074. Map reqProperty = new HashMap();
  1075. if(!StringUtils.isEmpty(contentttype)){
  1076. reqProperty.put("Content-type", contentttype);
  1077. }
  1078. String account = userid;
  1079. String timestamp = (System.currentTimeMillis())/1000+"";
  1080. account = DesUtil.encode(account, pwd);
  1081. String signature = account+channel+timestamp+pwd;
  1082. signature = MD5.MD5Encode(signature);
  1083. JSONObject params = new JSONObject();
  1084. params.put("account", account);
  1085. params.put("channel", channel);
  1086. params.put("timestamp", timestamp);
  1087. params.put("signature", signature);
  1088. tmplogmap.put("invokeparams", params.toJSONString());
  1089. String res = "";
  1090. if(url.startsWith("https")){
  1091. res = HttpInvoke.sendhttpsReqAll(method, url, params.toJSONString(), reqProperty, timeout*1000, tls);
  1092. }else{
  1093. res = HttpInvoke.sendHttpByPost(method, url, params.toJSONString(), reqProperty, timeout*1000);
  1094. }
  1095. tmplogmap.put("invokeres", res);
  1096. //{"resultcode":"0","errorinfo":"ok","data":{"userid":"UooUmz1MQgSRsKdMZVpGIQ==","mappid":"9e888164125f44359943d48b566355da"}}
  1097. if(!StringUtils.isEmpty(res)){
  1098. JSONObject tmp = JSONObject.parseObject(res);
  1099. resultcode = tmp.getString("resultcode");
  1100. errorinfo = tmp.getString("errorinfo");
  1101. if(tmp.getJSONObject("data") != null){
  1102. mappid = tmp.getJSONObject("data").getString("mappid");
  1103. }
  1104. }
  1105. } catch (Exception e) {
  1106. if (e instanceof BusinessException) {
  1107. resultcode = ((BusinessException)e).getCode();
  1108. errorinfo = ((BusinessException)e).getMessage();
  1109. }else{
  1110. e.printStackTrace();
  1111. resultcode = "8000";
  1112. errorinfo = "获取映射ID出现异常,"+e.getMessage();
  1113. }
  1114. } finally {
  1115. tmplogmap.put("resultcode", resultcode);
  1116. tmplogmap.put("errorinfo", errorinfo);
  1117. logmap.put("getMappidByUserid", tmplogmap);
  1118. }
  1119. return mappid;
  1120. }
  1121. **/
  1122. }