袁野 3 weeks ago
commit 505734eb16
  1. 55
      cweb/src/main/java/com/hfkj/controller/TakeOutController.java
  2. 34
      cweb/src/main/java/com/hfkj/controller/TestController.java
  3. 21
      cweb/src/main/resources/dev/logback.xml
  4. 118
      service/src/main/java/com/hfkj/common/utils/SignatureUtil.java
  5. 6
      service/src/main/java/com/hfkj/config/CommonSysConfig.java
  6. 63
      service/src/main/java/com/hfkj/service/meituan/MeiTuanService.java
  7. 1
      service/src/main/java/com/hfkj/service/pdd/PddService.java
  8. 22
      service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java
  9. 5
      service/src/main/resources/dev/commonConfig.properties

@ -0,0 +1,55 @@
package com.hfkj.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.meituan.MeiTuanService;
import com.hfkj.service.user.BsUserAccountRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value="/takeOut")
@Api(value="外卖")
public class TakeOutController {
private static Logger log = LoggerFactory.getLogger(TakeOutController.class);
@Autowired
private UserCenter userCenter;
@RequestMapping(value="/generateLink",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "自助取链接口 ")
public ResponseData generateLink(@RequestParam(value = "actId" , required = false) Long actId,
@RequestParam(value = "linkType" , required = false) Integer linkType
) {
try {
// 用户session
UserSessionObject session = userCenter.getSessionModel(UserSessionObject.class);
JSONObject jsonObject = new JSONObject();
jsonObject.put("actId" , actId);
jsonObject.put("sid" , session.getUser().getId());
jsonObject.put("linkType" , linkType);
JSONObject object = MeiTuanService.generateLink(jsonObject);
return ResponseMsgUtil.success(object);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -8,6 +8,7 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.model.ResponseData;
import com.hfkj.service.meituan.MeiTuanService;
import com.hfkj.service.pdd.PddService;
import com.hfkj.service.taobao.TaoBaoService;
import com.hfkj.service.user.BsUserContributeService;
@ -38,6 +39,11 @@ import java.util.Map;
public class TestController {
private static Logger log = LoggerFactory.getLogger(TestController.class);
@Resource
private BsUserParentRelService userParentRelService;
@Resource
private BsUserContributeService userContributeService;
@RequestMapping(value="/material",method = RequestMethod.GET)
@ResponseBody
@ -82,11 +88,30 @@ public class TestController {
return ResponseMsgUtil.exception(e);
}
}
@Resource
private BsUserParentRelService userParentRelService;
@Resource
private BsUserContributeService userContributeService;
@RequestMapping(value="/generateLink",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "自助取链接口 ")
public ResponseData generateLink(@RequestParam(value = "actId" , required = false) Long actId,
@RequestParam(value = "linkType" , required = false) Integer linkType
) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("actId" , actId);
jsonObject.put("sid" , "001");
jsonObject.put("linkType" , linkType);
JSONObject object = MeiTuanService.generateLink(jsonObject);
return ResponseMsgUtil.success(object);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getParent",method = RequestMethod.GET)
@ResponseBody
@ -140,4 +165,5 @@ public class TestController {
}
}

@ -113,4 +113,25 @@
<appender-ref ref="PddLog" />
</logger>
<!-- 拼多多接口 -->
<!--美团接口 -->
<appender name="MeiTuanLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>log/MeiTuanLog.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/MeiTuanLog/MeiTuanLog.log.%d.%i</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>64 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>
%d %p (%file:%line\)- %m%n
</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
</appender>
<logger name="com.hfkj.service.meituan.MeiTuanService" level="INFO">
<appender-ref ref="MeiTuanLog" />
</logger>
<!-- 拼多多接口 -->
</configuration>

@ -0,0 +1,118 @@
package com.hfkj.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.config.CommonSysConst;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
public class SignatureUtil {
/**
* 参数签名
* @param param 参数
* @param secret 秘钥
* @return
* @throws Exception
*/
public static String createSign(Object param, String secret) throws Exception {
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class);
return md5Encode(paramSort(map, secret).getBytes());
}
/**
* 验证签名
* @param checkSign 需验证的签名字符串
* @param param 参数
* @param secret 秘钥
* @return
* @throws Exception
*/
public static Boolean checkSign(String checkSign,Object param, String secret) throws Exception {
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class);
// 去除签名
map.remove("sign");
if (checkSign.equals(createSign(map, secret))) {
return true;
}
return false;
}
/**
* 参数排序
* @param param
* @return
*/
public static String paramSort(final Map<String, Object> param, String secret) throws Exception {
Set<String> keySet = param.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray);
StringBuilder sb = new StringBuilder();
for (String k : keyArray) {
if (StringUtils.isBlank(sb.toString())) {
sb.append(k).append("=").append(param.get(k));
} else {
sb.append("&").append(k).append("=").append(param.get(k));
}
}
sb.append(secret);
return sb.toString();
}
/**
* MD5加密
* @param data
* @return
* @throws Exception
*/
public static String md5Encode(byte[] data) throws Exception {
// 初始化MessageDigest
MessageDigest md = MessageDigest.getInstance("MD5");
// 执行摘要信息
byte[] digest = md.digest(data);
// 将摘要信息转换为32位的十六进制字符串
return new String(new HexBinaryAdapter().marshal(digest));
}
public static String genSign(JSONObject object , String secret) throws Exception {
// 转换为TreeMap
TreeMap<String, Object> params = new TreeMap<>();
for (String key : object.keySet()) {
params.put(key, object.get(key));
}
params.remove("sign");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(secret)
.append(params.entrySet().stream()
.map(entry -> entry.getKey() + entry.getValue())
.collect(Collectors.joining()))
.append(secret);
return md5(stringBuilder.toString());
}
public static String md5(String source) {
String md5Result = null;
try {
byte[] hash = org.apache.commons.codec.binary.StringUtils.getBytesUtf8(source);
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(hash);
hash = messageDigest.digest();
md5Result = Hex.encodeHexString(hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return md5Result;
}
}

@ -27,5 +27,11 @@ public class CommonSysConfig {
private String taoBaoPostUrl;
private String taoBaoAppKey;
private String taoBaoAppSecret;
/**
* 美团请求参数
*/
private String meiTuanPostUrl;
private String meiTuanAppKey;
private String meiTuanAppSecret;
}

@ -0,0 +1,63 @@
package com.hfkj.service.meituan;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.SignatureUtil;
import com.hfkj.config.CommonSysConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MeiTuanService {
private static Logger log = LoggerFactory.getLogger(MeiTuanService.class);
/**
* @MethodName generateLink
* @Description: 自助取链接口
* @param param
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/10/11 下午4:35
*/
public static JSONObject generateLink(JSONObject param)throws Exception {
JSONObject object = request("generateLink" , param);
if (object.getInteger("status").equals(0)) {
return object;
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("des"));
}
}
/**
* @MethodName request
* @Description: 统一请求
* @param postUrl
* @param param
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/10/11 下午3:34
*/
public static JSONObject request(String postUrl, JSONObject param) throws Exception {
log.info("============ 美团请求-START =============");
param.put("appkey", CommonSysConst.getSysConfig().getMeiTuanAppKey());
param.put("sign" , SignatureUtil.genSign(param , CommonSysConst.getSysConfig().getMeiTuanAppSecret()));
log.info("请求接口:" + postUrl);
log.info("请求参数:" + JSONObject.toJSONString(param));
JSONObject response = HttpsUtils.doGet(CommonSysConst.getSysConfig().getMeiTuanPostUrl() + postUrl, param);
log.info("响应参数:" + response.toJSONString());
log.info("============ 美团请求-END ==============");
return response;
}
}

@ -20,7 +20,6 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
public class PddService {
private static Logger log = LoggerFactory.getLogger(PddService.class);

@ -181,4 +181,26 @@ public class TaoBaoService {
return JSONObject.parseObject(JSON.toJSONString(response));
}
public static JSONObject officialActivity(String clickUrl) throws Exception {
log.info("============ 淘口令生成-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability375 apiPackage = new Ability375(client);
// create domain
// create request
TaobaoTbkTpwdCreateRequest request = new TaobaoTbkTpwdCreateRequest();
request.setUrl(clickUrl);
TaobaoTbkTpwdCreateResponse response = apiPackage.taobaoTbkTpwdCreate(request);
log.info("请求接口:" + "taobaoTbkTpwdCreate");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 淘口令生成--END ==============");
return JSONObject.parseObject(JSON.toJSONString(response));
}
}

@ -4,3 +4,8 @@ domain=http://47.92.163.212
taoBaoPostUrl = https://eco.taobao.com/router/rest
taoBaoAppKey = 34807616
taoBaoAppSecret = f04baedca9cd794665dfa04a2fcbfd86
meiTuanPostUrl = https://openapi.meituan.com/api/
meiTuanAppKey = d876dc3766053f3cde609e5f11a26aba
meiTuanAppSecret = 7cdb8439a4c3fae7a092705bde95d4ef

Loading…
Cancel
Save