|
|
@@ -1,164 +0,0 @@
|
|
|
-package com.uas.erp.schedular.finance.mq;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
-import com.uas.erp.schedular.database.RestJdbcTemplate;
|
|
|
-import com.uas.erp.schedular.entity.Master;
|
|
|
-import com.uas.erp.schedular.entity.MqConfig;
|
|
|
-import com.uas.erp.schedular.service.MasterService;
|
|
|
-import com.uas.erp.schedular.service.SettingService;
|
|
|
-import com.uas.erp.schedular.util.ContextHolder;
|
|
|
-import com.uas.erp.schedular.util.HmacUtils;
|
|
|
-import com.uas.erp.schedular.web.ResultWrap;
|
|
|
-import com.usoft.mq.utils.BaseRabbitReceiveService;
|
|
|
-import com.usoft.mq.utils.MessageInfo;
|
|
|
-import com.usoft.security.utils.OpenApiSignUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.annotation.Order;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.Assert;
|
|
|
-import org.springframework.util.LinkedMultiValueMap;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-import org.springframework.web.util.DefaultUriTemplateHandler;
|
|
|
-
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.security.InvalidKeyException;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class RabbitReceiveServiceImpl extends BaseRabbitReceiveService {
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
- @Autowired
|
|
|
- private RestJdbcTemplate jdbcTemplate;
|
|
|
- @Autowired
|
|
|
- private SettingService settingService;
|
|
|
-
|
|
|
- private final static String SECRETKEY = "600d3f07955ba67fe050007f01002db2";
|
|
|
- private final static String BASEPATH = "http://192.168.253.3:26600";
|
|
|
- private final static String UASURL = "http://192.168.253.29:8080/ERP";
|
|
|
- private final static String MASTERNAME = "YITOA_BL";
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- public void init() throws InterruptedException {
|
|
|
- Master master = new Master();
|
|
|
- master.setMa_user("YITOA_DATACENTER");
|
|
|
- master.setMa_uu(10050002L);
|
|
|
- master.setMa_accesssecret(SECRETKEY);
|
|
|
- master.setMa_env("prod");
|
|
|
- ContextHolder.setMaster(master);
|
|
|
- MqConfig mqConfig = null;
|
|
|
- try {
|
|
|
- mqConfig = jdbcTemplate.queryForBean("select MA_MQDYNAMICCREATE ,MA_MQHOST, MA_MQPORT, MA_MQVIRTUALHOST, MA_MQUSERNAME, MA_MQPASSWORD, MA_MQQUEUENAME from master where ma_user='" + MASTERNAME + "'", MqConfig.class);
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
- }
|
|
|
- if(mqConfig != null){
|
|
|
- isDynamicCreate = mqConfig.isMa_mqdynamiccreate();
|
|
|
- host = mqConfig.getMa_mqhost();
|
|
|
- port = mqConfig.getMa_mqport();
|
|
|
- virtualHost = mqConfig.getMa_mqvirtualhost();
|
|
|
- username = mqConfig.getMa_mqusername();
|
|
|
- password = mqConfig.getMa_mqpassword();
|
|
|
- queueName = mqConfig.getMa_mqqueuename();
|
|
|
- }
|
|
|
- /*isDynamicCreate = true;
|
|
|
- host = "134.175.196.24";
|
|
|
- port = 5672;
|
|
|
- virtualHost = "finance";
|
|
|
- username = "finance_platform";
|
|
|
- password = "platform8888";
|
|
|
- queueName = "finance_10046945";*/
|
|
|
- //ContextHolder.setMaster(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void processMessage(MessageInfo messageInfo) throws Exception {
|
|
|
-// messageInfo.getUserId().equals()
|
|
|
- switch (messageInfo.getAppId()){
|
|
|
- case "1001": //应收宝
|
|
|
- processMessageForReceivable(messageInfo.getBizId(), messageInfo.getBizType());
|
|
|
- break;
|
|
|
- default:
|
|
|
- //throw new Exception();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void processMessageForReceivable(String bizId, String bizType) throws Exception {
|
|
|
- String url = "";
|
|
|
- String uasURL = "";
|
|
|
- String codeName = "";
|
|
|
- switch (bizType){
|
|
|
- case "1": //额度申请
|
|
|
- url = BASEPATH + "/api/credit/get?";
|
|
|
- uasURL = "/openapi/receivable/getCreditApplyInfoReq.action";
|
|
|
- codeName = "creditApplyCode";
|
|
|
- break;
|
|
|
- case "2": //提款申请
|
|
|
- url = BASEPATH + "/api/draw/get?";
|
|
|
- uasURL = "/openapi/receivable/getDrawInfoResp.action";
|
|
|
- codeName = "code";
|
|
|
- break;
|
|
|
- case "3": //增额申请
|
|
|
- url = BASEPATH + "/api/addCredit/get?";
|
|
|
- uasURL = "/openapi/receivable/getAddCreditApplyInfoReq.action";
|
|
|
- codeName = "creditApplyCode";
|
|
|
- break;
|
|
|
- default:
|
|
|
- //throw new Exception();
|
|
|
- break;
|
|
|
- }
|
|
|
- Execute(url, bizId, uasURL, codeName);
|
|
|
- }
|
|
|
-
|
|
|
- private void Execute(String requestURL, String bizId, String uasURL, String codeName) throws Exception {
|
|
|
- String paramStr = "secretId=" + 10046945 + "&"+ codeName +"=" + URLEncoder.encode(bizId,"UTF-8");
|
|
|
- //进行签名
|
|
|
- String signatureValue = OpenApiSignUtil.sign(paramStr,SECRETKEY);
|
|
|
- signatureValue = URLEncoder.encode(signatureValue, "UTF-8");
|
|
|
- String signatureKV = OpenApiSignUtil.SIGNATURE_KEY + "=" + signatureValue;
|
|
|
- paramStr += "&" + signatureKV;
|
|
|
- requestURL = requestURL + paramStr;
|
|
|
-
|
|
|
- DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
|
|
|
- uriTemplateHandler.setStrictEncoding(true);
|
|
|
- restTemplate.setUriTemplateHandler(uriTemplateHandler);
|
|
|
- String result = restTemplate.getForObject(requestURL, String.class);
|
|
|
- String UASurl = UASURL + uasURL;
|
|
|
- Map<String, Object> map = new HashMap<String, Object>();
|
|
|
- map.put("data", result);
|
|
|
-
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
- headers.add("referer", getSignature(codeName));
|
|
|
- MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
|
|
- formData.setAll(map);
|
|
|
- HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(formData, headers);
|
|
|
- String returnStr = restTemplate.postForEntity(UASurl, request, String.class).getBody();
|
|
|
- ResultWrap<String> wrap = JSON.parseObject(returnStr, new TypeReference<ResultWrap<String>>(){});
|
|
|
- }
|
|
|
-
|
|
|
- public String getSignature(String code) {
|
|
|
- String url = "_timestamp=" + System.currentTimeMillis() + "&master=";
|
|
|
- if("code".equals(code)){
|
|
|
- url += "YITOA_BL";
|
|
|
- }else{
|
|
|
- url += "YITOA_DATACENTER";
|
|
|
- }
|
|
|
- // 签名
|
|
|
- return url + "&_signature=" + HmacUtils.encode(url);
|
|
|
- }
|
|
|
-}
|