e5a119d20ee1ae5395a98ead1c48e77cd5003c88.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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.process.bean.ChannelOrderBean;
  8. import com.chinacreator.process.bean.OrderConfigBean;
  9. import com.chinacreator.process.dao.CsmakeupDao;
  10. import com.chinacreator.process.dao.DictionaryDao;
  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.video.queue.MessageService;
  15. import com.chinacreator.video.queue.bean.MessagePipe;
  16. import net.sf.json.JSONArray;
  17. import org.apache.log4j.Logger;
  18. import org.quartz.DisallowConcurrentExecution;
  19. import org.quartz.PersistJobDataAfterExecution;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import java.sql.SQLException;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 指定四个畅视产品订购和退订成功后调拓维的C+会员接口同步订购关系
  28. *
  29. * @author zhengrong.yan
  30. * @date 20200911
  31. */
  32. ///update 新增产品加新增字段(传递退订时间等)
  33. /*
  34. 畅视随心选会员包 99144185
  35. 畅视随心选定向流量会员包(前向) 99144186
  36. 畅视随心选定向流量尊享包(前向) 99144187
  37. 99134262 畅视随心选定向流量会员+PP视频会员包 20210114 新添加
  38. */
  39. @PersistJobDataAfterExecution
  40. @DisallowConcurrentExecution
  41. public class ChangshiPushMQJob {
  42. private Logger logger = Logger.getLogger("changshicj");
  43. @Autowired
  44. private DictionaryDao dictionaryDao;
  45. @Autowired
  46. private MessageService messageService;
  47. @Autowired
  48. private CsmakeupDao csmakeupDao;
  49. public void doProcess() throws Exception {
  50. logger.info("指定四个畅视产品订购和退订成功后调拓维的C+会员接口同步订购关系推送消息队列JOB启动");
  51. if (dictionaryDao.getValue("recivemq").equals("0")) {
  52. long beginTime = System.currentTimeMillis();
  53. List<MessagePipe> list = messageService.reciveBatchMessage("changshicj", 500);
  54. logger.info("接收消息队列花费时间:" + (System.currentTimeMillis() - beginTime));
  55. List<Map> dataList = new ArrayList<Map>();
  56. for (MessagePipe messagePipe : list) {
  57. Map reqBean = transBean(messagePipe.getBody());
  58. dataList.add(reqBean);
  59. }
  60. if (dataList != null && dataList.size() > 0) {
  61. logger.info("待处理数据条数:" + dataList.size());
  62. for (Map reqBean : dataList) {
  63. this.handleOrder(reqBean);
  64. }
  65. }
  66. } else {
  67. logger.info("停止接收队列消息");
  68. }
  69. }
  70. /**
  71. * 业务处理
  72. *
  73. * @param mqBean
  74. */
  75. public void handleOrder(Map reqBean) {
  76. Map logMap = new HashMap();
  77. logMap.put("data", reqBean);
  78. long starttime = System.currentTimeMillis();
  79. String resultCode = "-1";
  80. String resultInfo = "";
  81. try {
  82. //调拓维C+接口
  83. tuoweiInvoke(reqBean);
  84. resultCode = "0";
  85. resultInfo = "执行成功";
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. resultCode = "8000";
  89. resultInfo = "系统错误," + e.getMessage();
  90. logger.error("同步订购关系出现异常," + e.getMessage());
  91. } finally {
  92. //写日志
  93. logMap.put("time", System.currentTimeMillis() - starttime);
  94. logMap.put("reusltCode", resultCode);
  95. logMap.put("resultInfo", resultInfo);
  96. logger.info(JsonUtil.objectToJson(logMap));
  97. }
  98. }
  99. /**
  100. * 解析数据
  101. *
  102. * @param body orderId TD_POINTS_ORDER_REC表ID字段,我方生成的订单流水号
  103. * orderNo 积分商城订单号
  104. * requestId 返回给客户的请求ID
  105. * @return
  106. */
  107. public Map transBean(Map<String, Object> body) {
  108. String jsonStr = JsonUtil.objectToJson(body);
  109. return (Map) JsonUtil.jsonToBean(jsonStr, Map.class);
  110. }
  111. /**
  112. * 获取请求属性性
  113. *
  114. * @return
  115. */
  116. private static Map getProperty(String updatetype) {
  117. Map reqProperty = new HashMap();
  118. if ("0".equals(updatetype)) {//订购
  119. reqProperty.put("Content-type", "application/json;charset=utf-8");
  120. } else {//退订
  121. reqProperty.put("Content-type", "application/x-www-form-urlencoded");
  122. }
  123. return reqProperty;
  124. }
  125. /**
  126. * 增加拓维C+接口
  127. *
  128. * @param orderBean
  129. */
  130. private void tuoweiInvoke(Map reqBean) throws Exception {
  131. boolean hasrec = false;
  132. long starttime = System.currentTimeMillis();
  133. HashMap params = new HashMap();
  134. try {
  135. List<HashMap> confList = csmakeupDao.getBusiConf(reqBean.get("spid").toString());//spid过滤数据
  136. if (confList != null && confList.size() > 0) {
  137. hasrec = true;
  138. HashMap conf = confList.get(0);
  139. conf.put("SENO", csmakeupDao.getNo()); //获取业务流水号
  140. params.put("SENO", conf.get("SENO")); //获取业务流水号
  141. params.put("CHANNEL", "JOB-changshicj");
  142. params.put("USERID", reqBean.get("userid"));
  143. params.put("PROVINCE", reqBean.get("province"));
  144. params.put("AREA", reqBean.get("area"));
  145. params.put("VIPRECODE", "-1");
  146. params.put("VIPREINFO", "");
  147. params.put("RESULTCODE", "0");
  148. params.put("RESULTINFO", "ok");
  149. params.put("STATUS", "0");
  150. params.put("MUSPID", conf.get("MUSPID"));
  151. if ("1".equals(reqBean.get("type"))) {//0 订购 1 退订
  152. params.put("STATUS", "1");
  153. }
  154. params.put("CPID", conf.get("CPID"));
  155. String result = invokeTwvip(reqBean, conf); //调拓维会员接口返回结果
  156. if (!"".equals(result)) {
  157. params.put("VIPRECODE", JSON.parseObject(result).get("code").toString());
  158. //params.put("VIPREINFO", JSON.parseObject(result).get("message").toString());
  159. params.put("VIPREINFO", result);
  160. }
  161. }
  162. } catch (Exception e) {
  163. e.printStackTrace();
  164. logger.error("调拓维C+接口出现异常," + e.getMessage());
  165. params.put("VIPRECODE", "8000");
  166. params.put("VIPREINFO", e.getMessage());
  167. params.put("RESULTCODE", "8000");
  168. params.put("RESULTINFO", "调拓维C+会员接口异常," + e.getMessage());
  169. throw e;
  170. } finally {
  171. if (hasrec) {
  172. try {
  173. String vipreinfo = (String) params.get("VIPREINFO");
  174. if (vipreinfo != null && vipreinfo.length() > 500) {
  175. params.put("VIPREINFO", vipreinfo.subSequence(0, 450));
  176. }
  177. params.put("TIMES", System.currentTimeMillis() - starttime);
  178. csmakeupDao.addOrderRec(params);
  179. } catch (Exception e) {
  180. e.printStackTrace();
  181. logger.error("拓维C+接口添加订购记录出现异常," + e.getMessage());
  182. }
  183. }
  184. }
  185. }
  186. /**
  187. * 调拓维会员接口
  188. *
  189. * @param orderBean
  190. * @param conf
  191. * @return
  192. * @throws Exception
  193. */
  194. private String invokeTwvip(Map orderBean, HashMap conf) throws Exception {
  195. String result = ""; //调拓维会员接口返回结果
  196. String vipurl = "";
  197. String jsonParams = "";
  198. if ("1".equals(orderBean.get("type"))) {//退订
  199. vipurl = dictionaryDao.getValue("csmakeupvipcancelurl");
  200. jsonParams = this.fullCancelParams(orderBean.get("userid").toString(), conf,
  201. orderBean.get("canceltime")==null?"":orderBean.get("canceltime").toString());
  202. } else {//订购
  203. vipurl = dictionaryDao.getValue("csmakeupviporderurl");
  204. jsonParams = this.fullOrderParams(orderBean.get("userid").toString(), conf);
  205. }
  206. logger.info("vipurl=>" + vipurl + ", jsonParams=>" + jsonParams);
  207. /*
  208. if("1".equals(orderBean.getUpdatetype())){//订购
  209. result = com.chinacreator.process.util.URLUtil.postJson(vipurl, jsonParams);
  210. result = HttpInvoke.sendHttpByPost("POST", vipurl, jsonParams, getProperty(orderBean.getUpdatetype()));
  211. }else{//退订
  212. result = com.chinacreator.process.util.URLUtil.postForm(vipurl, jsonParams);
  213. result = HttpInvoke.sendHttpByPost("POST", vipurl, jsonParams, getProperty(orderBean.getUpdatetype()));
  214. }*/
  215. result = HttpInvoke.sendhttpsReq("POST", vipurl, jsonParams, getProperty(orderBean.get("type").toString()));
  216. logger.info("调拓维会员接口返回结果:" + result);
  217. //去空格、换行符号
  218. if (result != null) result = result.replaceAll("\r|\n", "").replaceAll(" ", "").replaceAll(" ", "");
  219. //result = "{\"code\":0,\"message\":\"成功\",\"success\":true}";
  220. //result = "{\"code\":7007,\"message\":\"签名无效\",\"success\":false}";
  221. return result;
  222. }
  223. /**
  224. * 填充退订会员参数
  225. *
  226. * @param mobile
  227. * @param conf
  228. * @return
  229. * @throws Exception
  230. */
  231. private String fullCancelParams(String mobile, HashMap conf, String canceltime) throws Exception {
  232. String jsonParams = "";
  233. HashMap<String, String> params = new HashMap<String, String>();
  234. String timestamp = System.currentTimeMillis() + "";
  235. String spid = conf.get("VSPID").toString();
  236. String cpid = conf.get("VCPID").toString();
  237. String userType = "1";
  238. String password = conf.get("VPWD").toString();
  239. mobile = DesUtil.encode(mobile, password); //手机号码加密
  240. String refundTime = canceltime;
  241. String signature = MD5.MD5Encode(spid + cpid + mobile + refundTime + userType + timestamp + password);
  242. JSONObject json = new JSONObject();
  243. json.put("timestamp", timestamp);
  244. json.put("signature", signature);
  245. json.put("spid", spid);
  246. json.put("cpid", cpid);
  247. json.put("mobile", mobile);
  248. json.put("userType", userType);
  249. json.put("refundTime", refundTime);
  250. jsonParams = json.toJSONString();
  251. //去除json格式
  252. jsonParams = jsonParams.replaceAll(":", "=").replaceAll(",", "&")
  253. .replaceAll("\"", "").replaceAll("\\{", "").replaceAll("\\}", "");
  254. return jsonParams;
  255. }
  256. /**
  257. * 填充订购会员参数
  258. *
  259. * @param mobile
  260. * @param conf
  261. * @return
  262. * @throws Exception
  263. */
  264. private String fullOrderParams(String mobile, HashMap conf) throws Exception {
  265. String jsonParams = "";
  266. String timestamp = System.currentTimeMillis() + "";
  267. String spid = conf.get("VSPID").toString();
  268. String cpid = conf.get("VCPID").toString();
  269. String memberUrl = "";
  270. String orderNumber = conf.get("SENO").toString();
  271. String password = conf.get("VPWD").toString();
  272. mobile = DesUtil.encode(mobile, password); //手机号码加密
  273. String signature = MD5.MD5Encode(spid + cpid + orderNumber + timestamp + password);
  274. JSONObject json = new JSONObject();
  275. JSONArray jsonArray = new JSONArray();
  276. jsonArray.add(mobile);
  277. json.put("timestamp", timestamp);
  278. json.put("signature", signature);
  279. json.put("spid", spid);
  280. json.put("cpid", cpid);
  281. json.put("mobiles", jsonArray);
  282. json.put("memberUrl", memberUrl);
  283. json.put("orderNumber", orderNumber);
  284. jsonParams = json.toJSONString();
  285. return jsonParams;
  286. }
  287. }