Merge branch 'dev' of http://gitea.dctpay.com/hurui/puhui-go into dev
commit
079a8e2790
@ -0,0 +1,78 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; |
||||
import java.security.MessageDigest; |
||||
import java.util.Arrays; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class SignatureUtil { |
||||
/** |
||||
* 参数签名 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String createSign(Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
return md5Encode(paramSort(map, key).getBytes()); |
||||
} |
||||
|
||||
/** |
||||
* 验证签名 |
||||
* @param checkSign 需验证的签名字符串 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Boolean checkSign(String checkSign,Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
// 去除签名
|
||||
map.remove("sign"); |
||||
if (checkSign.equals(createSign(map, key))) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 参数排序 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String paramSort(final Map<String, Object> param, String key) { |
||||
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("&key=").append(key); |
||||
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)); |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.hfkj.haioil; |
||||
|
||||
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; |
||||
|
||||
import java.util.Date; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
public class HaiOilService { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(HaiOilService.class); |
||||
|
||||
|
||||
/** |
||||
* @MethodName pushPk |
||||
* @Description: 推送优惠券包 |
||||
* @param map |
||||
* @return: com.alibaba.fastjson.JSONObject |
||||
* @Author: Sum1Dream |
||||
* @Date: 2024/9/9 下午2:57 |
||||
*/ |
||||
public static JSONObject pushPk(Map<String , Object> map) throws Exception { |
||||
|
||||
JSONObject object = request("/openapi/discount/pushPk" , map); |
||||
|
||||
if (Objects.equals(object.getString("return_code"), "000000")) { |
||||
return object; |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求失败!"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 请求 |
||||
* @param postUrl 接口请求地址 |
||||
* @param param 参数 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject request(String postUrl, Map<String,Object> param) throws Exception { |
||||
|
||||
log.info("============ 嗨加油请求-START ============="); |
||||
param.put("appId", CommonSysConst.getSysConfig().getHaiOilAppid()); |
||||
param.put("reqId", new Date().getTime()); |
||||
param.put("sign", SignatureUtil.createSign(param , CommonSysConst.getSysConfig().getHaiOilAppSecret())); |
||||
|
||||
log.info("请求接口:" + postUrl); |
||||
log.info("请求参数:" + JSONObject.toJSONString(param)); |
||||
|
||||
JSONObject response = HttpsUtils.doPost(CommonSysConst.getSysConfig().getHaiOilPostUrl()+ postUrl, JSONObject.toJSONString(param)); |
||||
|
||||
log.info("响应参数:" + response.toJSONString()); |
||||
log.info("============ 嗨加油请求-END =============="); |
||||
return response; |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,52 @@ |
||||
package com.hfkj.service; |
||||
import com.hfkj.entity.SecConfig; |
||||
|
||||
/** |
||||
* @ClassName SecConfigService.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description //TODO
|
||||
* @createTime 17:29 2021/6/23 |
||||
**/ |
||||
public interface SecConfigService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name create |
||||
* @Description // 创建
|
||||
* @Date 15:11 2024/4/19 |
||||
* @Param GoodsBrand |
||||
* @return void |
||||
*/ |
||||
void create(SecConfig secConfig); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name update |
||||
* @Description // 修改
|
||||
* @Date 15:12 2024/4/19 |
||||
* @Param GoodsBrand |
||||
* @return void |
||||
*/ |
||||
void update(SecConfig secConfig); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name delete |
||||
* @Description // 修改
|
||||
* @Date 15:12 2024/4/19 |
||||
* @Param id |
||||
* @return void |
||||
*/ |
||||
void delete(Integer id); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name queryDetail |
||||
* @Description // 根据ID查询产品类型详情
|
||||
* @Date 15:12 2024/4/19 |
||||
* @Param id |
||||
* @return com.hfkj.entity.GoodsBrand |
||||
*/ |
||||
SecConfig queryDetail(Integer id); |
||||
} |
@ -0,0 +1,34 @@ |
||||
package com.hfkj.service.impl; |
||||
|
||||
import com.hfkj.dao.SecConfigMapper; |
||||
import com.hfkj.entity.SecConfig; |
||||
import com.hfkj.service.SecConfigService; |
||||
import org.springframework.stereotype.Service; |
||||
import javax.annotation.Resource; |
||||
|
||||
@Service("secConfigService") |
||||
public class SecConfigServiceImpl implements SecConfigService { |
||||
|
||||
@Resource |
||||
private SecConfigMapper secConfigMapper; |
||||
|
||||
@Override |
||||
public void create(SecConfig secConfig) { |
||||
secConfigMapper.insert(secConfig); |
||||
} |
||||
|
||||
@Override |
||||
public void update(SecConfig secConfig) { |
||||
secConfigMapper.updateByPrimaryKeySelective(secConfig); |
||||
} |
||||
|
||||
@Override |
||||
public void delete(Integer id) { |
||||
secConfigMapper.deleteByPrimaryKey(id); |
||||
} |
||||
|
||||
@Override |
||||
public SecConfig queryDetail(Integer id) { |
||||
return secConfigMapper.selectByPrimaryKey(id); |
||||
} |
||||
} |
Loading…
Reference in new issue