| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import com.dderp.common.api.BusinessExecutor
- import com.dderp.common.api.flycat.PlatformAccessTokenService
- import com.dderp.common.datas.ERPModule
- import com.dderp.common.entity.base.ProcessMapItem
- import com.dderp.common.entity.base.ProcessStringItem
- import com.dderp.common.entity.base.ScriptMapResult
- import com.dderp.common.entity.base.ScriptStringResult
- import com.dderp.common.entity.site.ERPTokenUser
- import com.dderp.common.http.HttpTools
- import com.sweetfish.convert.json.JsonConvert
- import com.sweetfish.service.RetResult
- import groovy.json.JsonSlurper
- import org.apache.logging.log4j.LogManager
- import org.apache.logging.log4j.Logger
- import org.rex.RMap
- import javax.annotation.Resource
- import java.nio.charset.StandardCharsets
- import java.time.LocalDateTime
- import java.time.ZoneOffset
- import java.util.concurrent.ExecutionException
- import java.util.concurrent.TimeUnit
- import java.util.concurrent.TimeoutException
- @SuppressWarnings("unused")
- class BE_Invoke_PostInvoker_DYLK implements BusinessExecutor<ProcessMapItem, ScriptStringResult> {
- private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
- private Map<String, String> platPropertiesMap = new HashMap<>()
- @Resource(name = "APP_HOME")
- String homePath
- @Resource
- JsonConvert jsonConvert
- @Resource
- PlatformAccessTokenService tokenService
- @Override
- String scriptName() {
- return "[抖音来客]通用post请求"
- }
- @Override
- ERPModule module() {
- return ERPModule.PLATFORM_TOKEN
- }
- @Override
- void start(long supplierCode) {
- //取到该平台的properties
- //这地方严格来说是有问题的,supplierCode的区分没有加进去,做得好的话应该是properties文件用supplierCode区分开
- //各平台默认需要以下几个参数
- //appId
- //appSecret
- //reqUrl 接口请求地址
- //storeBindUrl 生成门店绑定url时候的请求地址
- final File df = new File(homePath, "/conf/platformProperty/DYLK.properties");
- if (df.isFile()) {
- try {
- Properties ps = new Properties();
- InputStream ins = new FileInputStream(df);
- ps.load(new InputStreamReader(ins, StandardCharsets.UTF_8));
- ins.close();
- ps.forEach((x, y) ->
- platPropertiesMap.putIfAbsent((String) x, (String) y)
- );
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- }
- }
- }
- RetResult<ScriptStringResult> execute(ProcessMapItem source) {
- //秒级时间戳,groovy里面不让用system
- long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
- RMap params = source.itemData
- String dataSourceId = source.dataSourceId
- long supplierCode = source.supplierCode
- ERPTokenUser currentUser = source.currentUser
- Map<String, String> header = new HashMap<>();
- header.put("access-token", tokenService.getAccessToken("DYLK", dataSourceId, supplierCode as String));
- header.put("log_id", String.valueOf(new Date().getTime()));
- header.put("Content-Type", "application/json");
- String resp
- try {
- resp = HttpTools.postHttpContentAsync(platPropertiesMap.get("reqUrl") +
- params.getString("subUrl"), header, params.getString("body")).get(20, TimeUnit.SECONDS)
- ScriptStringResult stringResult = new ScriptStringResult()
- stringResult.setResultStr(resp)
- return RetResult.<ScriptStringResult> successT().result(stringResult)
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- logger.error("请求抖音来客接口[" + params.getString("subUrl") + "]失败", e);
- }
- return RetResult.errorT();
- }
- }
|