dev^2^2
parent
798802daea
commit
20af3db305
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,168 @@ |
||||
package com.hfkj.service.coupon.channel; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
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.config.CommonSysConst; |
||||
import com.meituan.sqt.utils.EncryptUtil; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.UnsupportedEncodingException; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @ClassName MeiTuanService |
||||
* @Author Sum1Dream |
||||
* @Description 优涂接口 |
||||
* @Date 2024/8/26 下午4:52 |
||||
**/ |
||||
public class YouTuCouponService { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(YouTuCouponService.class); |
||||
|
||||
|
||||
/** |
||||
* @MethodName getYouTuCouponList |
||||
* @Description:电子券模板列表 |
||||
* @param param |
||||
* @return: com.alibaba.fastjson.JSONObject |
||||
* @Author: Sum1Dream |
||||
* @Date: 2024/11/19 下午3:38 |
||||
*/ |
||||
public static JSONObject getYouTuCouponList(JSONObject param) { |
||||
|
||||
try { |
||||
JSONObject object = request( "/openapi/couponV3/getMerchantCouponTpl", param); |
||||
|
||||
if (object.getInteger("code").equals(200)) { |
||||
return object.getJSONObject("data"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败!"); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.info("响应错误信息:{}", e); |
||||
} |
||||
|
||||
return null; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @MethodName getMerchantCouponCode |
||||
* @Description:获取电子券码 |
||||
* @param param |
||||
* @return: com.alibaba.fastjson.JSONObject |
||||
* @Author: Sum1Dream |
||||
* @Date: 2024/11/19 下午3:38 |
||||
*/ |
||||
public static JSONObject getMerchantCouponCode(JSONObject param) { |
||||
|
||||
try { |
||||
JSONObject object = request( "/openapi/couponV3/getMerchantCouponCode", param); |
||||
|
||||
if (object.getInteger("code").equals(200)) { |
||||
return object.getJSONObject("data"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败!"); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.info("响应错误信息:{}", e); |
||||
} |
||||
|
||||
return null; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @MethodName merchantCouponToMember |
||||
* @Description:发送电子券到优途 |
||||
* @param param |
||||
* @return: com.alibaba.fastjson.JSONObject |
||||
* @Author: Sum1Dream |
||||
* @Date: 2024/11/19 下午4:36 |
||||
*/ |
||||
public static JSONObject merchantCouponToMember(JSONObject param) { |
||||
|
||||
try { |
||||
JSONObject object = request( "/openapi/couponV3/merchantCouponToMember", param); |
||||
|
||||
if (object.getInteger("code").equals(200)) { |
||||
return object.getJSONObject("data"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败!"); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.info("响应错误信息:{}", e); |
||||
} |
||||
|
||||
return null; |
||||
|
||||
} |
||||
|
||||
public static JSONObject getMerchantCouponState(JSONObject param) { |
||||
|
||||
try { |
||||
JSONObject object = request( "/openapi/couponV3/getMerchantCouponState", param); |
||||
|
||||
if (object.getInteger("code").equals(200)) { |
||||
return object.getJSONObject("data"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败!"); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.info("响应错误信息:{}", e); |
||||
} |
||||
|
||||
return null; |
||||
|
||||
} |
||||
|
||||
|
||||
public static JSONObject request(String url , JSONObject param) throws Exception { |
||||
log.info("获取卡券列表-请求参数: " + JSON.toJSONString(param)); |
||||
|
||||
StringBuilder stringBuffer = new StringBuilder(); |
||||
|
||||
param.put("app_id", CommonSysConst.getSysConfig().getYtAccessKey()); |
||||
JSONObject response = HttpsUtils.doPost(CommonSysConst.getSysConfig().getYtPostUrl() + url + "?app_id" + CommonSysConst.getSysConfig().getYtAccessKey() |
||||
+ "&sign=" + encryptSha1(String.valueOf(stringBuffer.append(CommonSysConst.getSysConfig().getYtSecretKey()).append(param.toJSONString()))) |
||||
, param); |
||||
log.info("获取卡券列表-回调参数: " + JSON.toJSONString(response)); |
||||
log.info("========================请求任务End========================="); |
||||
// 请求接口
|
||||
return response; |
||||
} |
||||
|
||||
|
||||
public static String encryptSha1(String input) { |
||||
try { |
||||
// Create MD5 Hash
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
||||
md.update(input.getBytes(java.nio.charset.StandardCharsets.UTF_8)); |
||||
byte[] digest = md.digest(); |
||||
StringBuffer hexString = new StringBuffer(); |
||||
for (byte b : digest) { |
||||
String hex = Integer.toHexString(0xff & b); |
||||
if (hex.length() == 1) hexString.append('0'); |
||||
hexString.append(hex); |
||||
} |
||||
return hexString.toString(); |
||||
|
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return ""; |
||||
|
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue