ShouhuoPay.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. package com.minpay.common.pay;
  2. import com.huilian.api.open.huilianjavademo.XmlUtil;
  3. import com.min.base64.Base64;
  4. import com.min.des.DesUtils;
  5. import com.minpay.common.bean.User;
  6. import com.minpay.common.constant.PayOSConstant;
  7. import com.minpay.common.exception.BusinessCodeException;
  8. import com.minpay.common.pay.bean.Huilianpay;
  9. import com.minpay.common.service.IAccountService;
  10. import com.minpay.common.service.IHuilianPayService;
  11. import com.minpay.common.service.IPropertiesService;
  12. import com.minpay.common.service.IPublicService;
  13. import com.minpay.common.service.impl.HuilianPayServiceImpl;
  14. import com.minpay.common.util.CommonUtil;
  15. import com.minpay.common.util.DateUtil;
  16. import com.minpay.common.util.HttpPostUtil;
  17. import com.minpay.common.util.PayCommonUtil;
  18. import com.minpay.db.table.mapper.*;
  19. import com.minpay.db.table.model.*;
  20. import com.minpay.db.table.own.mapper.DeliveryMapper;
  21. import com.minpay.shouhuo.deliveryaction.DeliveryAction;
  22. import com.minpay.shouhuo.orderdrawaction.OrderDrawAction;
  23. import com.startup.minpay.frame.business.IMINAction;
  24. import com.startup.minpay.frame.business.MINHttpServletRequestContext;
  25. import com.startup.minpay.frame.business.res.MINActionResult;
  26. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  27. import com.startup.minpay.frame.exception.MINBusinessException;
  28. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  29. import com.startup.minpay.frame.service.base.Service;
  30. import com.startup.minpay.frame.session.MINSession;
  31. import com.startup.minpay.frame.target.MINAction;
  32. import com.startup.minpay.frame.target.MINComponent;
  33. import com.startup.minpay.frame.target.MINParam;
  34. import net.sf.json.JSONObject;
  35. import org.apache.commons.lang.StringUtils;
  36. import javax.servlet.http.HttpServletRequest;
  37. import javax.servlet.http.HttpServletResponse;
  38. import java.io.BufferedReader;
  39. import java.io.InputStream;
  40. import java.io.InputStreamReader;
  41. import java.io.PrintWriter;
  42. import java.util.*;
  43. /**
  44. * 售货机支付通用接口
  45. * @author Zhumq
  46. *
  47. */
  48. @MINComponent
  49. public class ShouhuoPay implements IMINAction{
  50. /** 通用支付 */
  51. public final static String MIN_COMMMON_PAY = "minCommmonPay";
  52. /** PersonalPay支付回调 */
  53. public final static String PERSONALPAY_CALL_BACK = "personalPayCallBack";
  54. /** 查询PersonalPay的订单状态 */
  55. public final static String QUERY_PERSONALPAY_ORDERSTT = "queryPersonalpayOrderstt";
  56. /**
  57. * 通用支付
  58. * @param payAmt 支付总金额
  59. * @param orderId 支付订单号
  60. * @param payType 支付类型(渠道 WX微信 ALI 支付宝)
  61. * @param session
  62. * @param fapRequest
  63. * @return
  64. * @throws Exception
  65. */
  66. @MINAction(value = MIN_COMMMON_PAY, transaction = IMINTransactionEnum.CMT)
  67. public MINActionResult minCommmonPay(
  68. @MINParam(key = "payAmt") String payAmt,
  69. @MINParam(key = "orderId") String orderId,
  70. @MINParam(key = "payType", defaultValue = "WX") String payType,
  71. MINSession session,
  72. MINHttpServletRequestContext fapRequest
  73. ) throws Exception {
  74. MINActionResult res = new MINActionResult();
  75. //获取操作员信息
  76. User user = session.getUser();
  77. //获取当前时间
  78. String nowTime = DateUtil.getCurrentDateTimeString();
  79. String oldID = orderId;
  80. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).selectByPrimaryKey(oldID);
  81. if(CommonUtil.compare(payAmt, ordInf.getOrderAmt()) != 0){
  82. throw new MINBusinessException("交易异常");//支付金额不对
  83. }
  84. VmPaymentInfExample paymentExp = new VmPaymentInfExample();
  85. paymentExp.createCriteria().andChannelEqualTo(user.getChannel()).andTranflownoEqualTo(orderId);
  86. List<VmPaymentInf> paymenList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).selectByExample(paymentExp);
  87. // 如果已经支付过一次
  88. if(paymenList.size() > 0) {
  89. // 0 初始状态,1成功,2失败,3在途,4待审核,5已审核
  90. if(!"0".equals(paymenList.get(0).getStatus())
  91. && !"3".equals(paymenList.get(0).getStatus())) {
  92. throw new MINBusinessException("订单已经在支付中!");
  93. }
  94. // 再次支付
  95. if("3".equals(paymenList.get(0).getStatus())) {
  96. // 复制订单明细/订单/支付流水
  97. // 支付状态修改
  98. ordInf.setState("80"); // 支付状态 80:已重新支付
  99. VmOrderInfExample orderExp = new VmOrderInfExample();
  100. orderExp.createCriteria().andIdEqualTo(oldID);
  101. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByExampleSelective(ordInf, orderExp);
  102. // 产生新的订单号
  103. orderId = DateUtil.getDifferentTimeByFormat("MMddHHmmss").concat(StringUtils.substring(orderId, 10));
  104. ordInf.setId(orderId);
  105. ordInf.setState("91");
  106. ordInf.setPayMode(payType);
  107. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).insert(ordInf);
  108. //获取订单下的详情信息
  109. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  110. examp.createCriteria().andChannelEqualTo(user.getChannel()).andOrderIdEqualTo(oldID);
  111. List<VmOrderDetails> detailList = Service.lookup(IMINDataBaseService.class)
  112. .getMybatisMapper(VmOrderDetailsMapper.class)
  113. .selectByExample(examp);
  114. int flags = 0;
  115. // 循环插入明细表
  116. for(VmOrderDetails detDto : detailList) {
  117. String att = null;
  118. if(flags < 10){
  119. att = "0"+flags;
  120. }else{
  121. att = flags +"";
  122. }
  123. // 订单号
  124. detDto.setDetailsId(orderId.concat(att));
  125. detDto.setOrderId(orderId);
  126. detDto.setModifyUser(user.getId());
  127. detDto.setModifyTime(nowTime);
  128. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderDetailsMapper.class).insert(detDto);
  129. flags ++;
  130. }
  131. // 循环插入支付明细
  132. String flowno = Service.lookup(IPublicService.class).getSequence("VM_PAYMENT_INF_ID");
  133. for(VmPaymentInf payMentInf : paymenList) {
  134. //收支类型:00供应商收款01订单退款02平台分润03代理分润
  135. if("00".equals(payMentInf.getType())){
  136. payMentInf.setFlowno(nowTime.concat(flowno).concat("sh"));
  137. }else if("01".equals(payMentInf.getType())){
  138. payMentInf.setFlowno(nowTime.concat(flowno).concat("tk"));
  139. }else if("02".equals(payMentInf.getType())){
  140. payMentInf.setFlowno(nowTime.concat(flowno).concat("pt"));
  141. }else if("03".equals(payMentInf.getType())){
  142. payMentInf.setFlowno(nowTime.concat(flowno).concat("dl"));
  143. }
  144. payMentInf.setTranflowno(orderId);
  145. payMentInf.setTranmissiondatetime(nowTime);
  146. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  147. payMentInf.setStatus("3");
  148. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).insert(payMentInf);
  149. }
  150. }
  151. else {
  152. //修改支付方式
  153. ordInf.setPayMode(payType);
  154. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(ordInf);
  155. VmPaymentInf paymentInf = new VmPaymentInf();
  156. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  157. paymentInf.setStatus("3");
  158. paymentInf.setTranflowno(orderId);
  159. paymentInf.setTranmissiondatetime(DateUtil.getCurrentDateTimeString());
  160. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).updateByExampleSelective(paymentInf, paymentExp);
  161. }
  162. }else{
  163. //修改支付方式
  164. ordInf.setPayMode(payType);
  165. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(ordInf);
  166. }
  167. Map<String, Object> resMap = null;
  168. try {
  169. VmPaymentInf paymentInf = new VmPaymentInf();
  170. // 支付通道
  171. String payChannel = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() +"_PERSONALPAY_PAY_CHANNEL");
  172. //汇联
  173. if("HLZF".equals(payChannel)) {
  174. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(ordInf.getEquipmentId());
  175. if(equipmentInf == null) {
  176. throw new MINBusinessException("没有找到此售货机");
  177. }
  178. String branchid = equipmentInf.getBranchid();
  179. //查询商户开通了那个支付渠道
  180. String pay_channel = Service.lookup(IPublicService.class).getSysParValue( "PAY_CHANNEL");
  181. //查询机器所属机构
  182. VmAccountExample accExp = new VmAccountExample();
  183. accExp.createCriteria().andChannelEqualTo(user.getChannel()).andUsridEqualTo(branchid).andTypeEqualTo(pay_channel);
  184. List<VmAccount> accList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmAccountMapper.class).selectByExample(accExp);
  185. if(accList.size() != 1 ){
  186. throw new MINBusinessException("商户收款账户异常");
  187. }
  188. String accNo = accList.get(0).getNumber();
  189. //支付后台回调地址
  190. String notify_url = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_NOTIFY_URL");
  191. notify_url = "http://xubing2.minpay.cc/services";
  192. notify_url = notify_url + "/ShouhuoPay/personalPayCallBack";
  193. if("05".equals(pay_channel)){
  194. pay_channel = "09";
  195. }
  196. Huilianpay prePay = new Huilianpay();
  197. IHuilianPayService huilianPayService = new HuilianPayServiceImpl();
  198. prePay.setChannel(payType);
  199. prePay.setNotifyUrl(notify_url);
  200. prePay.setOpenId(user.getOpenid());
  201. prePay.setOutTradeNo(orderId);
  202. prePay.setProviderType(pay_channel);
  203. prePay.setTotalAmount(payAmt);
  204. prePay.setHlMerchantId(accNo);
  205. prePay.setGoodName(orderId);
  206. prePay.setSucUrl("http://shjservices.personalpay.cn/services/");
  207. resMap = huilianPayService.prePay(prePay);
  208. }
  209. } catch (Exception e) {
  210. throw new MINBusinessException("调用支付失败");
  211. }
  212. // 抽奖订单
  213. /*if("01".equals(ordInf.getProType())) {
  214. // 减余额
  215. // 创建用户基本账户
  216. IAccountService accservice = Service.lookup(IAccountService.class);
  217. // 41:消费
  218. accservice.modfiyAccount(ordInf.getChannel(), ordInf.getPersonId(), "01",
  219. CommonUtil.multiply(ordInf.getOrderAmt(), "-1"), "41", ordInf.getId(), "游戏消费");
  220. //调用真实回调
  221. backEx(ordInf.getId(), "0000000000", "TRADE_SUCCESS", ordInf.getOrderAmt(), "000000", "", "93");
  222. // 正常商品购买、但是选择的是钱包支付
  223. } if("00".equals(ordInf.getProType()) && "09".equals(payType)) {
  224. // 减余额
  225. // 创建用户基本账户
  226. IAccountService accservice = Service.lookup(IAccountService.class);
  227. // 41:消费
  228. accservice.modfiyAccount(ordInf.getChannel(), ordInf.getPersonId(), "01",
  229. CommonUtil.multiply(ordInf.getOrderAmt(), "-1"), "41", ordInf.getId(), "购买商品");
  230. //调用真实回调
  231. backEx(ordInf.getId(), "0000000000", "TRADE_SUCCESS", ordInf.getOrderAmt(), "000000", "", "93");
  232. }*/
  233. res.set("payMap",resMap);
  234. return res;
  235. }
  236. /**
  237. * 查询PersonalPay的订单状态
  238. * @param orderId 订单号
  239. * @param session
  240. * @return
  241. * @throws MINBusinessException
  242. */
  243. @MINAction(value = QUERY_PERSONALPAY_ORDERSTT)
  244. public MINActionResult queryPersonalpayOrderstt(
  245. @MINParam(key = "orderId") String orderId,
  246. MINSession session ) throws MINBusinessException {
  247. MINActionResult res = new MINActionResult();
  248. //获取操作员信息
  249. User user = session.getUser();
  250. try {
  251. VmOrderInf listch = Service.lookup(IMINDataBaseService.class)
  252. .getMybatisMapper(VmOrderInfMapper.class)
  253. .selectByPrimaryKey(orderId);
  254. if(listch.getState().equals("00")){
  255. res.set("orderId", orderId);
  256. res.set("stt", listch.getState());
  257. res.set("code", "200");
  258. // 00正常商品,01抽奖商品,02:充值',
  259. res.set("proType", listch.getProType());
  260. return res;
  261. }
  262. // 支付通道
  263. String payChannel = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() +"_PERSONALPAY_PAY_CHANNEL");
  264. String appSecret = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_APP_SECRET");
  265. if("PEP".equals(payChannel)) {
  266. String appid = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_APP_ID");
  267. String mchid = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_MCH_ID");
  268. //创建PersonalPay订单对象
  269. SortedMap<Object, Object> perPay = new TreeMap<Object, Object>();
  270. perPay.put("mchid",mchid);//商户号
  271. perPay.put("appid", appid);//appId
  272. perPay.put("orderno",orderId);//交易订单号
  273. perPay.put("sysorderno","");//交易订单号
  274. perPay.put("signtype","MD5");//加密类型
  275. String paySign = PayCommonUtil.createSign("UTF-8", perPay, appSecret);
  276. perPay.put("sign",paySign);//加密后字符串
  277. /**
  278. * 返回值信息
  279. * 10:创建订单 80:已重新支付 90:已取消 91:未支付 92:支付中 00 :已支付, 01 :手动通知(掉单后可手动通知)
  280. * "stt":"10",
  281. * "code":0
  282. */
  283. //获取请求PersonalPay的路径"http://api.personalpay.net/api/";
  284. String url = Service.lookup(IPropertiesService.class)
  285. .getSystemProperties().get(user.getChannel() + "_PERSONALPAY_PAY_ADDRESS").getKey();
  286. String str = PayCommonUtil.getRequestJSON(perPay);
  287. String results = HttpPostUtil.sendPostFormachine(url.concat("/OrderAction/queryOrderStt"), str);
  288. //获取转义后响应信息
  289. JSONObject detail = JSONObject.fromObject(results);
  290. //获取code,用来判断是否认证成功
  291. String code = String.valueOf(detail.get("code"));
  292. if(!"0".equals(code)){
  293. throw new BusinessCodeException("JINM0115");//操作失败!
  294. }
  295. res.set("code", detail.get("code"));
  296. res.set("orderId", orderId);
  297. res.set("stt", detail.get("stt"));
  298. // 00正常商品,01抽奖商品,02:充值',
  299. res.set("proType", listch.getProType());
  300. }
  301. } catch (Exception e) {
  302. throw new MINBusinessException("调用支付查询失败");
  303. }
  304. return res;
  305. }
  306. /**
  307. * personalPay支付回调
  308. * @return
  309. * @throws Exception
  310. */
  311. @MINAction(value = PERSONALPAY_CALL_BACK, session = false)
  312. public MINActionResult personalPayCallBack(
  313. HttpServletRequest request,
  314. HttpServletResponse response
  315. ) throws Exception {
  316. PrintWriter printWriter = response.getWriter();
  317. printWriter.write("SUCCESS");
  318. printWriter.flush();//没有该句也是报一样错.
  319. printWriter.close();
  320. MINActionResult res = new MINActionResult();
  321. StringBuffer sb = new StringBuffer() ;
  322. InputStream is = request.getInputStream();
  323. InputStreamReader isr = new InputStreamReader(is);
  324. BufferedReader br = new BufferedReader(isr);
  325. String s = "" ;
  326. while((s=br.readLine())!=null){
  327. sb.append(s) ;
  328. }
  329. String result = sb.toString();
  330. XmlUtil xmlUtil = new XmlUtil();
  331. Map<String, Object> resMap = xmlUtil.parseb(result, "ant.mybank.bkmerchanttrade.prePayNotice");
  332. System.out.println("通知报文:" + resMap.toString());
  333. //支付宝或微信订单号 PayChannelOrderNo
  334. String payOrderno = resMap.get("PayChannelOrderNo").toString();
  335. //我方订单号 OutTradeNo
  336. String orderno = resMap.get("OutTradeNo").toString();
  337. //实付金额 BuyerPayAmount TotalAmount
  338. String amt = resMap.get("TotalAmount").toString();
  339. amt = CommonUtil.divide(amt,"100");
  340. //第三方订单号 OrderNo
  341. String sysorderno = resMap.get("OrderNo").toString();
  342. //查询订单如果已支付状态表示已经回调过
  343. //调用真实回调
  344. backEx(orderno, sysorderno, "TRADE_SUCCESS", amt,payOrderno, "", "");
  345. return res;
  346. }
  347. /**
  348. * 回调真实执行方法
  349. * @param orderno 商户流水号(订单)
  350. * @param sysorderno 交易流水号
  351. * @param status 状态
  352. * @param amt 交易金额
  353. * @param failReason 失败原因
  354. * @param payChannel 支付通道(04快捷支付 91微信支付92支付宝支付 93钱包支付)
  355. * @throws Exception
  356. */
  357. private void backEx(
  358. String orderno,
  359. String sysorderno,
  360. String status,
  361. String amt,
  362. String payOrderno,
  363. String failReason,
  364. String payChannel) throws Exception {
  365. // 交易流水号
  366. VmPaymentInfExample paymentExp = new VmPaymentInfExample();
  367. paymentExp.createCriteria().andTranflownoEqualTo(orderno);
  368. List<VmPaymentInf> payMentList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).selectByExample(paymentExp);
  369. if(payMentList.size() == 0) {
  370. throw new MINBusinessException("error");
  371. }
  372. // 0 初始状态 --如果已经通知过返回
  373. // 3在途
  374. if(!"0".equals(payMentList.get(0).getStatus())
  375. && !"3".equals(payMentList.get(0).getStatus())) {
  376. throw new MINBusinessException("error");
  377. }
  378. VmPaymentInf payMentInf = new VmPaymentInf();
  379. payMentInf.setBankflowno(sysorderno);
  380. // 支付方式(01 账户支付、02 预付卡支付、03 网银支付、04快捷支付 91微信支付92支付宝支付)
  381. if(CommonUtil.isNotEmpty(payChannel)) {
  382. payMentInf.setPaytype(payChannel);
  383. }
  384. VmOrderInf orderInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).selectByPrimaryKey(orderno);
  385. orderInf.setState("92"); // 92:支付中
  386. // TRADE_SUCCESS:交易成功,用户付款成功
  387. // TRADE_FINISHED:交易结束,付款金额已结算给商户
  388. // TRADE_CLOSED:交易关闭,交易失败
  389. if("TRADE_SUCCESS".equals(status)
  390. || "TRADE_FINISHED".equals(status)) {
  391. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  392. payMentInf.setStatus("1");
  393. payMentInf.setSuccamount(amt);//支付成功返还金额
  394. //支付成功时间
  395. payMentInf.setSucctime(DateUtil.getCurrentDateTimeString());
  396. orderInf.setState("00"); // 00:已支付
  397. orderInf.setPayOrderno(payOrderno); // 支付平台订单号(微信、支付宝订单号)
  398. }
  399. else if("TRADE_CLOSED".equals(status)) {
  400. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  401. payMentInf.setStatus("2");
  402. orderInf.setState("93"); // 93:支付失败
  403. }
  404. // 不是空
  405. if(!CommonUtil.isEmpty(failReason)) {
  406. payMentInf.setRemarktwo(failReason);
  407. }
  408. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).updateByExampleSelective(payMentInf, paymentExp);
  409. // 变更待结算账户
  410. IAccountService service = Service.lookup(IAccountService.class);
  411. orderInf.setId(orderno);
  412. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(orderInf);
  413. if("00".equals(orderInf.getState())){
  414. if("01".equals(orderInf.getProType())){
  415. //抽奖的商品走这里
  416. OrderDrawAction drawAction = new OrderDrawAction();
  417. drawAction.editOrderDraw(orderInf,sysorderno);
  418. }else if("00".equals(orderInf.getProType())){
  419. //购买商品走这里
  420. DeliveryAction.purchaseCreateDeliveryInfo(orderno,"");
  421. //执行推货
  422. // toMachine(orderInf.getChannel(), orderno);
  423. }
  424. // 充值
  425. else if("02".equals(orderInf.getProType())) {
  426. // 00充值(CZ)
  427. service.modfiyAccount(orderInf.getChannel(), orderInf.getPersonId(), "01", amt, "00", payMentList.get(0).getFlowno(), "充值");
  428. }
  429. }
  430. }
  431. //推货方法
  432. private void toMachine(String channel , String orderNo) throws Exception{
  433. String url = Service.lookup(IPropertiesService.class)
  434. .getSystemProperties().get(channel + "_GET_MACHINE_ADDRESS").getKey();
  435. String retUrl = Service.lookup(IPropertiesService.class)
  436. .getSystemProperties().get(channel + "_RETURN_MACHINE_ADDRESS").getKey();
  437. //组装推送接口
  438. String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON");
  439. String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine");
  440. //组装传送参数
  441. //初始化查询条件
  442. Map<String,String> map = new HashMap<String,String>();
  443. map.put("orderNo", orderNo);//订单编号
  444. //传入渠道验证
  445. map.put("channel", channel);
  446. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  447. .getMybatisMapper(DeliveryMapper.class)
  448. .queryDeliverys(map);
  449. if(list != null && list.size() > 0){
  450. Map<String,String> mapNew = new HashMap<String,String>();
  451. mapNew.put("imeiAddr", list.get(0).get("equIMEI"));
  452. mapNew.put("cargoNo", list.get(0).get("cargoWay"));
  453. mapNew.put("deliveryNo", list.get(0).get("delveryNo"));
  454. mapNew.put("channel", channel);
  455. mapNew.put("returnUrl", returnUrl);
  456. mapNew.put("MINView", "JSON");
  457. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  458. String str = jsonOb.toString();
  459. String passwardKey = Service.lookup(IPropertiesService.class)
  460. .getSystemProperties().get(channel +"_TO_MACHINE_PASSWORD_KEY").getKey();
  461. //数据加密
  462. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  463. //调用通用通讯接口
  464. String results = HttpPostUtil.sendPostFormachine(sendUrl,desDe);
  465. //获取转义后响应信息
  466. JSONObject detail = JSONObject.fromObject(results);
  467. String code = String.valueOf(detail.get("code"));
  468. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  469. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(list.get(0).get("delveryNo"));
  470. if(!"0".equals(code)){
  471. //改变提货状态为3卡货(提货失败)....
  472. delInf.setStatus("3");
  473. //throw new BusinessCodeException("JINM0011");//操作失败!
  474. }else{
  475. //获取处理状态
  476. String state = String.valueOf(detail.get("returnData"));
  477. JSONObject stateNew = JSONObject.fromObject(state);
  478. if("200".equals(stateNew.get("code"))){
  479. //改变提货状态为5处理中....
  480. delInf.setStatus("5");
  481. }else{
  482. //改变提货状态为3处理中....
  483. delInf.setStatus("3");
  484. //String msg = String.valueOf(stateNew.get("msg"));
  485. //throw new MINBusinessException(msg);//操作失败!
  486. }
  487. }
  488. //处理提货状态
  489. Service.lookup(IMINDataBaseService.class)
  490. .getMybatisMapper(VmDeliveryInfMapper.class)
  491. .updateByPrimaryKeySelective(delInf);
  492. }else{
  493. throw new MINBusinessException("没有提货信息!");
  494. }
  495. }
  496. }