|
@@ -1,8 +1,12 @@
|
|
package com.usky.dxtop.service.api;
|
|
package com.usky.dxtop.service.api;
|
|
|
|
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.TreeMap;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.usky.dxtop.common.utils.StringUtils;
|
|
|
|
+import com.usky.dxtop.common.utils.http.HttpUtils;
|
|
|
|
+import com.usky.dxtop.common.utils.sign.Md5Utils;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yq
|
|
* @author yq
|
|
@@ -10,260 +14,123 @@ import java.util.TreeMap;
|
|
*/
|
|
*/
|
|
public class OneCardApi {
|
|
public class OneCardApi {
|
|
|
|
|
|
- private static final String URL = "http://183.129.209.98:19001";
|
|
|
|
|
|
+ private static final String URL = "http://10.208.2.158:7002/";
|
|
|
|
|
|
private static final Integer VERSION = 3;
|
|
private static final Integer VERSION = 3;
|
|
- /**
|
|
|
|
- * 寻卡地址
|
|
|
|
- */
|
|
|
|
- private static final String FIND_URL = String.format("%s/%s",URL,"partner/find");
|
|
|
|
- /**
|
|
|
|
- * 读卡
|
|
|
|
- */
|
|
|
|
- private static final String GET_CARD_URL = String.format("%s/%s",URL,"partner/get");
|
|
|
|
- /**
|
|
|
|
- * 卡消费
|
|
|
|
- */
|
|
|
|
- private static final String PAY_URL = String.format("%s/%s",URL,"partner/pay");
|
|
|
|
- /**
|
|
|
|
- * 卡消费撤单
|
|
|
|
- */
|
|
|
|
- private static final String UN_PAY_URL = String.format("%s/%s",URL,"partner/unpay");
|
|
|
|
- /**
|
|
|
|
- * 卡充值
|
|
|
|
- */
|
|
|
|
- private static final String CHARGE = String.format("%s/%s",URL,"partner/change");
|
|
|
|
- /**
|
|
|
|
- * 取消卡充值
|
|
|
|
- */
|
|
|
|
- private static final String UN_CHANGE = String.format("%s/%s",URL,"partner/unchange");
|
|
|
|
- /**
|
|
|
|
- * 查看终端的充值和消费流水(含撤单)
|
|
|
|
- */
|
|
|
|
- private static final String RECONCILIATION = String.format("%s/%s",URL,"partner/reconciliation");
|
|
|
|
- /**
|
|
|
|
- * 卡日志查询
|
|
|
|
- */
|
|
|
|
- private static final String LOGS = String.format("%s/%s",URL,"partner/logs");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private static final String SHOP = "";
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private static final String TERM = "";
|
|
|
|
-
|
|
|
|
- private static final String OPER = "";
|
|
|
|
|
|
|
|
|
|
+ public static final String CARD_LOSS_url = String.format("%s%s",URL,"partner/card/loss");
|
|
|
|
|
|
|
|
+ public static final String CARD_REISSUE = String.format("%s%s",URL,"caih/reissue");
|
|
/**
|
|
/**
|
|
- * 公用的请求参数
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 餐厅编号
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getCommonParam(){
|
|
|
|
- TreeMap<String, Object> tMap = new TreeMap<>();
|
|
|
|
- tMap.put("v",3);
|
|
|
|
- tMap.put("d",new Date());
|
|
|
|
- tMap.put("shop",3);
|
|
|
|
- tMap.put("term",3);
|
|
|
|
- tMap.put("oper",3);
|
|
|
|
- tMap.put("format","json");
|
|
|
|
- return tMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ private static final String SHOP = "101";
|
|
/**
|
|
/**
|
|
- * 寻卡参数
|
|
|
|
- * @param t (11按卡号,21按唯一识别号,22 按姓名,23 按身份证号,24 按订餐手机号)
|
|
|
|
- * @param q
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 终端编号
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getFindParam(Integer t,String q){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("t",t);
|
|
|
|
- commonParam.put("q",q);
|
|
|
|
- return commonParam;
|
|
|
|
- }
|
|
|
|
|
|
+ private static final String TERM = "108";
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 读卡
|
|
|
|
- * @param cid 物理卡号
|
|
|
|
- * @param cno 交易卡面编码
|
|
|
|
- * @param account 是否需要获取多账户信息:可选参数,如传值必须传入 all
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 终端操作员
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getReadCardParam(String cid,String cno,String account){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("account",account);
|
|
|
|
- return commonParam;
|
|
|
|
- }
|
|
|
|
|
|
+ private static final String OPER = "admin";
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 卡消费
|
|
|
|
- * @param cid 物理卡号
|
|
|
|
- * @param cno 交易卡面编码
|
|
|
|
- * @param amt 交易金额
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static TreeMap<String, Object> getPayParam(String cid,String cno,Double amt,Long invoice){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("amt",amt);
|
|
|
|
- commonParam.put("invoice",invoice);
|
|
|
|
- return commonParam;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ private static final String KEY = "951b19605fce4132bd40fbfe3f85a1a6";
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 卡充值撤销
|
|
|
|
- * @param cid
|
|
|
|
- * @param cno
|
|
|
|
- * @param seq 编号
|
|
|
|
- * @param amt 退还金额
|
|
|
|
|
|
+ * 公用请求
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getUnPayParam(String cid,String cno,Long seq,Double amt){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("amt",amt);
|
|
|
|
- commonParam.put("seq",seq);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static TreeMap<String,String> commonParam(){
|
|
|
|
+ TreeMap<String,String> treeMap = new TreeMap<>();
|
|
|
|
+ treeMap.put("shop",SHOP);
|
|
|
|
+ treeMap.put("term",TERM);
|
|
|
|
+ treeMap.put("oper",OPER);
|
|
|
|
+ treeMap.put("d",new Date().toString());
|
|
|
|
+ return treeMap;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 卡充值
|
|
|
|
|
|
+ * 卡挂失
|
|
* @param cid
|
|
* @param cid
|
|
* @param cno
|
|
* @param cno
|
|
- * @param amt 金额
|
|
|
|
- * @param invoice
|
|
|
|
- * @param cashbox 钱箱参数4支付表5微信
|
|
|
|
|
|
+ * @param msg
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getChargeParam(String cid,String cno,Double amt,Long invoice,Integer cashbox){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("amt",amt);
|
|
|
|
- commonParam.put("cashbox",cashbox);
|
|
|
|
- commonParam.put("invoice",invoice);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static TreeMap<String,String> cardLoss(String cid,String cno,String msg){
|
|
|
|
+ TreeMap<String, String> treeMap = commonParam();
|
|
|
|
+ treeMap.put("cid",cid);
|
|
|
|
+ treeMap.put("cno",cno);
|
|
|
|
+ treeMap.put("msg",msg);
|
|
|
|
+ List<String> paramList = getParamList(treeMap);
|
|
|
|
+ treeMap.put("sig",sign(paramList));
|
|
|
|
+ return treeMap;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 取消卡充值
|
|
|
|
- * @param cid
|
|
|
|
- * @param cno
|
|
|
|
- * @param amt
|
|
|
|
- * @param msg 取消原因
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static TreeMap<String, Object> getUnChargeParam(String cid,String cno,Double amt,String msg){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("amt",amt);
|
|
|
|
- commonParam.put("cashbox",msg);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static TreeMap<String,String> cardReissue(String cid,String cidNew){
|
|
|
|
+ TreeMap<String, String> treeMap = commonParam();
|
|
|
|
+ treeMap.put("cid",cid);
|
|
|
|
+ treeMap.put("cid_new",cidNew);
|
|
|
|
+ treeMap.put("v", String.valueOf(VERSION));
|
|
|
|
+ treeMap.put("format", "json");
|
|
|
|
+ List<String> paramList = getParamList(treeMap);
|
|
|
|
+ treeMap.put("sig",sign(paramList));
|
|
|
|
+ return treeMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 终端的充值,消费,撤单记录
|
|
|
|
- * @param date 日期
|
|
|
|
- * @param pi 页数
|
|
|
|
- * @param ps 条数
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static TreeMap<String, Object> getReconciliationParam(Integer date,Integer pi,Integer ps){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("date",date);
|
|
|
|
- commonParam.put("pi",pi);
|
|
|
|
- commonParam.put("ps",ps);
|
|
|
|
- return commonParam;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 卡日志查询
|
|
|
|
- * @param t (1 查询卡消费日志(包含消费撤单日志),2 查询卡充值日志(包含充值撤单日志),3 查询卡消费和充值日志(包含消费和充值撤
|
|
|
|
- * 单日志)4 查询卡事务日志(不含消费和充值的其它相
|
|
|
|
- * 关日志))
|
|
|
|
- * @param cid
|
|
|
|
- * @param cno
|
|
|
|
- * @param account
|
|
|
|
- * @param pi
|
|
|
|
- * @param ps
|
|
|
|
|
|
+ * 验签
|
|
|
|
+ * @param list
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getCardLogsParam(Integer t,String cid,String cno,Integer account,Integer pi,Integer ps){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("t",t);
|
|
|
|
- commonParam.put("cid",cid);
|
|
|
|
- commonParam.put("cno",cno);
|
|
|
|
- commonParam.put("account",account);
|
|
|
|
- commonParam.put("pi",pi);
|
|
|
|
- commonParam.put("ps",ps);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static String sign(List<String> list){
|
|
|
|
+ String[] strs = new String[list.size()];
|
|
|
|
+ list.toArray(strs);
|
|
|
|
+ Arrays.sort(strs , String.CASE_INSENSITIVE_ORDER);
|
|
|
|
+ String str = "";
|
|
|
|
+ for(int i=0; i < strs.length; i++) str += strs[i];
|
|
|
|
+ str += KEY;
|
|
|
|
+ return Md5Utils.hash(str);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 日期查询卡消费日志
|
|
|
|
- * @param t
|
|
|
|
- * @param cid
|
|
|
|
- * @param cno
|
|
|
|
- * @param account
|
|
|
|
- * @param sd
|
|
|
|
- * @param ed
|
|
|
|
- * @param pi
|
|
|
|
- * @param ps
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static TreeMap<String, Object> getCardLogsByDateParam(Integer t,String cid,String cno,Integer account,
|
|
|
|
- Date sd,Date ed
|
|
|
|
- ,Integer pi,Integer ps){
|
|
|
|
- TreeMap<String, Object> commonParam = getCardLogsParam(t, cid, cno, account, pi, ps);
|
|
|
|
- commonParam.put("sd",sd);
|
|
|
|
- commonParam.put("ed",ed);
|
|
|
|
- return commonParam;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 全部日志
|
|
|
|
- * @param t
|
|
|
|
- * @param account
|
|
|
|
- * @param sd
|
|
|
|
- * @param ed
|
|
|
|
- * @param pi
|
|
|
|
- * @param ps
|
|
|
|
|
|
+ * 获取list请求参数
|
|
|
|
+ * @param params
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getCardLogsByAllParam(Integer t,Integer account, Date sd,Date ed,Integer pi,Integer ps){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("t",t);
|
|
|
|
- commonParam.put("account",account);
|
|
|
|
- commonParam.put("pi",pi);
|
|
|
|
- commonParam.put("ps",ps);
|
|
|
|
- commonParam.put("sd",sd);
|
|
|
|
- commonParam.put("ed",ed);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static List<String> getParamList(TreeMap<String, String> params){
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
|
+ StringBuilder buf = new StringBuilder();
|
|
|
|
+ if (!StringUtils.isBlank(entry.getValue()) && !"sign".equals(entry.getKey())) {
|
|
|
|
+ list.add(buf.append(entry.getKey()).append("=").append(entry.getValue()).toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 卡支付二维码
|
|
|
|
- * @param cid
|
|
|
|
- * @param timeOut
|
|
|
|
- * @param unique
|
|
|
|
|
|
+ * 拼接请求参数
|
|
|
|
+ * @param params
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static TreeMap<String, Object> getCardQrCodeParam(String cid,Integer timeOut,String unique){
|
|
|
|
- TreeMap<String, Object> commonParam = getCommonParam();
|
|
|
|
- commonParam.put("t",cid);
|
|
|
|
- commonParam.put("account",timeOut);
|
|
|
|
- commonParam.put("pi",unique);
|
|
|
|
- return commonParam;
|
|
|
|
|
|
+ public static String joinParam(TreeMap<String, String> params){
|
|
|
|
+ StringBuilder buf = new StringBuilder();
|
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
|
+ String value = "";
|
|
|
|
+ if (StringUtils.isNotBlank(entry.getValue())){
|
|
|
|
+ value = entry.getValue();
|
|
|
|
+ }
|
|
|
|
+ if (!"sign".equals(entry.getKey())) {
|
|
|
|
+ buf.append(entry.getKey()).append("=").append(value).append("&");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String changeBuf = buf.toString();
|
|
|
|
+ return changeBuf.substring(0, changeBuf.length() - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|