|
@@ -0,0 +1,146 @@
|
|
|
+package cn.hnthyy.thmz.service.impl.thmz;
|
|
|
+
|
|
|
+import cn.hnthyy.thmz.Utils.HttpUtil;
|
|
|
+import cn.hnthyy.thmz.common.Constants;
|
|
|
+import cn.hnthyy.thmz.entity.MzException;
|
|
|
+import cn.hnthyy.thmz.service.thmz.TransactionService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class TransactionServiceImpl implements TransactionService {
|
|
|
+ @Value("${misPossUrl}")
|
|
|
+ private String misPossUrl;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject sign(String routerCode) {
|
|
|
+ log.info("调用智能POS签到接口,路由识别码={}", routerCode);
|
|
|
+ String realUrl = misPossUrl + "sign";
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //Map 对象存入
|
|
|
+ map.put("routerCode", routerCode);
|
|
|
+ //Map 转成 JSONObject 字符串
|
|
|
+ JSONObject jsonObj = new JSONObject(map);
|
|
|
+ try {
|
|
|
+ String result = HttpUtil.sendHttpPost(realUrl, jsonObj.toString(), 120000);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new JSONObject(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("调用智能POS签到接口,路由识别码={}", routerCode);
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject balance(String routerCode) {
|
|
|
+ log.info("调用智能POS查余接口,路由识别码={}", routerCode);
|
|
|
+ String realUrl = misPossUrl + "balance";
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //Map 对象存入
|
|
|
+ map.put("routerCode", routerCode);
|
|
|
+ //Map 转成 JSONObject 字符串
|
|
|
+ JSONObject jsonObj = new JSONObject(map);
|
|
|
+ try {
|
|
|
+ String result = HttpUtil.sendHttpPost(realUrl, jsonObj.toString(), 120000);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new JSONObject(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("调用智能POS查余接口,路由识别码={}", routerCode);
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject consume(String routerCode, double amt, String lsOrderNo, String inputRemarkInfo, String chequeType) throws MzException {
|
|
|
+ String realUrl;
|
|
|
+ String type;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if(Constants.YLK.equals(chequeType)){
|
|
|
+ type= "消费";
|
|
|
+ realUrl = misPossUrl + "consume";
|
|
|
+ }else if(Constants.WX.equals(chequeType) || Constants.ZFB.equals(chequeType)){
|
|
|
+ type= "聚合支付";
|
|
|
+ realUrl = misPossUrl + "onlinePayment";
|
|
|
+ map.put("qrCodeParam", "");
|
|
|
+ }else {
|
|
|
+ throw new MzException("当前支付方式无法发起智能银行收款!");
|
|
|
+ }
|
|
|
+ log.info("调用智能POS{}接口,路由识别码={}", type, routerCode);
|
|
|
+ //Map 对象存入
|
|
|
+ map.put("routerCode", routerCode);
|
|
|
+ map.put("amt", amt);
|
|
|
+ map.put("isNeedPrintReceipt", false);
|
|
|
+ map.put("counterNo", "");
|
|
|
+ map.put("orderNo", "");
|
|
|
+ map.put("orderNo", "");
|
|
|
+ map.put("lsOrderNo", lsOrderNo);
|
|
|
+ map.put("inputRemarkInfo", inputRemarkInfo==null?"":inputRemarkInfo);
|
|
|
+ map.put("remarkSize", 0);
|
|
|
+ //Map 转成 JSONObject 字符串
|
|
|
+ JSONObject jsonObj = new JSONObject(map);
|
|
|
+ try {
|
|
|
+ String result = HttpUtil.sendHttpPost(realUrl, jsonObj.toString(), 120000);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new JSONObject(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("调用智能POS{}接口,路由识别码={}",type, routerCode);
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject refund(String routerCode, double amt, String lsOrderNo, String inputRemarkInfo, String chequeType, String orgRefNo, String transDate) throws MzException {
|
|
|
+ String realUrl;
|
|
|
+ String type;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if(Constants.YLK.equals(chequeType)){
|
|
|
+ type= "退货";
|
|
|
+ realUrl = misPossUrl + "refund";
|
|
|
+ map.put("orgRefNo", orgRefNo);
|
|
|
+ map.put("transDate", transDate);
|
|
|
+ }else if(Constants.WX.equals(chequeType) || Constants.ZFB.equals(chequeType)){
|
|
|
+ type= "聚合支付退款";
|
|
|
+ realUrl = misPossUrl + "onlineRefund";
|
|
|
+ map.put("qrCodeParam", "");
|
|
|
+ }else {
|
|
|
+ throw new MzException("当前支付方式无法发起智能银行退款!");
|
|
|
+ }
|
|
|
+ log.info("调用智能POS{}接口,路由识别码={}", type, routerCode);
|
|
|
+ //Map 对象存入
|
|
|
+ map.put("routerCode", routerCode);
|
|
|
+ map.put("amt", amt);
|
|
|
+ map.put("isNeedPrintReceipt", false);
|
|
|
+ map.put("lsOrderNo", lsOrderNo);
|
|
|
+ map.put("inputRemarkInfo", inputRemarkInfo==null?"":inputRemarkInfo);
|
|
|
+ map.put("remarkSize", 0);
|
|
|
+ //Map 转成 JSONObject 字符串
|
|
|
+ JSONObject jsonObj = new JSONObject(map);
|
|
|
+ try {
|
|
|
+ String result = HttpUtil.sendHttpPost(realUrl, jsonObj.toString(), 120000);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new JSONObject(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("调用智能POS{}接口,路由识别码={}",type, routerCode);
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|