Jelajahi Sumber

测试一卡通

yq 3 tahun lalu
induk
melakukan
0853a054ef

+ 1 - 1
src/main/java/com/usky/dxtop/common/constant/UserConstants.java

@@ -76,5 +76,5 @@ public class UserConstants
     public static final int PASSWORD_MIN_LENGTH = 5;
     public static final int PASSWORD_MAX_LENGTH = 20;
 
-    public static final String ACCOUNT_LOCK = "lock_account_";
+    public static final String ACCOUNT_LOCK = "top_lock_account_";
 }

+ 52 - 0
src/main/java/com/usky/dxtop/controller/web/business/TestController.java

@@ -0,0 +1,52 @@
+package com.usky.dxtop.controller.web.business;
+
+import com.alibaba.fastjson.JSONObject;
+import com.usky.dxtop.common.utils.http.HttpUtils;
+import com.usky.dxtop.model.Staff;
+import com.usky.dxtop.service.StaffService;
+import com.usky.dxtop.service.api.OneCardApi;
+import com.usky.dxtop.service.api.SmApi;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+@RestController
+@RequestMapping("/test")
+public class TestController {
+
+
+
+    @Autowired
+    private StaffService staffService;
+
+    @GetMapping("/cardLoss")
+    public String testCardLoss(@RequestParam String cid, @RequestParam String cno, @RequestParam String msg){
+        TreeMap<String, String> param = OneCardApi.cardLoss(cid, cno, msg);
+        Map<String,String> map = new HashMap<>();
+        map.put("Content-Type","application/x-www-form-urlencoded");
+        String result = HttpUtils.sendPost(OneCardApi.CARD_LOSS_url,OneCardApi.joinParam(param), map);
+        return result;
+    }
+    @GetMapping("/cardReissue")
+    public String testCardReissue(@RequestParam String cid,@RequestParam String cidNew){
+        TreeMap<String, String> param = OneCardApi.cardReissue(cid, cidNew);
+        Map<String,String> map = new HashMap<>();
+        map.put("Content-Type","application/x-www-form-urlencoded");
+        String result = HttpUtils.sendPost(OneCardApi.CARD_REISSUE,OneCardApi.joinParam(param), map);
+        return result;
+    }
+
+    @GetMapping("/sendStaff")
+    public String sendStaff(@RequestParam Long staffId,@RequestParam String card,@RequestParam Integer type){
+        Staff staff = staffService.getById(staffId);
+        staff.setCardId(card);
+        staffService.personSendMessage(staff,type);
+        return "";
+    }
+}

+ 19 - 3
src/main/java/com/usky/dxtop/controller/web/business/WxController.java

@@ -1,6 +1,10 @@
 package com.usky.dxtop.controller.web.business;
 
 import com.usky.dxtop.common.core.domain.ApiResult;
+import com.usky.dxtop.common.exception.CustomException;
+import com.usky.dxtop.common.utils.StringUtils;
+import com.usky.dxtop.model.Staff;
+import com.usky.dxtop.service.StaffService;
 import com.usky.dxtop.service.api.TopApiConfiger;
 import com.usky.dxtop.service.api.WxApi;
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +13,9 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.crypto.spec.OAEPParameterSpec;
+import java.util.Optional;
+
 /**
  * 微信
  * @author yq
@@ -24,6 +31,9 @@ public class WxController {
     @Autowired
     private WxApi wxApi;
 
+    @Autowired
+    private StaffService staffService;
+
     /**
      * 微信登录
      * @param jsCode
@@ -61,18 +71,24 @@ public class WxController {
 
     /**
      * 公众号进行消息推送
-     * @param openId
+     * @param userId
      * @param data
      * @param templateId
      * @param detailUrl
      * @return
      */
     @GetMapping("/offSendMessage")
-    public ApiResult<String> offSendMessageT(@RequestParam String openId,
+    public ApiResult<String> offSendMessageT(@RequestParam String userId,
                                      @RequestParam Object data,
                                      @RequestParam String templateId,
                                      @RequestParam(required = false) String detailUrl){
-        return ApiResult.success(wxApi.sendMessageApi(openId, data, wxApi.getToken(WxApi.APP_ID, WxApi.SECRET), templateId, detailUrl));
+        Staff staff = staffService.one(userId, null, null);
+        return Optional.ofNullable(staff).map(s  -> {
+                    if (StringUtils.isBlank(s.getOpenId())){
+                        throw new CustomException("用户没有绑定openid,绑定后再进行操作");
+                    }
+                    return ApiResult.success(wxApi.sendMessageApi(staff.getOpenId(), data, wxApi.getToken(WxApi.APP_ID, WxApi.SECRET), templateId, detailUrl));
+                }).orElseThrow(() -> new CustomException("用户信息不存在"));
     }
 
     /**

+ 1 - 0
src/main/java/com/usky/dxtop/framework/web/service/SysLoginService.java

@@ -1,5 +1,6 @@
 package com.usky.dxtop.framework.web.service;
 
+import com.alibaba.fastjson.JSON;
 import com.usky.dxtop.common.constant.Constants;
 import com.usky.dxtop.common.constant.UserConstants;
 import com.usky.dxtop.common.core.domain.model.LoginUser;

+ 80 - 213
src/main/java/com/usky/dxtop/service/api/OneCardApi.java

@@ -1,8 +1,12 @@
 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
@@ -10,260 +14,123 @@ import java.util.TreeMap;
  */
 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 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
      */
-    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 cno
-     * @param amt 金额
-     * @param invoice
-     * @param cashbox 钱箱参数4支付表5微信
+     * @param msg
      * @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
      */
-    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
      */
-    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
      */
-    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);
     }
 }