parent
71ffc282f9
commit
d156ff7b5a
@ -0,0 +1,172 @@ |
||||
package com.hfkj.channel.saas; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.saas.config.SaasConfig; |
||||
import com.hfkj.channel.saas.utils.RSAUtil; |
||||
import com.hfkj.channel.saas.utils.SaasCommon; |
||||
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 jdk.nashorn.internal.ir.annotations.Reference; |
||||
import org.apache.commons.codec.binary.Base64; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* |
||||
* 活动服务 |
||||
* @className: SaasActivityService |
||||
* @author: HuRui |
||||
* @date: 2023/5/12 |
||||
**/ |
||||
@Component |
||||
public class SaasActivityService { |
||||
@Resource |
||||
private SaasCommon saasCommon; |
||||
|
||||
/** |
||||
* 查询服务商活动 |
||||
* @return |
||||
*/ |
||||
public JSONArray queryAgentActivityList() { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("agentNo", SaasConfig.userNo); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestUrl + "htkmarketing/open/welfare/activity", obj, header); |
||||
System.out.println("参数:" + JSONObject.toJSONString(param)); |
||||
System.out.println("加密:" + obj.getString("data")); |
||||
System.out.println("request:" + obj.toJSONString()); |
||||
System.out.println("response:" + responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return JSONArray.parseArray(new String(RSAUtil.decryptByPublicKey(Base64.decodeBase64(responseObj.getString("data")), Base64.decodeBase64(RSAUtil.PUBLIC_KEY)))); |
||||
|
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 查询服务商参与状态查询 |
||||
* @param activityId |
||||
* @return |
||||
*/ |
||||
public JSONObject queryAgentActivityStatus(String activityId) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("activityId", activityId); |
||||
param.put("agentNo", SaasConfig.userNo); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestUrl + "https://test.wsmsd.cn/sit/htkmarketing/open/welfare/agent/status", obj, header); |
||||
System.out.println("参数:" + JSONObject.toJSONString(param)); |
||||
System.out.println("加密:" + obj.getString("data")); |
||||
System.out.println("request:" + obj.toJSONString()); |
||||
System.out.println("response:" + responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return JSONObject.parseObject(new String(RSAUtil.decryptByPublicKey(Base64.decodeBase64(responseObj.getString("data")), Base64.decodeBase64(RSAUtil.PUBLIC_KEY)))); |
||||
} |
||||
|
||||
/** |
||||
* 查询商户参与状态查询 |
||||
* @param activityId |
||||
* @param externalCustomerNo 外部商户号 |
||||
* @return |
||||
*/ |
||||
public JSONObject queryCustomerActivityStatus(String activityId,String externalCustomerNo) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("activityId", activityId); |
||||
param.put("externalCustomerNo", externalCustomerNo); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestUrl + "htkmarketing/open/welfare/customer/status", obj, header); |
||||
System.out.println("参数:" + JSONObject.toJSONString(param)); |
||||
System.out.println("加密:" + obj.getString("data")); |
||||
System.out.println("request:" + obj.toJSONString()); |
||||
System.out.println("response:" + responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return JSONObject.parseObject(new String(RSAUtil.decryptByPublicKey(Base64.decodeBase64(responseObj.getString("data")), Base64.decodeBase64(RSAUtil.PUBLIC_KEY)))); |
||||
} |
||||
|
||||
/** |
||||
* 服务商报名活动 |
||||
* @return |
||||
*/ |
||||
public JSONObject agentRegisterActivity(String activityId) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("agentNo", SaasConfig.userNo); |
||||
param.put("activityId", activityId); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestUrl + "htkmarketing/open/welfare/agent/register", obj, header); |
||||
System.out.println("参数:" + JSONObject.toJSONString(param)); |
||||
System.out.println("加密:" + obj.getString("data")); |
||||
System.out.println("request:" + obj.toJSONString()); |
||||
System.out.println("response:" + responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return responseObj; |
||||
} |
||||
|
||||
/** |
||||
* 商户报名活动 |
||||
* @return |
||||
*/ |
||||
public JSONObject customerRegisterActivity(String activityId, String branchBankNo, List<String> externalCustomerNos) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("activityId", activityId); |
||||
param.put("branchBankNo", branchBankNo); |
||||
param.put("externalCustomerNos", externalCustomerNos); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestUrl + "htkmarketing/open/welfare/customer/register", obj, header); |
||||
System.out.println("参数:" + JSONObject.toJSONString(param)); |
||||
System.out.println("加密:" + obj.getString("data")); |
||||
System.out.println("request:" + obj.toJSONString()); |
||||
System.out.println("response:" + responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return responseObj; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.hfkj.channel.saas.utils; |
||||
|
||||
import freemarker.template.Template; |
||||
import freemarker.template.TemplateException; |
||||
import net.coobird.thumbnailator.Thumbnails; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileWriter; |
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 生成协议工具 |
||||
* @className: GenerateAgreementUtil |
||||
* @author: HuRui |
||||
* @date: 2023/5/15 |
||||
**/ |
||||
public class GenerateAgreementUtil { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenerateAgreementUtil.class); |
||||
|
||||
/** |
||||
* 生成html文件数据 |
||||
* @param template |
||||
* @param data |
||||
* @return |
||||
* @throws IOException |
||||
* @throws TemplateException |
||||
*/ |
||||
// html 替换占位符
|
||||
public static File writeHtml(Long merId,Template template, Map<String, Object> data) throws IOException, TemplateException { |
||||
String fileName = merId+"/"+System.currentTimeMillis()+".html"; |
||||
File htmlFile = new File("D:/home", fileName); |
||||
FileWriter sw = new FileWriter(htmlFile); |
||||
log.info("生成协议html, 地址:{}, 参数:{} ", htmlFile.getAbsolutePath(), data); |
||||
template.process(data, sw); |
||||
return htmlFile; |
||||
} |
||||
|
||||
/** |
||||
* html文件 转 png 示例代码 |
||||
* @param htmlFile html文件 |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
public static String createAgreementPicture(Long merId,File htmlFile) throws IOException { |
||||
String fileName = merId+"/"+htmlFile.getName() + ".jpg"; |
||||
File outputFile = new File("D:/home", htmlFile.getName() + ".jpg"); |
||||
log.info("生成图片开始, HTML地址 {}, 图片地址:{}", htmlFile.getAbsolutePath(), outputFile.getAbsolutePath()); |
||||
// windows
|
||||
String commandProcess = "cmd.exe /c wkhtmltoimage --width 400 --quality 94 " + htmlFile.getPath() + " " + outputFile.getPath(); |
||||
// String commandProcess = "wkhtmltoimage --width 400 --quality 94 " + htmlFile.getPath() + " " + outputFile.getPath();
|
||||
log.info("协议执行procommand:{}", commandProcess); |
||||
long startTime = System.currentTimeMillis(); //获取开始时间
|
||||
Process process = Runtime.getRuntime().exec(commandProcess); |
||||
try { |
||||
int exitVal = process.waitFor(); |
||||
log.info("协议html转换png结果:{}", exitVal); |
||||
} catch (InterruptedException e) { |
||||
e.printStackTrace(); |
||||
log.info("协议html转换png错误:{}", e.getMessage()); |
||||
throw new IOException(e); |
||||
} |
||||
long endTime = System.currentTimeMillis(); //获取结束时间
|
||||
log.info("程序运行时间: " + (endTime - startTime) + "ms"); |
||||
log.info("生成图片结束,地址: {}", outputFile.getPath()); |
||||
Thumbnails.of(outputFile).scale(1).outputQuality(0.9).toFile(outputFile); |
||||
return fileName; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,9 @@ |
||||
package com.hfkj.common; |
||||
|
||||
/** |
||||
* @className: StreamGobbler |
||||
* @author: HuRui |
||||
* @date: 2023/5/12 |
||||
**/ |
||||
public class StreamGobbler { |
||||
} |
Loading…
Reference in new issue