From f96ce14854ee14229282a3adc5c1467fcafdf210 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 5 Jul 2021 14:49:06 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cweb/controller/HighTestController.java | 17 ++++- .../java/com/hai/config/CommonSysConfig.java | 44 ++++++++++--- .../java/com/hai/config/QianZhuConfig.java | 65 +++++++++++++++++++ .../resources/dev/commonConfig.properties | 10 ++- .../resources/prod/commonConfig.properties | 6 +- 5 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/config/QianZhuConfig.java diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java index ea43b460..bdc0108d 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java @@ -5,7 +5,9 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.*; +import com.hai.config.QianZhuConfig; import com.hai.config.TuanYouConfig; import com.hai.entity.*; import com.hai.model.HighMerchantModel; @@ -14,6 +16,7 @@ import com.hai.model.ResponseData; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -21,7 +24,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.Date; +import java.util.*; /** * @Auther: 胡锐 @@ -158,4 +161,16 @@ public class HighTestController { + @RequestMapping(value = "/test1", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "测试") + public ResponseData test1() { + try { + return ResponseMsgUtil.success(QianZhuConfig.getToken("user"+new Date().getTime(), "user"+new Date().getTime(), "17726395120")); + } catch (Exception e) { + log.error("HighOrderController --> getOrderById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java index 19b21ed4..d72a8eae 100644 --- a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java +++ b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java @@ -15,15 +15,11 @@ public class CommonSysConfig { private String tuanYouDieselAccount; // 柴油账号 private String tuanYouGasolineAccount; // 汽油账号 - private String wx_cert; - - public String getWx_cert() { - return wx_cert; - } + private String qinzhuUrl; + private String qinzhuPlatformId; + private String qinzhuSecret; - public void setWx_cert(String wx_cert) { - this.wx_cert = wx_cert; - } + private String wx_cert; public String getTuanYouUrl() { return tuanYouUrl; @@ -64,4 +60,36 @@ public class CommonSysConfig { public void setTuanYouGasolineAccount(String tuanYouGasolineAccount) { this.tuanYouGasolineAccount = tuanYouGasolineAccount; } + + public String getQinzhuUrl() { + return qinzhuUrl; + } + + public void setQinzhuUrl(String qinzhuUrl) { + this.qinzhuUrl = qinzhuUrl; + } + + public String getQinzhuPlatformId() { + return qinzhuPlatformId; + } + + public void setQinzhuPlatformId(String qinzhuPlatformId) { + this.qinzhuPlatformId = qinzhuPlatformId; + } + + public String getQinzhuSecret() { + return qinzhuSecret; + } + + public void setQinzhuSecret(String qinzhuSecret) { + this.qinzhuSecret = qinzhuSecret; + } + + public String getWx_cert() { + return wx_cert; + } + + public void setWx_cert(String wx_cert) { + this.wx_cert = wx_cert; + } } diff --git a/hai-service/src/main/java/com/hai/config/QianZhuConfig.java b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java new file mode 100644 index 00000000..a8ed897c --- /dev/null +++ b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java @@ -0,0 +1,65 @@ +package com.hai.config; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.pay.util.sdk.WXPayConstants; +import com.hai.common.utils.HttpsUtils; +import com.hai.common.utils.MD5Util; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.model.ResponseData; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.*; + +/** + * @author hurui + * @version 1.0 + * @ClassName QianZhuConfig + * @description: 千猪接口配置 + * @date 2021/7/5 14:18 + */ +public class QianZhuConfig { + + + @RequestMapping(value = "/getToken", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取用户token") + public static JSONObject getToken(String platformUniqueId,String nickname,String mobile) throws Exception { + Map map = new HashMap<>(); + map.put("platformId", CommonSysConst.getSysConfig().getQinzhuPlatformId()); + map.put("timestamp", new Date().getTime()); + map.put("platformUniqueId", platformUniqueId); + map.put("nickname", nickname); + map.put("mobile", mobile); + map.put("sign", MD5Util.encode(generateSignature(map,CommonSysConst.getSysConfig().getQinzhuSecret()).getBytes()).toLowerCase()); + return HttpsUtils.doGet(CommonSysConst.getSysConfig().getQinzhuUrl()+"/api/v2/platform/getToken", map); + } + + /** + * 生成签名 + * @param data 数据 + * @param key 秘钥app_secret + * @return 加密结果 + */ + public static String generateSignature(final Map data, String key){ + Set keySet = data.keySet(); + String[] keyArray = keySet.toArray(new String[keySet.size()]); + Arrays.sort(keyArray); + StringBuilder sb = new StringBuilder(); + for (String k : keyArray) { + if (k.equals(WXPayConstants.FIELD_SIGN)) { + continue; + } + if (StringUtils.isBlank(sb.toString())) { + sb.append(k).append("=").append(data.get(k)); + } else { + sb.append("&").append(k).append("=").append(data.get(k)); + } + } + sb.append(key); + return sb.toString(); + } +} diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index fc9c12f1..593a621f 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -1,7 +1,11 @@ tuanYouUrl=https://test02-motorcade-hcs.czb365.com tuanYouAppKey=208241666939552 tuanYouAppSecret=adecc3cff077834cb8632c8ab3bec0e6 -tuanYouDieselAccount =9b115eao4400 -tuanYouGasolineAccount =9b115e5g4400 +tuanYouDieselAccount=9b115eao4400 +tuanYouGasolineAccount=9b115e5g4400 -wx_cert=/home/project/wx_cert/ \ No newline at end of file +qinzhuUrl=https://live-test.qianzhu8.com +qinzhuPlatformId=10376 +qinzhuSecret=ktxb49sh2jfhgn8g + +wx_cert=/home/project/wx_cert/ diff --git a/hai-service/src/main/resources/prod/commonConfig.properties b/hai-service/src/main/resources/prod/commonConfig.properties index 541ce55a..9829c269 100644 --- a/hai-service/src/main/resources/prod/commonConfig.properties +++ b/hai-service/src/main/resources/prod/commonConfig.properties @@ -4,4 +4,8 @@ tuanYouAppSecret=adecc3cff077834cb8632c8ab3bec0e6 tuanYouDieselAccount=9b115eao4400 tuanYouGasolineAccount=9b115e5g4400 -wx_cert=/home/project/wx_cert/ \ No newline at end of file +qinzhuUrl=https://live-test.qianzhu8.com/ +qinzhuPlatformId=10376 +qinzhuSecret=ktxb49sh2jfhgn8g + +wx_cert=/home/project/wx_cert/