|
@@ -0,0 +1,120 @@
|
|
|
+package com.usky.dxtop.service.api;
|
|
|
+
|
|
|
+import com.sun.org.apache.regexp.internal.RE;
|
|
|
+import com.usky.dxtop.common.utils.DateUtils;
|
|
|
+import com.usky.dxtop.common.utils.StringUtils;
|
|
|
+import com.usky.dxtop.common.utils.sign.Md5Utils;
|
|
|
+import org.apache.poi.ss.usermodel.DateUtil;
|
|
|
+
|
|
|
+import java.awt.font.ShapeGraphicAttribute;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/8/23 14:50
|
|
|
+ */
|
|
|
+public class TopApi {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 版本
|
|
|
+ */
|
|
|
+ private static final String VERSION = "v1.0";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫码支付
|
|
|
+ */
|
|
|
+ private static final String SCAN_TO_PAY_URL = "https://interfacetest.allinpaygx.com/api/access/payInterface/usePaymentCode";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商户编号
|
|
|
+ */
|
|
|
+ private static final String MERCHANT_NO = "121050000103";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 密钥
|
|
|
+ */
|
|
|
+ private static final String SECRET = "0341dff192f644b5892338f0d964a6b2";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回调url
|
|
|
+ */
|
|
|
+ private static final String SCAN_NOTIFY_URL = "https://wx.ewoogi.com/dxapi/test";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接扫码支付
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static TreeMap<String, String> generateScanPayApiParam(String orderNo, Integer amount, String note,
|
|
|
+ String storeNo, String backUrl, String orderNumber,
|
|
|
+ String validTime, String remark, String goods){
|
|
|
+ TreeMap<String, String> tMap = new TreeMap<>();
|
|
|
+ tMap.put("version",VERSION);
|
|
|
+ tMap.put("payTime",DateUtils.dateTimeNow());
|
|
|
+ tMap.put("merchantNo",MERCHANT_NO);
|
|
|
+ tMap.put("merchantOrderNo",orderNo);
|
|
|
+ tMap.put("amount",amount.toString());
|
|
|
+ tMap.put("note",note);
|
|
|
+ tMap.put("storeNo",storeNo);
|
|
|
+ tMap.put("backUrl",backUrl);
|
|
|
+ tMap.put("orderNumber",orderNumber);
|
|
|
+ tMap.put("validTime",validTime);
|
|
|
+ tMap.put("remark",remark);
|
|
|
+ tMap.put("notifyUrl",SCAN_NOTIFY_URL);
|
|
|
+ tMap.put("goods",goods);
|
|
|
+ return tMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫码支付api
|
|
|
+ * @param orderNo
|
|
|
+ * @param amount
|
|
|
+ * @param note
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String generateScanPayApi(String orderNo,Integer amount,String note){
|
|
|
+ TreeMap<String, String> params = generateScanPayApiParam(orderNo, amount, note,
|
|
|
+ null,null,null,null,null,null);
|
|
|
+ StringBuilder buf = new StringBuilder();
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ if (!StringUtils.isBlank(entry.getValue()) && !"sign".equals(entry.getKey())) {
|
|
|
+ buf.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String changeBuf = buf.toString();
|
|
|
+ String substring = changeBuf.substring(0, changeBuf.length() - 1);
|
|
|
+ return String.format("%s?%s&sign=%s",SCAN_TO_PAY_URL,
|
|
|
+ substring,
|
|
|
+ signData(params));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 参数加签
|
|
|
+ * 参数加签规则,key+value拼接(value为空时,key value不参与拼接),以key首字母ascii码排序,最后拼接上secret串再进行MD5加密,得到的MD5密钥字母转大写,例:amount1merchantNo1210500001030341dff192f644b5892338f0d964a6b2
|
|
|
+ * @param treeMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String signData(Map<String, String> treeMap) {
|
|
|
+ StringBuilder buf = new StringBuilder();
|
|
|
+ for (Map.Entry<String, String> entry : treeMap.entrySet()) {
|
|
|
+ if (!StringUtils.isBlank(entry.getValue()) && !"sign".equals(entry.getKey())) {
|
|
|
+ buf.append(entry.getKey()).append(entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buf.append(SECRET);
|
|
|
+ return Md5Utils.hash(buf.toString()).toUpperCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验签
|
|
|
+ * @param treeMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean validSign(Map<String, String> treeMap){
|
|
|
+ String validSign = treeMap.get("sign");
|
|
|
+ String sign = signData(treeMap);
|
|
|
+ return validSign != null && validSign.equals(sign) && "".equals(validSign);
|
|
|
+ }
|
|
|
+}
|