ShouhuoPay.java 22 KB

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